Skip to content

Commit

Permalink
Fix sorted map iterator initialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
benbjohnson committed Mar 2, 2019
1 parent d3fd75b commit 4423819
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions immutable.go
Original file line number Diff line number Diff line change
Expand Up @@ -1585,31 +1585,37 @@ func (itr *SortedMapIterator) Done() bool {

// First moves the iterator to the first key/value pair.
func (itr *SortedMapIterator) First() {
if itr.m.root != nil {
itr.stack[0] = sortedMapIteratorElem{node: itr.m.root}
itr.depth = 0
itr.first()
if itr.m.root == nil {
itr.depth = -1
return
}
itr.stack[0] = sortedMapIteratorElem{node: itr.m.root}
itr.depth = 0
itr.first()
}

// Last moves the iterator to the last key/value pair.
func (itr *SortedMapIterator) Last() {
if itr.m.root != nil {
itr.stack[0] = sortedMapIteratorElem{node: itr.m.root}
itr.depth = 0
itr.last()
if itr.m.root == nil {
itr.depth = -1
return
}
itr.stack[0] = sortedMapIteratorElem{node: itr.m.root}
itr.depth = 0
itr.last()
}

// Seek moves the iterator position to the given key in the map.
// If the key does not exist then the next key is used. If no more keys exist
// then the iteartor is marked as done.
func (itr *SortedMapIterator) Seek(key interface{}) {
if itr.m.root != nil {
itr.stack[0] = sortedMapIteratorElem{node: itr.m.root}
itr.depth = 0
itr.seek(key)
if itr.m.root == nil {
itr.depth = -1
return
}
itr.stack[0] = sortedMapIteratorElem{node: itr.m.root}
itr.depth = 0
itr.seek(key)
}

// Next returns the current key/value pair and moves the iterator forward.
Expand Down

0 comments on commit 4423819

Please sign in to comment.