Commit 12f1aea3 authored by obscuren's avatar obscuren

Fixed iterator for short nodes.

In some cases the iterator didn't properly return the correct key
because it didn't append fields to the reverse lookup.
parent b05e63c3
...@@ -65,9 +65,9 @@ func (self *Iterator) next(node Node, key []byte) []byte { ...@@ -65,9 +65,9 @@ func (self *Iterator) next(node Node, key []byte) []byte {
} }
} else { } else {
cnode := node.Value() cnode := node.Value()
skey := key[len(k):]
var ret []byte var ret []byte
skey := key[len(k):]
if trie.BeginsWith(key, k) { if trie.BeginsWith(key, k) {
ret = self.next(cnode, skey) ret = self.next(cnode, skey)
} else if bytes.Compare(k, key[:len(k)]) > 0 { } else if bytes.Compare(k, key[:len(k)]) > 0 {
...@@ -93,7 +93,8 @@ func (self *Iterator) key(node Node) []byte { ...@@ -93,7 +93,8 @@ func (self *Iterator) key(node Node) []byte {
return k return k
} else { } else {
return self.key(node.Value()) k := trie.RemTerm(node.Key())
return append(k, self.key(node.Value())...)
} }
case *FullNode: case *FullNode:
if node.Value() != nil { if node.Value() != nil {
......
...@@ -8,12 +8,17 @@ func TestIterator(t *testing.T) { ...@@ -8,12 +8,17 @@ func TestIterator(t *testing.T) {
{"do", "verb"}, {"do", "verb"},
{"ether", "wookiedoo"}, {"ether", "wookiedoo"},
{"horse", "stallion"}, {"horse", "stallion"},
{"shaman", "horse"},
{"doge", "coin"},
{"dog", "puppy"},
{"somethingveryoddindeedthis is", "myothernodedata"},
} }
v := make(map[string]bool) v := make(map[string]bool)
for _, val := range vals { for _, val := range vals {
v[val.k] = false v[val.k] = false
trie.UpdateString(val.k, val.v) trie.UpdateString(val.k, val.v)
} }
trie.Commit()
it := trie.Iterator() it := trie.Iterator()
for it.Next() { for it.Next() {
......
...@@ -122,7 +122,6 @@ func TestEmptyValues(t *testing.T) { ...@@ -122,7 +122,6 @@ func TestEmptyValues(t *testing.T) {
} }
func TestReplication(t *testing.T) { func TestReplication(t *testing.T) {
t.Skip()
trie := NewEmpty() trie := NewEmpty()
vals := []struct{ k, v string }{ vals := []struct{ k, v string }{
{"do", "verb"}, {"do", "verb"},
...@@ -138,7 +137,7 @@ func TestReplication(t *testing.T) { ...@@ -138,7 +137,7 @@ func TestReplication(t *testing.T) {
for _, val := range vals { for _, val := range vals {
trie.UpdateString(val.k, val.v) trie.UpdateString(val.k, val.v)
} }
trie.Hash() trie.Commit()
trie2 := New(trie.roothash, trie.cache.backend) trie2 := New(trie.roothash, trie.cache.backend)
if string(trie2.GetString("horse")) != "stallion" { if string(trie2.GetString("horse")) != "stallion" {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment