Rename NextResult -> NextPath

See discussion in #92.
This commit is contained in:
kortschak 2014-08-01 07:27:16 +09:30
parent cb177aa390
commit f8e28e066e
20 changed files with 37 additions and 37 deletions

View file

@ -52,7 +52,7 @@ An important failure of MQL before was that it was never well-specified. Let's n
### New Iterators
#### Limit Iterator
The necessary component to make mid-query limit work. Acts as a limit on Next(), a passthrough on Contains(), and a limit on NextResult()
The necessary component to make mid-query limit work. Acts as a limit on Next(), a passthrough on Contains(), and a limit on NextPath()
## Medium Term

View file

@ -79,15 +79,15 @@ type Iterator interface {
// To get the full results of iteration, do the following:
// while (!Next()):
// emit result
// while (!NextResult()):
// while (!NextPath()):
// emit result
//
// All of them should set iterator.Last to be the last returned value, to
// make results work.
//
// NextResult() advances iterators that may have more than one valid result,
// NextPath() advances iterators that may have more than one valid result,
// from the bottom up.
NextResult() bool
NextPath() bool
// Contains returns whether the value is within the set held by the iterator.
Contains(Value) bool

View file

@ -110,7 +110,7 @@ func (it *Int64) Result() graph.Value {
return it.result
}
func (it *Int64) NextResult() bool {
func (it *Int64) NextPath() bool {
return false
}

View file

@ -236,15 +236,15 @@ func (it *And) Size() (int64, bool) {
return val, b
}
// An And has no NextResult of its own -- that is, there are no other values
// An And has no NextPath of its own -- that is, there are no other values
// which satisfy our previous result that are not the result itself. Our
// subiterators might, however, so just pass the call recursively.
func (it *And) NextResult() bool {
if it.primaryIt.NextResult() {
func (it *And) NextPath() bool {
if it.primaryIt.NextPath() {
return true
}
for _, sub := range it.internalIterators {
if sub.NextResult() {
if sub.NextPath() {
return true
}
}

View file

@ -156,7 +156,7 @@ func (it *Fixed) Result() graph.Value {
return it.result
}
func (it *Fixed) NextResult() bool {
func (it *Fixed) NextPath() bool {
return false
}

View file

@ -27,9 +27,9 @@ package iterator
// value to check, it means "Check all predicates that have this value for your
// direction against the subiterator." This would imply that there's more than
// one possibility for the same Contains()ed value. While we could return the
// number of options, it's simpler to return one, and then call NextResult()
// number of options, it's simpler to return one, and then call NextPath()
// enough times to enumerate the options. (In fact, one could argue that the
// raison d'etre for NextResult() is this iterator).
// raison d'etre for NextPath() is this iterator).
//
// Alternatively, can be seen as the dual of the LinksTo iterator.
@ -175,14 +175,14 @@ func (it *HasA) NextContains() bool {
}
// Get the next result that matches this branch.
func (it *HasA) NextResult() bool {
// Order here is important. If the subiterator has a NextResult, then we
func (it *HasA) NextPath() bool {
// Order here is important. If the subiterator has a NextPath, then we
// need do nothing -- there is a next result, and we shouldn't move forward.
// However, we then need to get the next result from our last Contains().
//
// The upshot is, the end of NextResult() bubbles up from the bottom of the
// The upshot is, the end of NextPath() bubbles up from the bottom of the
// iterator tree up, and we need to respect that.
if it.primaryIt.NextResult() {
if it.primaryIt.NextPath() {
return true
}
return it.NextContains()

View file

@ -95,7 +95,7 @@ func (it *Null) SubIterators() []graph.Iterator {
return nil
}
func (it *Null) NextResult() bool {
func (it *Null) NextPath() bool {
return false
}

View file

@ -183,8 +183,8 @@ func (it *LinksTo) Close() {
}
// We won't ever have a new result, but our subiterators might.
func (it *LinksTo) NextResult() bool {
return it.primaryIt.NextResult()
func (it *LinksTo) NextPath() bool {
return it.primaryIt.NextPath()
}
// Register the LinksTo.

View file

@ -88,9 +88,9 @@ func (it *Optional) Result() graph.Value {
// An optional iterator only has a next result if, (a) last time we checked
// we had any results whatsoever, and (b) there was another subresult in our
// optional subbranch.
func (it *Optional) NextResult() bool {
func (it *Optional) NextPath() bool {
if it.lastCheck {
return it.subIt.NextResult()
return it.subIt.NextPath()
}
return false
}

View file

@ -228,13 +228,13 @@ func (it *Or) Size() (int64, bool) {
return val, b
}
// An Or has no NextResult of its own -- that is, there are no other values
// An Or has no NextPath of its own -- that is, there are no other values
// which satisfy our previous result that are not the result itself. Our
// subiterators might, however, so just pass the call recursively. In the case of
// shortcircuiting, only allow new results from the currently checked graph.iterator
func (it *Or) NextResult() bool {
func (it *Or) NextPath() bool {
if it.currentIterator != -1 {
return it.internalIterators[it.currentIterator].NextResult()
return it.internalIterators[it.currentIterator].NextPath()
}
return false
}

View file

@ -152,9 +152,9 @@ func (it *Comparison) Result() graph.Value {
return it.result
}
func (it *Comparison) NextResult() bool {
func (it *Comparison) NextPath() bool {
for {
hasNext := it.subIt.NextResult()
hasNext := it.subIt.NextPath()
if !hasNext {
return false
}

View file

@ -129,7 +129,7 @@ func (it *AllIterator) Result() graph.Value {
return it.result
}
func (it *AllIterator) NextResult() bool {
func (it *AllIterator) NextPath() bool {
return false
}

View file

@ -154,7 +154,7 @@ func (it *Iterator) Result() graph.Value {
return it.result
}
func (it *Iterator) NextResult() bool {
func (it *Iterator) NextPath() bool {
return false
}

View file

@ -111,7 +111,7 @@ func (it *Iterator) Result() graph.Value {
return it.result
}
func (it *Iterator) NextResult() bool {
func (it *Iterator) NextPath() bool {
return false
}

View file

@ -128,7 +128,7 @@ func TestIteratorsAndNextResultOrderA(t *testing.T) {
)
for {
got = append(got, ts.NameOf(all.Result()))
if !outerAnd.NextResult() {
if !outerAnd.NextPath() {
break
}
}

View file

@ -165,7 +165,7 @@ func (it *Iterator) Result() graph.Value {
return it.result
}
func (it *Iterator) NextResult() bool {
func (it *Iterator) NextPath() bool {
return false
}

View file

@ -50,7 +50,7 @@ func StringResultTreeEvaluator(it Nexter) string {
}
out += it.ResultTree().String()
out += "\n"
for it.NextResult() == true {
for it.NextPath() == true {
out += " "
out += it.ResultTree().String()
out += "\n"

View file

@ -162,7 +162,7 @@ func runIteratorToArray(it graph.Iterator, ses *Session, limit int) []map[string
if limit >= 0 && count >= limit {
break
}
for it.NextResult() == true {
for it.NextPath() == true {
if ses.doHalt {
return nil
}
@ -220,7 +220,7 @@ func runIteratorWithCallback(it graph.Iterator, ses *Session, callback otto.Valu
if limit >= 0 && count >= limit {
break
}
for it.NextResult() == true {
for it.NextPath() == true {
if ses.doHalt {
return
}
@ -259,7 +259,7 @@ func runIteratorOnSession(it graph.Iterator, ses *Session) {
if !cont {
break
}
for it.NextResult() == true {
for it.NextPath() == true {
if ses.doHalt {
return
}

View file

@ -96,7 +96,7 @@ func (s *Session) ExecInput(input string, c chan interface{}, limit int) {
tags := make(map[string]graph.Value)
it.TagResults(tags)
c <- tags
for it.NextResult() == true {
for it.NextPath() == true {
tags := make(map[string]graph.Value)
it.TagResults(tags)
c <- tags

View file

@ -89,7 +89,7 @@ func (s *Session) ExecInput(input string, out chan interface{}, limit int) {
if nResults > limit && limit != -1 {
break
}
for it.NextResult() == true {
for it.NextPath() == true {
tags := make(map[string]graph.Value)
it.TagResults(tags)
out <- &tags