Merge pull request #664 from cosmos/sunny/IAVLsubspace
added Subspace Iterator to IAVLTree
This commit is contained in:
commit
c97a5aeab0
|
@ -119,6 +119,13 @@ func (st *iavlStore) Iterator(start, end []byte) Iterator {
|
||||||
return newIAVLIterator(st.tree.Tree(), start, end, true)
|
return newIAVLIterator(st.tree.Tree(), start, end, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (st *iavlStore) Subspace(prefix []byte) Iterator {
|
||||||
|
end := make([]byte, len(prefix))
|
||||||
|
copy(end, prefix)
|
||||||
|
end[len(end)-1]++
|
||||||
|
return st.Iterator(prefix, end)
|
||||||
|
}
|
||||||
|
|
||||||
// Implements IterKVStore.
|
// Implements IterKVStore.
|
||||||
func (st *iavlStore) ReverseIterator(start, end []byte) Iterator {
|
func (st *iavlStore) ReverseIterator(start, end []byte) Iterator {
|
||||||
return newIAVLIterator(st.tree.Tree(), start, end, false)
|
return newIAVLIterator(st.tree.Tree(), start, end, false)
|
||||||
|
|
|
@ -82,6 +82,26 @@ func TestIAVLIterator(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIAVLSubspace(t *testing.T) {
|
||||||
|
db := dbm.NewMemDB()
|
||||||
|
tree, _ := newTree(t, db)
|
||||||
|
iavlStore := newIAVLStore(tree, numHistory)
|
||||||
|
|
||||||
|
iavlStore.Set([]byte("test1"), []byte("test1"))
|
||||||
|
iavlStore.Set([]byte("test2"), []byte("test2"))
|
||||||
|
iavlStore.Set([]byte("test3"), []byte("test3"))
|
||||||
|
|
||||||
|
iter := iavlStore.Subspace([]byte("test"))
|
||||||
|
expected := []string{"test1", "test2", "test3"}
|
||||||
|
for i := 0; iter.Valid(); iter.Next() {
|
||||||
|
expectedKey := expected[i]
|
||||||
|
key, value := iter.Key(), iter.Value()
|
||||||
|
assert.EqualValues(t, key, expectedKey)
|
||||||
|
assert.EqualValues(t, value, expectedKey)
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestIAVLStoreQuery(t *testing.T) {
|
func TestIAVLStoreQuery(t *testing.T) {
|
||||||
db := dbm.NewMemDB()
|
db := dbm.NewMemDB()
|
||||||
tree := iavl.NewVersionedTree(db, cacheSize)
|
tree := iavl.NewVersionedTree(db, cacheSize)
|
||||||
|
|
Loading…
Reference in New Issue