Returns index in hash ring with the closest hash to key's hash
(key string, ctx *routing.LBContext)
| 146 | |
| 147 | // Returns index in hash ring with the closest hash to key's hash |
| 148 | func (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 |
| 161 | func (ch *consistentHash) search(key string, ctx *routing.LBContext) int { |
no test coverage detected