Canonicalize leveldb internal iterator

This commit is contained in:
Barak Michener 2014-06-28 16:47:37 -04:00
parent 44ae0b523e
commit 82f3fc7bfa
2 changed files with 31 additions and 31 deletions

View file

@ -30,7 +30,7 @@ type AllIterator struct {
prefix []byte
dir string
open bool
it iterator.Iterator
dbIt iterator.Iterator
ts *TripleStore
ro *opt.ReadOptions
}
@ -40,28 +40,28 @@ func NewAllIterator(prefix, dir string, ts *TripleStore) *AllIterator {
graph.BaseIteratorInit(&it.BaseIterator)
it.ro = &opt.ReadOptions{}
it.ro.DontFillCache = true
it.it = ts.db.NewIterator(nil, it.ro)
it.dbIt = ts.db.NewIterator(nil, it.ro)
it.prefix = []byte(prefix)
it.dir = dir
it.open = true
it.ts = ts
it.it.Seek(it.prefix)
if !it.it.Valid() {
it.dbIt.Seek(it.prefix)
if !it.dbIt.Valid() {
it.open = false
it.it.Release()
it.dbIt.Release()
}
return &it
}
func (it *AllIterator) Reset() {
if !it.open {
it.it = it.ts.db.NewIterator(nil, it.ro)
it.dbIt = it.ts.db.NewIterator(nil, it.ro)
it.open = true
}
it.it.Seek(it.prefix)
if !it.it.Valid() {
it.dbIt.Seek(it.prefix)
if !it.dbIt.Valid() {
it.open = false
it.it.Release()
it.dbIt.Release()
}
}
@ -77,10 +77,10 @@ func (it *AllIterator) Next() (graph.TSVal, bool) {
return nil, false
}
var out []byte
out = make([]byte, len(it.it.Key()))
copy(out, it.it.Key())
it.it.Next()
if !it.it.Valid() {
out = make([]byte, len(it.dbIt.Key()))
copy(out, it.dbIt.Key())
it.dbIt.Next()
if !it.dbIt.Valid() {
it.Close()
}
if !bytes.HasPrefix(out, it.prefix) {
@ -96,10 +96,10 @@ func (it *AllIterator) Check(v graph.TSVal) bool {
return true
}
func (lit *AllIterator) Close() {
if lit.open {
lit.it.Release()
lit.open = false
func (it *AllIterator) Close() {
if it.open {
it.dbIt.Release()
it.open = false
}
}