Find returns the segment or gap whose range contains the given key. If a segment is found, the returned Iterator is non-terminal and the returned GapIterator is terminal. Otherwise, the returned Iterator is terminal and the returned GapIterator is non-terminal.
(key Key)
| 210 | // returned GapIterator is terminal. Otherwise, the returned Iterator is |
| 211 | // terminal and the returned GapIterator is non-terminal. |
| 212 | func (s *Set) Find(key Key) (Iterator, GapIterator) { |
| 213 | n := &s.root |
| 214 | for { |
| 215 | // Binary search invariant: the correct value of i lies within [lower, |
| 216 | // upper]. |
| 217 | lower := 0 |
| 218 | upper := n.nrSegments |
| 219 | for lower < upper { |
| 220 | i := lower + (upper-lower)/2 |
| 221 | if r := n.keys[i]; key < r.End { |
| 222 | if key >= r.Start { |
| 223 | return Iterator{n, i}, GapIterator{} |
| 224 | } |
| 225 | upper = i |
| 226 | } else { |
| 227 | lower = i + 1 |
| 228 | } |
| 229 | } |
| 230 | i := lower |
| 231 | if !n.hasChildren { |
| 232 | return Iterator{}, GapIterator{n, i} |
| 233 | } |
| 234 | n = n.children[i] |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | // FindSegment returns the segment whose range contains the given key. If no |
| 239 | // such segment exists, FindSegment returns a terminal iterator. |
no outgoing calls
no test coverage detected