aboutsummaryrefslogtreecommitdiff
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
parentv0.1.0 (diff)
downloadpds-97a10bd671f22b2ded1fecd3e9018f502eeaf697.tar.gz
pds-97a10bd671f22b2ded1fecd3e9018f502eeaf697.tar.xz
Minor iterator refactor; update comment
-rw-r--r--immutable.go19
-rw-r--r--immutable_test.go15
2 files changed, 17 insertions, 17 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.
diff --git a/immutable_test.go b/immutable_test.go
index a0c7821..05a96e6 100644
--- a/immutable_test.go
+++ b/immutable_test.go
@@ -483,7 +483,7 @@ func ExampleList_Iterator_reverse() {
}
// Ensure node can support overwrites as it expands.
-func TestIngernal_mapNode_Overwrite(t *testing.T) {
+func TestInternal_mapNode_Overwrite(t *testing.T) {
const n = 1000
var h intHasher
var node mapNode = &mapArrayNode{}
@@ -517,7 +517,7 @@ func TestIngernal_mapNode_Overwrite(t *testing.T) {
}
}
-func TestIngernal_mapArrayNode(t *testing.T) {
+func TestInternal_mapArrayNode(t *testing.T) {
// Ensure 8 or fewer elements stays in an array node.
t.Run("Append", func(t *testing.T) {
var h intHasher
@@ -593,7 +593,7 @@ func TestIngernal_mapArrayNode(t *testing.T) {
})
}
-func TestIngernal_mapValueNode(t *testing.T) {
+func TestInternal_mapValueNode(t *testing.T) {
t.Run("Simple", func(t *testing.T) {
var h intHasher
n := newMapValueNode(h.Hash(2), 2, 3)
@@ -1131,10 +1131,7 @@ func (m *TestMap) Validate() error {
return fmt.Errorf("key (%d) mismatch: immutable=%d, std=%d", k, v, m.std[k])
}
}
- if err := m.validateIterator(); err != nil {
- return err
- }
- return nil
+ return m.validateIterator()
}
func (m *TestMap) validateIterator() error {
@@ -1260,7 +1257,7 @@ func ExampleMap_Iterator() {
// apple 100
}
-func TestIngernalSortedMapLeafNode(t *testing.T) {
+func TestInternalSortedMapLeafNode(t *testing.T) {
RunRandom(t, "NoSplit", func(t *testing.T, rand *rand.Rand) {
var cmpr intComparer
var node sortedMapNode = &sortedMapLeafNode{}
@@ -1360,7 +1357,7 @@ func TestIngernalSortedMapLeafNode(t *testing.T) {
})
}
-func TestIngernalSortedMapBranchNode(t *testing.T) {
+func TestInternalSortedMapBranchNode(t *testing.T) {
RunRandom(t, "NoSplit", func(t *testing.T, rand *rand.Rand) {
keys := make([]int, 32*16)
for i := range keys {