Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add go.mod file, update for 6.16 #216

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add SetIterateLowerBound and testcase
  • Loading branch information
houfazhou authored and roysc committed Jul 14, 2021
commit 300fe467ef4a83c3f53c16e8b3ef63d958352a88
33 changes: 33 additions & 0 deletions iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,36 @@ func TestIterator(t *testing.T) {
ensure.Nil(t, iter.Err())
ensure.DeepEqual(t, actualKeys, givenKeys)
}

func TestIteratorWithRange(t *testing.T) {
db := newTestDB(t, "TestIterator", nil)
defer db.Close()

// insert keys
givenKeys := [][]byte{
[]byte("key1"),
[]byte("key2"),
[]byte("key3"),
[]byte("key4"),
[]byte("key5"),
}
wo := NewDefaultWriteOptions()
for _, k := range givenKeys {
ensure.Nil(t, db.Put(wo, k, []byte("val")))
}

ro := NewDefaultReadOptions()
ro.SetIterateLowerBound([]byte("key2"))
ro.SetIterateUpperBound([]byte("key4"))

iter := db.NewIterator(ro)
defer iter.Close()
var actualKeys [][]byte
for iter.SeekToFirst(); iter.Valid(); iter.Next() {
key := make([]byte, 4)
copy(key, iter.Key().Data())
actualKeys = append(actualKeys, key)
}
ensure.Nil(t, iter.Err())
ensure.DeepEqual(t, len(actualKeys), 2)
}
18 changes: 16 additions & 2 deletions options_read.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,29 @@ func (opts *ReadOptions) SetTailing(value bool) {
// not a valid entry. If iterator_extractor is not null, the Seek target
// and iterator_upper_bound need to have the same prefix.
// This is because ordering is not guaranteed outside of prefix domain.
// There is no lower bound on the iterator. If needed, that can be easily
// implemented.
// Default: nullptr
func (opts *ReadOptions) SetIterateUpperBound(key []byte) {
cKey := byteToChar(key)
cKeyLen := C.size_t(len(key))
C.rocksdb_readoptions_set_iterate_upper_bound(opts.c, cKey, cKeyLen)
}

// SetIterateLowerBound specifies "iterate_lower_bound", which defines
// the smallest key at which the backward iterator can return an entry.
// Once the bound is passed, Valid() will be false.
// `iterate_lower_bound` is inclusive ie the bound value is a valid
// entry.
//
// If prefix_extractor is not null, the Seek target and `iterate_lower_bound`
// need to have the same prefix. This is because ordering is not guaranteed
// outside of prefix domain.
// Default: nullptr
func (opts *ReadOptions) SetIterateLowerBound(key []byte) {
cKey := byteToChar(key)
cKeyLen := C.size_t(len(key))
C.rocksdb_readoptions_set_iterate_lower_bound(opts.c, cKey, cKeyLen)
}

// SetPinData specifies the value of "pin_data". If true, it keeps the blocks
// loaded by the iterator pinned in memory as long as the iterator is not deleted,
// If used when reading from tables created with
Expand Down