Source File
order.go
Belonging Package
github.com/parquet-go/parquet-go
package parquetimport ()func orderOfBool( []bool) int {switch len() {case 0, 1:return 0default::= 0:= 0if [0] { // true => false: descending= -1= streakOfTrue()if == len() {= +1} else {+= streakOfFalse([:])}} else { // false => true: ascending= +1= streakOfFalse()+= streakOfTrue([:])}if != len() {= 0}return}}func streakOfTrue( []bool) int {if := bytes.IndexByte(unsafecast.Slice[byte](), 0); >= 0 {return}return len()}func streakOfFalse( []bool) int {if := bytes.IndexByte(unsafecast.Slice[byte](), 1); >= 0 {return}return len()}func orderOfBytes( [][]byte) int {switch len() {case 0, 1:return 0}= skipBytesStreak()if len() < 2 {return 1}:= bytes.Compare([0], [1])switch {case < 0:if bytesAreInAscendingOrder([1:]) {return +1}case > 0:if bytesAreInDescendingOrder([1:]) {return -1}}return 0}func skipBytesStreak( [][]byte) [][]byte {for := 1; < len(); ++ {if !bytes.Equal([], [0]) {return [-1:]}}return [len()-1:]}func bytesAreInAscendingOrder( [][]byte) bool {for := len() - 1; > 0; -- {:= bytes.Compare([-1], [])if > 0 {return false}}return true}func bytesAreInDescendingOrder( [][]byte) bool {for := len() - 1; > 0; -- {:= bytes.Compare([-1], [])if < 0 {return false}}return true}
![]() |
The pages are generated with Golds v0.8.4. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |