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
|
|
@ -36,15 +36,13 @@ func (it *AllIterator) SubIterators() []graph.Iterator {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (it *AllIterator) Next() (graph.Value, bool) {
|
||||
next, out := it.Int64.Next()
|
||||
if !out {
|
||||
return next, out
|
||||
func (it *AllIterator) Next() bool {
|
||||
if !it.Int64.Next() {
|
||||
return false
|
||||
}
|
||||
i64 := next.(int64)
|
||||
_, ok := it.ts.revIdMap[i64]
|
||||
_, ok := it.ts.revIdMap[it.Int64.Result().(int64)]
|
||||
if !ok {
|
||||
return it.Next()
|
||||
}
|
||||
return next, out
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ func (it *Iterator) Clone() graph.Iterator {
|
|||
|
||||
func (it *Iterator) Close() {}
|
||||
|
||||
func (it *Iterator) Next() (graph.Value, bool) {
|
||||
func (it *Iterator) Next() bool {
|
||||
graph.NextLogIn(it)
|
||||
if it.tree.Max() == nil || it.result == int64(it.tree.Max().(Int64)) {
|
||||
return graph.NextLogOut(it, nil, false)
|
||||
|
|
|
|||
|
|
@ -132,11 +132,8 @@ func (ts *TripleStore) tripleExists(t *quad.Quad) (bool, int64) {
|
|||
}
|
||||
it := NewLlrbIterator(smallest_tree, "")
|
||||
|
||||
for {
|
||||
val, ok := it.Next()
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
for it.Next() {
|
||||
val := it.Result()
|
||||
if t.Equals(&ts.triples[val.(int64)]) {
|
||||
return true, val.(int64)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -114,10 +114,10 @@ func TestIteratorsAndNextResultOrderA(t *testing.T) {
|
|||
outerAnd.AddSubIterator(fixed)
|
||||
outerAnd.AddSubIterator(hasa)
|
||||
|
||||
val, ok := outerAnd.Next()
|
||||
if !ok {
|
||||
if !outerAnd.Next() {
|
||||
t.Error("Expected one matching subtree")
|
||||
}
|
||||
val := outerAnd.Result()
|
||||
if ts.NameOf(val) != "C" {
|
||||
t.Errorf("Matching subtree should be %s, got %s", "barak", ts.NameOf(val))
|
||||
}
|
||||
|
|
@ -138,8 +138,7 @@ func TestIteratorsAndNextResultOrderA(t *testing.T) {
|
|||
t.Errorf("Unexpected result, got:%q expect:%q", got, expect)
|
||||
}
|
||||
|
||||
val, ok = outerAnd.Next()
|
||||
if ok {
|
||||
if outerAnd.Next() {
|
||||
t.Error("More than one possible top level output?")
|
||||
}
|
||||
}
|
||||
|
|
@ -190,8 +189,7 @@ func TestRemoveTriple(t *testing.T) {
|
|||
hasa := iterator.NewHasA(ts, innerAnd, quad.Object)
|
||||
|
||||
newIt, _ := hasa.Optimize()
|
||||
_, ok := graph.Next(newIt)
|
||||
if ok {
|
||||
if graph.Next(newIt) {
|
||||
t.Error("E should not have any followers.")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue