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)
| 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. |
| 2207 | func (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. |
| 2226 | type sortedMapIteratorElem[K, V any] struct { |