MCPcopy
hub / github.com/grafana/dskit / searchToken

Function searchToken

ring/util.go:130–140  ·  view source on GitHub ↗

searchToken returns the offset of the tokens entry holding the range for the provided key.

(tokens []uint32, key uint32)

Source from the content-addressed store, hash-verified

128
129// searchToken returns the offset of the tokens entry holding the range for the provided key.
130func 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.

Callers 9

findInstancesForKeyMethod · 0.85
shuffleShardMethod · 0.85
TestSearchTokenFunction · 0.85
BenchmarkSearchTokenFunction · 0.85
ActivePartitionForKeyMethod · 0.85
shuffleShardMethod · 0.85

Calls

no outgoing calls

Tested by 4

TestSearchTokenFunction · 0.68
BenchmarkSearchTokenFunction · 0.68