(key uint32)
| 13 | type TokenRanges []uint32 |
| 14 | |
| 15 | func (tr TokenRanges) IncludesKey(key uint32) bool { |
| 16 | switch { |
| 17 | case len(tr) == 0: |
| 18 | return false |
| 19 | case key < tr[0]: |
| 20 | // key comes before the first range |
| 21 | return false |
| 22 | case key > tr[len(tr)-1]: |
| 23 | // key comes after the last range |
| 24 | return false |
| 25 | } |
| 26 | |
| 27 | index, found := slices.BinarySearch(tr, key) |
| 28 | switch { |
| 29 | case found: |
| 30 | // ranges are closed |
| 31 | return true |
| 32 | case index%2 == 1: |
| 33 | // hash would be inserted after the start of a range (even index) |
| 34 | return true |
| 35 | default: |
| 36 | return false |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | func (tr TokenRanges) Equal(other TokenRanges) bool { |
| 41 | if len(tr) != len(other) { |
no outgoing calls