Skip to content

Commit 99ebb86

Browse files
committed
Fixed iterator
1 parent 44eafb1 commit 99ebb86

2 files changed

Lines changed: 40 additions & 2 deletions

File tree

‎trie/iterator.go‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ func (self *Iterator) Next() bool {
2323
self.Key = []byte(DecodeCompact(k))
2424

2525
return len(k) > 0
26-
2726
}
2827

2928
func (self *Iterator) next(node Node, key []byte) []byte {
@@ -67,7 +66,7 @@ func (self *Iterator) next(node Node, key []byte) []byte {
6766
if BeginsWith(key, k) {
6867
ret = self.next(cnode, skey)
6968
} else if bytes.Compare(k, key[:len(k)]) > 0 {
70-
ret = self.key(node)
69+
return self.key(node)
7170
}
7271

7372
if ret != nil {

‎trie/trie_test.go‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,42 @@ func BenchmarkUpdate(b *testing.B) {
257257
}
258258
trie.Hash()
259259
}
260+
261+
type kv struct {
262+
k, v []byte
263+
t bool
264+
}
265+
266+
func TestLargeData(t *testing.T) {
267+
trie := NewEmpty()
268+
vals := make(map[string]*kv)
269+
270+
for i := byte(1); i < 255; i++ {
271+
value := &kv{ethutil.LeftPadBytes([]byte{i}, 32), []byte{i}, false}
272+
value2 := &kv{ethutil.LeftPadBytes([]byte{10, i}, 32), []byte{i}, false}
273+
trie.Update(value.k, value.v)
274+
trie.Update(value2.k, value2.v)
275+
vals[string(value.k)] = value
276+
vals[string(value2.k)] = value2
277+
fmt.Println(value, "\n", value2)
278+
}
279+
280+
it := trie.Iterator()
281+
for it.Next() {
282+
vals[string(it.Key)].t = true
283+
}
284+
285+
var untouched []*kv
286+
for _, value := range vals {
287+
if !value.t {
288+
untouched = append(untouched, value)
289+
}
290+
}
291+
292+
if len(untouched) > 0 {
293+
t.Errorf("Missed %d nodes", len(untouched))
294+
for _, value := range untouched {
295+
t.Error(value)
296+
}
297+
}
298+
}

0 commit comments

Comments
 (0)