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:
kortschak 2014-08-01 09:15:02 +09:30
parent f8e28e066e
commit b1a70d99aa
31 changed files with 168 additions and 233 deletions

View file

@ -151,25 +151,20 @@ func (it *And) AddSubIterator(sub graph.Iterator) {
it.itCount++
}
// Returns the Next value from the And iterator. Because the And is the
// intersection of its subiterators, it must choose one subiterator to produce a
// candidate, and check this value against the subiterators. A productive choice
// of primary iterator is therefore very important.
func (it *And) Next() (graph.Value, bool) {
// Returns advances the And iterator. Because the And is the intersection of its
// subiterators, it must choose one subiterator to produce a candidate, and check
// this value against the subiterators. A productive choice of primary iterator
// is therefore very important.
func (it *And) Next() bool {
graph.NextLogIn(it)
var curr graph.Value
var exists bool
for {
curr, exists = graph.Next(it.primaryIt)
if !exists {
return graph.NextLogOut(it, nil, false)
}
for graph.Next(it.primaryIt) {
curr := it.primaryIt.Result()
if it.subItsContain(curr) {
it.result = curr
return graph.NextLogOut(it, curr, true)
}
}
panic("unreachable")
return graph.NextLogOut(it, nil, false)
}
func (it *And) Result() graph.Value {