forked from parquet-go/parquet-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorder_purego.go
42 lines (36 loc) · 942 Bytes
/
order_purego.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//go:build purego || !amd64
package parquet
import "cmp"
func orderOfInt32(data []int32) int { return orderOf(data) }
func orderOfInt64(data []int64) int { return orderOf(data) }
func orderOfUint32(data []uint32) int { return orderOf(data) }
func orderOfUint64(data []uint64) int { return orderOf(data) }
func orderOfFloat32(data []float32) int { return orderOf(data) }
func orderOfFloat64(data []float64) int { return orderOf(data) }
func orderOf[T cmp.Ordered](data []T) int {
if len(data) > 1 {
if orderIsAscending(data) {
return +1
}
if orderIsDescending(data) {
return -1
}
}
return 0
}
func orderIsAscending[T cmp.Ordered](data []T) bool {
for i := len(data) - 1; i > 0; i-- {
if data[i-1] > data[i] {
return false
}
}
return true
}
func orderIsDescending[T cmp.Ordered](data []T) bool {
for i := len(data) - 1; i > 0; i-- {
if data[i-1] < data[i] {
return false
}
}
return true
}