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

Method Prev

immutable.go:2131–2145  ·  view source on GitHub ↗

Prev returns the current key/value pair and moves the iterator backward. Returns a nil key if the there are no more elements to return.

()

Source from the content-addressed store, hash-verified

2129// Prev returns the current key/value pair and moves the iterator backward.
2130// Returns a nil key if the there are no more elements to return.
2131func (itr *SortedMapIterator[K, V]) Prev() (key K, value V, ok bool) {
2132 // Return nil key if iteration is complete.
2133 if itr.Done() {
2134 return key, value, false
2135 }
2136
2137 // Retrieve current key/value pair.
2138 leafElem := &itr.stack[itr.depth]
2139 leafNode := leafElem.node.(*sortedMapLeafNode[K, V])
2140 leafEntry := &leafNode.entries[leafElem.index]
2141 key, value = leafEntry.key, leafEntry.value
2142
2143 itr.prev()
2144 return key, value, true
2145}
2146
2147// prev moves to the previous key. If no keys are before then depth is set to -1.
2148func (itr *SortedMapIterator[K, V]) prev() {

Callers 6

BenchmarkList_IteratorFunction · 0.45
TestSortedMap_IteratorFunction · 0.45

Calls 2

DoneMethod · 0.95
prevMethod · 0.95

Tested by 6

BenchmarkList_IteratorFunction · 0.36
TestSortedMap_IteratorFunction · 0.36