Skip to content

Commit

Permalink
update for latest tmlibs
Browse files Browse the repository at this point in the history
  • Loading branch information
ebuchman committed Dec 20, 2017
1 parent e37147d commit 13b8294
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
8 changes: 5 additions & 3 deletions store/cachekvstore_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package store

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -95,7 +96,7 @@ func TestCacheKVIteratorBounds(t *testing.T) {
}

// iterate over all of them
itr := st.Iterator(dbm.BeginningKey(), dbm.EndingKey())
itr := st.Iterator(nil, nil)
var i = 0
for ; itr.Valid(); itr.Next() {
k, v := itr.Key(), itr.Value()
Expand All @@ -106,9 +107,10 @@ func TestCacheKVIteratorBounds(t *testing.T) {
assert.Equal(t, nItems, i)

// iterate over none
itr = st.Iterator(bz("money"), dbm.EndingKey())
itr = st.Iterator(bz("money"), nil)
i = 0
for ; itr.Valid(); itr.Next() {
fmt.Println(string(itr.Key()))
i += 1
}
assert.Equal(t, 0, i)
Expand Down Expand Up @@ -221,7 +223,7 @@ func TestCacheKVMergeIterator(t *testing.T) {

// iterate over whole domain
func assertIterateDomain(t *testing.T, st KVStore, expectedN int) {
itr := st.Iterator(dbm.BeginningKey(), dbm.EndingKey())
itr := st.Iterator(nil, nil)
var i = 0
for ; itr.Valid(); itr.Next() {
k, v := itr.Key(), itr.Value()
Expand Down
6 changes: 4 additions & 2 deletions store/memiterator.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package store

import dbm "github.com/tendermint/tmlibs/db"
import (
dbm "github.com/tendermint/tmlibs/db"
)

// Iterates over iterKVCache items.
// if key is nil, means it was deleted.
Expand All @@ -13,7 +15,7 @@ type memIterator struct {
func newMemIterator(start, end []byte, items []KVPair) *memIterator {
itemsInDomain := make([]KVPair, 0)
for _, item := range items {
if dbm.IsKeyInDomain(item.Key, start, end) {
if dbm.IsKeyInDomain(item.Key, start, end, keyCompare(end, start) < 0) {
itemsInDomain = append(itemsInDomain, item)
}
}
Expand Down
10 changes: 10 additions & 0 deletions store/types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package store

import (
"bytes"

"github.com/tendermint/go-wire/data"
"github.com/tendermint/tmlibs/db"
)
Expand Down Expand Up @@ -128,3 +130,11 @@ type CommitID struct {
func (cid CommitID) IsZero() bool {
return cid.Version == 0 && len(cid.Hash) == 0
}

// bytes.Compare but returns 0 if either key is nil
func keyCompare(k1, k2 []byte) int {
if k1 == nil || k2 == nil {
return 0
}
return bytes.Compare(k1, k2)
}

0 comments on commit 13b8294

Please sign in to comment.