提交 82272ee0 编写于 作者: O obscuren

Iterator fix

上级 9ed0d389
......@@ -538,15 +538,13 @@ func (it *TrieIterator) fetchNode(key []int, node []byte, cb EachCallback) {
}
func (it *TrieIterator) iterateNode(key []int, currentNode *Value, cb EachCallback) {
//fmt.Println("node", currentNode)
if currentNode.Len() == 2 {
k := CompactDecode(currentNode.Get(0).Str())
if currentNode.Get(1).Str() == "" {
it.iterateNode(key, currentNode.Get(1), cb)
pk := append(key, k...)
if currentNode.Get(1).Len() != 0 && currentNode.Get(1).Str() == "" {
it.iterateNode(pk, currentNode.Get(1), cb)
} else {
pk := append(key, k...)
if k[len(k)-1] == 16 {
cb(DecodeCompact(pk), currentNode.Get(1))
......@@ -560,7 +558,7 @@ func (it *TrieIterator) iterateNode(key []int, currentNode *Value, cb EachCallba
if i == 16 && currentNode.Get(i).Len() != 0 {
cb(DecodeCompact(pk), currentNode.Get(i))
} else {
if currentNode.Get(i).Str() == "" {
if currentNode.Get(i).Len() != 0 && currentNode.Get(i).Str() == "" {
it.iterateNode(pk, currentNode.Get(i), cb)
} else {
val := currentNode.Get(i).Str()
......
......@@ -261,13 +261,13 @@ func TestTrieReplay(t *testing.T) {
_, trie2 := New()
trie.NewIterator().Each(func(key string, v *Value) {
trie2.Update(key, string(v.Str()))
trie2.Update(key, v.Str())
})
a := NewValue(trie.Root).Bytes()
b := NewValue(trie2.Root).Bytes()
if bytes.Compare(a, b) != 0 {
t.Errorf("root %x %x\n", trie.Root, trie2.Root)
t.Errorf("%s %x %x\n", test.Name, trie.Root, trie2.Root)
}
})
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册