MCPcopy
hub / github.com/google/gvisor / Find

Method Find

pkg/segment/set.go:212–236  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

210// returned GapIterator is terminal. Otherwise, the returned Iterator is
211// terminal and the returned GapIterator is non-terminal.
212func (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.

Callers 15

IsEmptyRangeMethod · 0.95
FindSegmentMethod · 0.95
LowerBoundSegmentMethod · 0.95
UpperBoundSegmentMethod · 0.95
FindGapMethod · 0.95
LowerBoundGapMethod · 0.95
UpperBoundGapMethod · 0.95
InsertRangeMethod · 0.95
TryInsertRangeMethod · 0.95
RemoveRangeWithMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected