working on it
This commit is contained in:
parent
2e5943e1bf
commit
56f28145dd
|
@ -458,6 +458,6 @@
|
|||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
inputs-digest = "cce90fda84a63ae5b41b40f0edc357eec4020d17fdd61585960ad537418749ea"
|
||||
inputs-digest = "ed1f3f7f1728cd02945f90ca780e9bdc982573a36a5cc8d7e9f19fb40ba2ca19"
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
||||
|
|
|
@ -122,7 +122,24 @@ func (st *iavlStore) Iterator(start, end []byte) Iterator {
|
|||
func (st *iavlStore) Subspace(prefix []byte) Iterator {
|
||||
end := make([]byte, len(prefix))
|
||||
copy(end, prefix)
|
||||
end[len(end)-1]++
|
||||
finished := false
|
||||
i := 1
|
||||
|
||||
for !finished {
|
||||
fmt.Printf("%v %v \n", len(end), i)
|
||||
fmt.Printf("%v \n", end)
|
||||
if end[len(end)-i] != byte(255) {
|
||||
end[len(end)-i]++
|
||||
finished = true
|
||||
} else {
|
||||
end[len(end)-i]++
|
||||
i++
|
||||
if i > len(end) {
|
||||
end = []byte{}
|
||||
finished = true
|
||||
}
|
||||
}
|
||||
}
|
||||
return st.Iterator(prefix, end)
|
||||
}
|
||||
|
||||
|
|
|
@ -73,13 +73,26 @@ func TestIAVLIterator(t *testing.T) {
|
|||
iavlStore := newIAVLStore(tree, numHistory)
|
||||
iter := iavlStore.Iterator([]byte("aloha"), []byte("hellz"))
|
||||
expected := []string{"aloha", "hello"}
|
||||
for i := 0; iter.Valid(); iter.Next() {
|
||||
i := 0
|
||||
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, treeData[expectedKey])
|
||||
i += 1
|
||||
}
|
||||
assert.Equal(t, i, len(expected))
|
||||
|
||||
iter = iavlStore.Iterator([]byte("golang"), []byte("rocks"))
|
||||
expected = []string{"hello"}
|
||||
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, treeData[expectedKey])
|
||||
i += 1
|
||||
}
|
||||
assert.Equal(t, i, len(expected))
|
||||
}
|
||||
|
||||
func TestIAVLSubspace(t *testing.T) {
|
||||
|
@ -90,16 +103,51 @@ func TestIAVLSubspace(t *testing.T) {
|
|||
iavlStore.Set([]byte("test1"), []byte("test1"))
|
||||
iavlStore.Set([]byte("test2"), []byte("test2"))
|
||||
iavlStore.Set([]byte("test3"), []byte("test3"))
|
||||
iavlStore.Set([]byte{byte(55), byte(255), byte(255), byte(0)}, []byte("test4"))
|
||||
iavlStore.Set([]byte{byte(55), byte(255), byte(255), byte(1)}, []byte("test4"))
|
||||
iavlStore.Set([]byte{byte(55), byte(255), byte(255), byte(255)}, []byte("test4"))
|
||||
i := 0
|
||||
|
||||
iter := iavlStore.Subspace([]byte("test"))
|
||||
expected := []string{"test1", "test2", "test3"}
|
||||
for i := 0; iter.Valid(); iter.Next() {
|
||||
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
|
||||
}
|
||||
assert.Equal(t, i, len(expected))
|
||||
|
||||
iter = iavlStore.Subspace([]byte{byte(55), byte(255), byte(255)})
|
||||
expected2 := [][]byte{
|
||||
[]byte{byte(55), byte(255), byte(255), byte(0)},
|
||||
[]byte{byte(55), byte(255), byte(255), byte(1)},
|
||||
[]byte{byte(55), byte(255), byte(255), byte(255)},
|
||||
}
|
||||
for i = 0; iter.Valid(); iter.Next() {
|
||||
expectedKey := expected2[i]
|
||||
key, value := iter.Key(), iter.Value()
|
||||
assert.EqualValues(t, key, expectedKey)
|
||||
assert.EqualValues(t, value, []byte("test4"))
|
||||
i += 1
|
||||
}
|
||||
assert.Equal(t, i, len(expected))
|
||||
|
||||
iter = iavlStore.Subspace([]byte{byte(255), byte(255)})
|
||||
expected2 = [][]byte{
|
||||
[]byte{byte(255), byte(255), byte(0)},
|
||||
[]byte{byte(255), byte(255), byte(1)},
|
||||
[]byte{byte(255), byte(255), byte(255)},
|
||||
}
|
||||
for i = 0; iter.Valid(); iter.Next() {
|
||||
expectedKey := expected2[i]
|
||||
key, value := iter.Key(), iter.Value()
|
||||
assert.EqualValues(t, key, expectedKey)
|
||||
assert.EqualValues(t, value, []byte("test4"))
|
||||
i += 1
|
||||
}
|
||||
assert.Equal(t, i, len(expected))
|
||||
}
|
||||
|
||||
func TestIAVLStoreQuery(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue