Browse Source

db: goleveldb iterator

pull/1842/head
Ethan Buchman 7 years ago
parent
commit
3e5dbef6a2
3 changed files with 23 additions and 21 deletions
  1. +0
    -5
      db/common_test.go
  2. +22
    -15
      db/go_level_db.go
  3. +1
    -1
      db/util_test.go

+ 0
- 5
db/common_test.go View File

@ -80,11 +80,6 @@ func TestDBIteratorTwoKeys(t *testing.T) {
itr := db.Iterator(BeginningKey(), EndingKey())
checkValid(t, itr, true)
for i := 0; i < 10; i++ {
checkNext(t, itr, true)
checkValid(t, itr, true)
}
checkNext(t, itr, true)
checkValid(t, itr, true)


+ 22
- 15
db/go_level_db.go View File

@ -20,6 +20,8 @@ func init() {
registerDBCreator(GoLevelDBBackendStr, dbCreator, false)
}
var _ DB = (*GoLevelDB)(nil)
type GoLevelDB struct {
db *leveldb.DB
}
@ -168,15 +170,13 @@ func (mBatch *goLevelDBBatch) Write() {
// Iterator
func (db *GoLevelDB) Iterator(start, end []byte) Iterator {
/*
XXX
itr := &goLevelDBIterator{
source: db.db.NewIterator(nil, nil),
}
itr.Seek(nil)
return itr
*/
return nil
itr := &goLevelDBIterator{
source: db.db.NewIterator(nil, nil),
start: start,
end: end,
}
itr.source.Seek(start)
return itr
}
func (db *GoLevelDB) ReverseIterator(start, end []byte) Iterator {
@ -184,9 +184,16 @@ func (db *GoLevelDB) ReverseIterator(start, end []byte) Iterator {
return nil
}
var _ Iterator = (*goLevelDBIterator)(nil)
type goLevelDBIterator struct {
source iterator.Iterator
invalid bool
source iterator.Iterator
invalid bool
start, end []byte
}
func (it *goLevelDBIterator) Domain() ([]byte, []byte) {
return it.start, it.end
}
// Key returns a copy of the current key.
@ -217,10 +224,6 @@ func (it *goLevelDBIterator) GetError() error {
return it.source.Error()
}
func (it *goLevelDBIterator) Seek(key []byte) {
it.source.Seek(key)
}
func (it *goLevelDBIterator) Valid() bool {
if it.invalid {
return false
@ -246,3 +249,7 @@ func (it *goLevelDBIterator) Prev() {
func (it *goLevelDBIterator) Close() {
it.source.Release()
}
func (it *goLevelDBIterator) Release() {
it.source.Release()
}

+ 1
- 1
db/util_test.go View File

@ -50,7 +50,7 @@ func TestPrefixIteratorMatch3(t *testing.T) {
t.Run(fmt.Sprintf("Prefix w/ backend %s", backend), func(t *testing.T) {
db := newTempDB(t, backend)
db.SetSync(bz("3"), bz("value_3"))
itr := IteratePrefix(db, []byte("2"))
itr := IteratePrefix(db, []byte("4"))
// Once invalid...
checkInvalid(t, itr)


Loading…
Cancel
Save