pick does a binary search. It returns the item with smallest index i that r.items[i].hash >= h.
(h uint64)
| 174 | // pick does a binary search. It returns the item with smallest index i that |
| 175 | // r.items[i].hash >= h. |
| 176 | func (r *ring) pick(h uint64) *ringEntry { |
| 177 | i := sort.Search(len(r.items), func(i int) bool { return r.items[i].hash >= h }) |
| 178 | if i == len(r.items) { |
| 179 | // If not found, and h is greater than the largest hash, return the |
| 180 | // first item. |
| 181 | i = 0 |
| 182 | } |
| 183 | return r.items[i] |
| 184 | } |
| 185 | |
| 186 | // next returns the next entry. |
| 187 | func (r *ring) next(e *ringEntry) *ringEntry { |