Simplify Nexter interface
This change allows a Nexter to be used in the same manner as a scanner
using a for graph.Next(it) {} construction.
It is important that graph.Next(it) and any associated it.Result() calls
operate on the same iterator.
This commit is contained in:
parent
f8e28e066e
commit
b1a70d99aa
31 changed files with 168 additions and 233 deletions
|
|
@ -101,10 +101,10 @@ func (it *AllIterator) Clone() graph.Iterator {
|
|||
return out
|
||||
}
|
||||
|
||||
func (it *AllIterator) Next() (graph.Value, bool) {
|
||||
func (it *AllIterator) Next() bool {
|
||||
if !it.open {
|
||||
it.result = nil
|
||||
return nil, false
|
||||
return false
|
||||
}
|
||||
var out []byte
|
||||
out = make([]byte, len(it.iter.Key()))
|
||||
|
|
@ -115,10 +115,10 @@ func (it *AllIterator) Next() (graph.Value, bool) {
|
|||
}
|
||||
if !bytes.HasPrefix(out, it.prefix) {
|
||||
it.Close()
|
||||
return nil, false
|
||||
return false
|
||||
}
|
||||
it.result = out
|
||||
return out, true
|
||||
return true
|
||||
}
|
||||
|
||||
func (it *AllIterator) ResultTree() *graph.ResultTree {
|
||||
|
|
|
|||
|
|
@ -117,19 +117,19 @@ func (it *Iterator) Close() {
|
|||
}
|
||||
}
|
||||
|
||||
func (it *Iterator) Next() (graph.Value, bool) {
|
||||
func (it *Iterator) Next() bool {
|
||||
if it.iter == nil {
|
||||
it.result = nil
|
||||
return nil, false
|
||||
return false
|
||||
}
|
||||
if !it.open {
|
||||
it.result = nil
|
||||
return nil, false
|
||||
return false
|
||||
}
|
||||
if !it.iter.Valid() {
|
||||
it.result = nil
|
||||
it.Close()
|
||||
return nil, false
|
||||
return false
|
||||
}
|
||||
if bytes.HasPrefix(it.iter.Key(), it.nextPrefix) {
|
||||
out := make([]byte, len(it.iter.Key()))
|
||||
|
|
@ -139,11 +139,11 @@ func (it *Iterator) Next() (graph.Value, bool) {
|
|||
if !ok {
|
||||
it.Close()
|
||||
}
|
||||
return out, true
|
||||
return true
|
||||
}
|
||||
it.Close()
|
||||
it.result = nil
|
||||
return nil, false
|
||||
return false
|
||||
}
|
||||
|
||||
func (it *Iterator) ResultTree() *graph.ResultTree {
|
||||
|
|
|
|||
|
|
@ -45,12 +45,8 @@ func makeTripleSet() []*quad.Quad {
|
|||
|
||||
func iteratedTriples(qs graph.TripleStore, it graph.Iterator) []*quad.Quad {
|
||||
var res ordered
|
||||
for {
|
||||
val, ok := graph.Next(it)
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
res = append(res, qs.Quad(val))
|
||||
for graph.Next(it) {
|
||||
res = append(res, qs.Quad(it.Result()))
|
||||
}
|
||||
sort.Sort(res)
|
||||
return res
|
||||
|
|
@ -85,12 +81,8 @@ func (o ordered) Swap(i, j int) { o[i], o[j] = o[j], o[i] }
|
|||
|
||||
func iteratedNames(qs graph.TripleStore, it graph.Iterator) []string {
|
||||
var res []string
|
||||
for {
|
||||
val, ok := graph.Next(it)
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
res = append(res, qs.NameOf(val))
|
||||
for graph.Next(it) {
|
||||
res = append(res, qs.NameOf(it.Result()))
|
||||
}
|
||||
sort.Strings(res)
|
||||
return res
|
||||
|
|
@ -266,8 +258,8 @@ func TestIterator(t *testing.T) {
|
|||
it.Reset()
|
||||
|
||||
it = qs.TriplesAllIterator()
|
||||
edge, _ := graph.Next(it)
|
||||
triple := qs.Quad(edge)
|
||||
graph.Next(it)
|
||||
triple := qs.Quad(it.Result())
|
||||
set := makeTripleSet()
|
||||
var ok bool
|
||||
for _, t := range set {
|
||||
|
|
|
|||
|
|
@ -37,10 +37,10 @@ func (ts *TripleStore) optimizeLinksTo(it *iterator.LinksTo) (graph.Iterator, bo
|
|||
if primary.Type() == graph.Fixed {
|
||||
size, _ := primary.Size()
|
||||
if size == 1 {
|
||||
val, ok := graph.Next(primary)
|
||||
if !ok {
|
||||
panic("Sizes lie")
|
||||
if !graph.Next(primary) {
|
||||
panic("unexpected size during optimize")
|
||||
}
|
||||
val := primary.Result()
|
||||
newIt := ts.TripleIterator(it.Direction(), val)
|
||||
nt := newIt.Tagger()
|
||||
nt.CopyFrom(it)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue