prev moves to the previous key. If no keys are before then depth is set to -1.
()
| 2146 | |
| 2147 | // prev moves to the previous key. If no keys are before then depth is set to -1. |
| 2148 | func (itr *SortedMapIterator[K, V]) prev() { |
| 2149 | for ; itr.depth >= 0; itr.depth-- { |
| 2150 | elem := &itr.stack[itr.depth] |
| 2151 | |
| 2152 | switch node := elem.node.(type) { |
| 2153 | case *sortedMapLeafNode[K, V]: |
| 2154 | if elem.index > 0 { |
| 2155 | elem.index-- |
| 2156 | return |
| 2157 | } |
| 2158 | case *sortedMapBranchNode[K, V]: |
| 2159 | if elem.index > 0 { |
| 2160 | elem.index-- |
| 2161 | itr.stack[itr.depth+1].node = node.elems[elem.index].node |
| 2162 | itr.depth++ |
| 2163 | itr.last() |
| 2164 | return |
| 2165 | } |
| 2166 | } |
| 2167 | } |
| 2168 | } |
| 2169 | |
| 2170 | // first positions the stack to the leftmost key from the current depth. |
| 2171 | // Elements and indexes below the current depth are assumed to be correct. |