searchToken returns the offset of the tokens entry holding the range for the provided key.
(tokens []uint32, key uint32)
| 128 | |
| 129 | // searchToken returns the offset of the tokens entry holding the range for the provided key. |
| 130 | func searchToken(tokens []uint32, key uint32) int { |
| 131 | i, found := slices.BinarySearch(tokens, key) |
| 132 | if found { |
| 133 | // we want the first token > key, not >= key |
| 134 | i = i + 1 |
| 135 | } |
| 136 | if i >= len(tokens) { |
| 137 | i = 0 |
| 138 | } |
| 139 | return i |
| 140 | } |
| 141 | |
| 142 | // tokenDistance returns the distance between the given tokens from and to. |
| 143 | // The distance between a token and itself is the whole ring, i.e., math.MaxUint32 + 1. |
no outgoing calls