Canonicalize leveldb internal iterator
This commit is contained in:
parent
44ae0b523e
commit
82f3fc7bfa
2 changed files with 31 additions and 31 deletions
|
|
@ -30,7 +30,7 @@ type AllIterator struct {
|
||||||
prefix []byte
|
prefix []byte
|
||||||
dir string
|
dir string
|
||||||
open bool
|
open bool
|
||||||
it iterator.Iterator
|
dbIt iterator.Iterator
|
||||||
ts *TripleStore
|
ts *TripleStore
|
||||||
ro *opt.ReadOptions
|
ro *opt.ReadOptions
|
||||||
}
|
}
|
||||||
|
|
@ -40,28 +40,28 @@ func NewAllIterator(prefix, dir string, ts *TripleStore) *AllIterator {
|
||||||
graph.BaseIteratorInit(&it.BaseIterator)
|
graph.BaseIteratorInit(&it.BaseIterator)
|
||||||
it.ro = &opt.ReadOptions{}
|
it.ro = &opt.ReadOptions{}
|
||||||
it.ro.DontFillCache = true
|
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.prefix = []byte(prefix)
|
||||||
it.dir = dir
|
it.dir = dir
|
||||||
it.open = true
|
it.open = true
|
||||||
it.ts = ts
|
it.ts = ts
|
||||||
it.it.Seek(it.prefix)
|
it.dbIt.Seek(it.prefix)
|
||||||
if !it.it.Valid() {
|
if !it.dbIt.Valid() {
|
||||||
it.open = false
|
it.open = false
|
||||||
it.it.Release()
|
it.dbIt.Release()
|
||||||
}
|
}
|
||||||
return &it
|
return &it
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *AllIterator) Reset() {
|
func (it *AllIterator) Reset() {
|
||||||
if !it.open {
|
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.open = true
|
||||||
}
|
}
|
||||||
it.it.Seek(it.prefix)
|
it.dbIt.Seek(it.prefix)
|
||||||
if !it.it.Valid() {
|
if !it.dbIt.Valid() {
|
||||||
it.open = false
|
it.open = false
|
||||||
it.it.Release()
|
it.dbIt.Release()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,10 +77,10 @@ func (it *AllIterator) Next() (graph.TSVal, bool) {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
var out []byte
|
var out []byte
|
||||||
out = make([]byte, len(it.it.Key()))
|
out = make([]byte, len(it.dbIt.Key()))
|
||||||
copy(out, it.it.Key())
|
copy(out, it.dbIt.Key())
|
||||||
it.it.Next()
|
it.dbIt.Next()
|
||||||
if !it.it.Valid() {
|
if !it.dbIt.Valid() {
|
||||||
it.Close()
|
it.Close()
|
||||||
}
|
}
|
||||||
if !bytes.HasPrefix(out, it.prefix) {
|
if !bytes.HasPrefix(out, it.prefix) {
|
||||||
|
|
@ -96,10 +96,10 @@ func (it *AllIterator) Check(v graph.TSVal) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lit *AllIterator) Close() {
|
func (it *AllIterator) Close() {
|
||||||
if lit.open {
|
if it.open {
|
||||||
lit.it.Release()
|
it.dbIt.Release()
|
||||||
lit.open = false
|
it.open = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ type Iterator struct {
|
||||||
checkId []byte
|
checkId []byte
|
||||||
dir string
|
dir string
|
||||||
open bool
|
open bool
|
||||||
it iterator.Iterator
|
dbIt iterator.Iterator
|
||||||
ts *TripleStore
|
ts *TripleStore
|
||||||
ro *opt.ReadOptions
|
ro *opt.ReadOptions
|
||||||
originalPrefix string
|
originalPrefix string
|
||||||
|
|
@ -48,26 +48,26 @@ func NewIterator(prefix, dir string, value graph.TSVal, ts *TripleStore) *Iterat
|
||||||
it.nextPrefix = append(it.nextPrefix, []byte(it.checkId[1:])...)
|
it.nextPrefix = append(it.nextPrefix, []byte(it.checkId[1:])...)
|
||||||
it.ro = &opt.ReadOptions{}
|
it.ro = &opt.ReadOptions{}
|
||||||
it.ro.DontFillCache = true
|
it.ro.DontFillCache = true
|
||||||
it.it = ts.db.NewIterator(nil, it.ro)
|
it.dbIt = ts.db.NewIterator(nil, it.ro)
|
||||||
it.open = true
|
it.open = true
|
||||||
it.ts = ts
|
it.ts = ts
|
||||||
ok := it.it.Seek(it.nextPrefix)
|
ok := it.dbIt.Seek(it.nextPrefix)
|
||||||
if !ok {
|
if !ok {
|
||||||
it.open = false
|
it.open = false
|
||||||
it.it.Release()
|
it.dbIt.Release()
|
||||||
}
|
}
|
||||||
return &it
|
return &it
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *Iterator) Reset() {
|
func (it *Iterator) Reset() {
|
||||||
if !it.open {
|
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.open = true
|
||||||
}
|
}
|
||||||
ok := it.it.Seek(it.nextPrefix)
|
ok := it.dbIt.Seek(it.nextPrefix)
|
||||||
if !ok {
|
if !ok {
|
||||||
it.open = false
|
it.open = false
|
||||||
it.it.Release()
|
it.dbIt.Release()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -79,13 +79,13 @@ func (it *Iterator) Clone() graph.Iterator {
|
||||||
|
|
||||||
func (it *Iterator) Close() {
|
func (it *Iterator) Close() {
|
||||||
if it.open {
|
if it.open {
|
||||||
it.it.Release()
|
it.dbIt.Release()
|
||||||
it.open = false
|
it.open = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *Iterator) Next() (graph.TSVal, bool) {
|
func (it *Iterator) Next() (graph.TSVal, bool) {
|
||||||
if it.it == nil {
|
if it.dbIt == nil {
|
||||||
it.Last = nil
|
it.Last = nil
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
@ -93,16 +93,16 @@ func (it *Iterator) Next() (graph.TSVal, bool) {
|
||||||
it.Last = nil
|
it.Last = nil
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
if !it.it.Valid() {
|
if !it.dbIt.Valid() {
|
||||||
it.Last = nil
|
it.Last = nil
|
||||||
it.Close()
|
it.Close()
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
if bytes.HasPrefix(it.it.Key(), it.nextPrefix) {
|
if bytes.HasPrefix(it.dbIt.Key(), it.nextPrefix) {
|
||||||
out := make([]byte, len(it.it.Key()))
|
out := make([]byte, len(it.dbIt.Key()))
|
||||||
copy(out, it.it.Key())
|
copy(out, it.dbIt.Key())
|
||||||
it.Last = out
|
it.Last = out
|
||||||
ok := it.it.Next()
|
ok := it.dbIt.Next()
|
||||||
if !ok {
|
if !ok {
|
||||||
it.Close()
|
it.Close()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue