MCPcopy Create free account
hub / github.com/benbjohnson/immutable / seek

Method seek

immutable.go:2207–2223  ·  view source on GitHub ↗

seek positions the stack to the given key from the current depth. Elements and indexes below the current depth are assumed to be correct.

(key K)

Source from the content-addressed store, hash-verified

2205// seek positions the stack to the given key from the current depth.
2206// Elements and indexes below the current depth are assumed to be correct.
2207func (itr *SortedMapIterator[K, V]) seek(key K) {
2208 for {
2209 elem := &itr.stack[itr.depth]
2210 elem.index = elem.node.indexOf(key, itr.m.comparer)
2211
2212 switch node := elem.node.(type) {
2213 case *sortedMapBranchNode[K, V]:
2214 itr.stack[itr.depth+1] = sortedMapIteratorElem[K, V]{node: node.elems[elem.index].node}
2215 itr.depth++
2216 case *sortedMapLeafNode[K, V]:
2217 if elem.index == len(node.entries) {
2218 itr.next()
2219 }
2220 return
2221 }
2222 }
2223}
2224
2225// sortedMapIteratorElem represents node/index pair in the SortedMapIterator stack.
2226type sortedMapIteratorElem[K, V any] struct {

Callers 1

SeekMethod · 0.95

Calls 2

nextMethod · 0.95
indexOfMethod · 0.65

Tested by

no test coverage detected