From 82f3fc7bfa97df41bba8fcdb08037058c54b4605 Mon Sep 17 00:00:00 2001 From: Barak Michener Date: Sat, 28 Jun 2014 16:47:37 -0400 Subject: [PATCH] Canonicalize leveldb internal iterator --- graph/leveldb/all_iterator.go | 34 +++++++++++++++++----------------- graph/leveldb/iterator.go | 28 ++++++++++++++-------------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/graph/leveldb/all_iterator.go b/graph/leveldb/all_iterator.go index 2c1edb1..3841b65 100644 --- a/graph/leveldb/all_iterator.go +++ b/graph/leveldb/all_iterator.go @@ -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 } } diff --git a/graph/leveldb/iterator.go b/graph/leveldb/iterator.go index 05d122b..2903829 100644 --- a/graph/leveldb/iterator.go +++ b/graph/leveldb/iterator.go @@ -31,7 +31,7 @@ type Iterator struct { checkId []byte dir string open bool - it iterator.Iterator + dbIt iterator.Iterator ts *TripleStore ro *opt.ReadOptions 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.ro = &opt.ReadOptions{} it.ro.DontFillCache = true - it.it = ts.db.NewIterator(nil, it.ro) + it.dbIt = ts.db.NewIterator(nil, it.ro) it.open = true it.ts = ts - ok := it.it.Seek(it.nextPrefix) + ok := it.dbIt.Seek(it.nextPrefix) if !ok { it.open = false - it.it.Release() + it.dbIt.Release() } return &it } func (it *Iterator) 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 } - ok := it.it.Seek(it.nextPrefix) + ok := it.dbIt.Seek(it.nextPrefix) if !ok { it.open = false - it.it.Release() + it.dbIt.Release() } } @@ -79,13 +79,13 @@ func (it *Iterator) Clone() graph.Iterator { func (it *Iterator) Close() { if it.open { - it.it.Release() + it.dbIt.Release() it.open = false } } func (it *Iterator) Next() (graph.TSVal, bool) { - if it.it == nil { + if it.dbIt == nil { it.Last = nil return nil, false } @@ -93,16 +93,16 @@ func (it *Iterator) Next() (graph.TSVal, bool) { it.Last = nil return nil, false } - if !it.it.Valid() { + if !it.dbIt.Valid() { it.Last = nil it.Close() return nil, false } - if bytes.HasPrefix(it.it.Key(), it.nextPrefix) { - out := make([]byte, len(it.it.Key())) - copy(out, it.it.Key()) + if bytes.HasPrefix(it.dbIt.Key(), it.nextPrefix) { + out := make([]byte, len(it.dbIt.Key())) + copy(out, it.dbIt.Key()) it.Last = out - ok := it.it.Next() + ok := it.dbIt.Next() if !ok { it.Close() }