github.com/go-board/x-go@v0.1.2-0.20220610024734-db1323f6cb15/xsort/search.go (about) 1 package xsort 2 3 import ( 4 "sort" 5 6 "github.com/go-board/x-go/types" 7 ) 8 9 func SearchUint(a []uint, x uint) int { 10 return sort.Search(len(a), func(i int) bool { return a[i] >= x }) 11 } 12 13 func SearchUint64(a []uint64, x uint64) int { 14 return sort.Search(len(a), func(i int) bool { return a[i] >= x }) 15 } 16 17 func SearchUint32(a []uint32, x uint32) int { 18 return sort.Search(len(a), func(i int) bool { return a[i] >= x }) 19 } 20 21 func SearchUint16(a []uint16, x uint16) int { 22 return sort.Search(len(a), func(i int) bool { return a[i] >= x }) 23 } 24 25 func SearchUint8(a []uint8, x uint8) int { 26 return sort.Search(len(a), func(i int) bool { return a[i] >= x }) 27 } 28 29 func SearchInt(a []int, x int) int { 30 return sort.SearchInts(a, x) 31 } 32 33 func SearchInt64(a []int64, x int64) int { 34 return sort.Search(len(a), func(i int) bool { return a[i] >= x }) 35 } 36 37 func SearchInt32(a []int32, x int32) int { 38 return sort.Search(len(a), func(i int) bool { return a[i] >= x }) 39 } 40 41 func SearchInt16(a []int16, x int16) int { 42 return sort.Search(len(a), func(i int) bool { return a[i] >= x }) 43 } 44 45 func SearchInt8(a []int8, x int8) int { 46 return sort.Search(len(a), func(i int) bool { return a[i] >= x }) 47 } 48 49 func SearchString(a []string, x string) int { 50 return sort.SearchStrings(a, x) 51 } 52 53 func SearchFloat64(a []float64, x float64) int { 54 return sort.SearchFloat64s(a, x) 55 } 56 57 func SearchFloat32(a []float32, x float32) int { 58 return sort.Search(len(a), func(i int) bool { return a[i] >= x }) 59 } 60 61 func SearchComparable(a []types.Comparable, x types.Comparable) int { 62 return sort.Search(len(a), func(i int) bool { return a[i].Compare(x) >= types.OrderingEqual }) 63 }