You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
526 B

10 years ago
10 years ago
10 years ago
10 years ago
  1. package common
  2. import (
  3. "sort"
  4. )
  5. // Sort for []uint64
  6. type Uint64Slice []uint64
  7. func (p Uint64Slice) Len() int { return len(p) }
  8. func (p Uint64Slice) Less(i, j int) bool { return p[i] < p[j] }
  9. func (p Uint64Slice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
  10. func (p Uint64Slice) Sort() { sort.Sort(p) }
  11. func SearchUint64s(a []uint64, x uint64) int {
  12. return sort.Search(len(a), func(i int) bool { return a[i] >= x })
  13. }
  14. func (p Uint64Slice) Search(x uint64) int { return SearchUint64s(p, x) }