MCPcopy Create free account
hub / github.com/zalando/skipper / searchRing

Method searchRing

loadbalancer/algorithm.go:148–158  ·  view source on GitHub ↗

Returns index in hash ring with the closest hash to key's hash

(key string, ctx *routing.LBContext)

Source from the content-addressed store, hash-verified

146
147// Returns index in hash ring with the closest hash to key's hash
148func (ch *consistentHash) searchRing(key string, ctx *routing.LBContext) int {
149 h := hash(key)
150 i := sort.Search(ch.Len(), func(i int) bool { return ch.hashRing[i].hash >= h })
151 if i == ch.Len() { // rollover
152 i = 0
153 }
154 for skipEndpoint(ctx, ch.hashRing[i].index) {
155 i = (i + 1) % ch.Len()
156 }
157 return i
158}
159
160// Returns index of endpoint with closest hash to key's hash
161func (ch *consistentHash) search(key string, ctx *routing.LBContext) int {

Callers 2

searchMethod · 0.95
boundedLoadSearchMethod · 0.95

Calls 3

LenMethod · 0.95
skipEndpointFunction · 0.85
hashFunction · 0.70

Tested by

no test coverage detected