aboutsummaryrefslogtreecommitdiff
path: root/immutable.go
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2019-03-01 14:25:35 -0700
committerBen Johnson <benbjohnson@yahoo.com>2019-03-01 14:25:35 -0700
commit97a10bd671f22b2ded1fecd3e9018f502eeaf697 (patch)
treee46da030d487507338936edf940a49ddaff374f3 /immutable.go
parentv0.1.0 (diff)
downloadpds-97a10bd671f22b2ded1fecd3e9018f502eeaf697.tar.gz
pds-97a10bd671f22b2ded1fecd3e9018f502eeaf697.tar.xz
Minor iterator refactor; update comment
Diffstat (limited to 'immutable.go')
-rw-r--r--immutable.go19
1 files changed, 11 insertions, 8 deletions
diff --git a/immutable.go b/immutable.go
index 6f5e6f6..f9be606 100644
--- a/immutable.go
+++ b/immutable.go
@@ -49,7 +49,7 @@ import (
"strings"
)
-// Lists are dense, ordered, indexed collections. They are analogous to slices
+// List is a dense, ordered, indexed collections. They are analogous to slices
// in Go. They can be updated by appending to the end of the list, prepending
// values to the beginning of the list, or updating existing indexes in the
// list.
@@ -1158,6 +1158,12 @@ func (itr *MapIterator) Next() (key, value interface{}) {
// Move up stack until we find a node that has remaining position ahead
// and move that element forward by one.
+ itr.next()
+ return key, value
+}
+
+// next moves to the next available key.
+func (itr *MapIterator) next() {
for ; itr.depth >= 0; itr.depth-- {
elem := &itr.stack[itr.depth]
@@ -1165,7 +1171,7 @@ func (itr *MapIterator) Next() (key, value interface{}) {
case *mapArrayNode:
if elem.index < len(node.entries)-1 {
elem.index++
- return key, value
+ return
}
case *mapBitmapIndexedNode:
@@ -1174,7 +1180,7 @@ func (itr *MapIterator) Next() (key, value interface{}) {
itr.stack[itr.depth+1].node = node.nodes[elem.index]
itr.depth++
itr.first()
- return key, value
+ return
}
case *mapHashArrayNode:
@@ -1184,7 +1190,7 @@ func (itr *MapIterator) Next() (key, value interface{}) {
itr.stack[itr.depth+1].node = node.nodes[elem.index]
itr.depth++
itr.first()
- return key, value
+ return
}
}
@@ -1194,13 +1200,10 @@ func (itr *MapIterator) Next() (key, value interface{}) {
case *mapHashCollisionNode:
if elem.index < len(node.entries)-1 {
elem.index++
- return key, value
+ return
}
}
}
-
- // This only occurs if depth is -1.
- return key, value
}
// first positions the stack left most index.