parent
cb177aa390
commit
f8e28e066e
20 changed files with 37 additions and 37 deletions
2
TODO.md
2
TODO.md
|
|
@ -52,7 +52,7 @@ An important failure of MQL before was that it was never well-specified. Let's n
|
||||||
### New Iterators
|
### New Iterators
|
||||||
|
|
||||||
#### Limit Iterator
|
#### 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
|
## Medium Term
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -79,15 +79,15 @@ type Iterator interface {
|
||||||
// To get the full results of iteration, do the following:
|
// To get the full results of iteration, do the following:
|
||||||
// while (!Next()):
|
// while (!Next()):
|
||||||
// emit result
|
// emit result
|
||||||
// while (!NextResult()):
|
// while (!NextPath()):
|
||||||
// emit result
|
// emit result
|
||||||
//
|
//
|
||||||
// All of them should set iterator.Last to be the last returned value, to
|
// All of them should set iterator.Last to be the last returned value, to
|
||||||
// make results work.
|
// 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.
|
// from the bottom up.
|
||||||
NextResult() bool
|
NextPath() bool
|
||||||
|
|
||||||
// Contains returns whether the value is within the set held by the iterator.
|
// Contains returns whether the value is within the set held by the iterator.
|
||||||
Contains(Value) bool
|
Contains(Value) bool
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@ func (it *Int64) Result() graph.Value {
|
||||||
return it.result
|
return it.result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *Int64) NextResult() bool {
|
func (it *Int64) NextPath() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -236,15 +236,15 @@ func (it *And) Size() (int64, bool) {
|
||||||
return val, b
|
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
|
// which satisfy our previous result that are not the result itself. Our
|
||||||
// subiterators might, however, so just pass the call recursively.
|
// subiterators might, however, so just pass the call recursively.
|
||||||
func (it *And) NextResult() bool {
|
func (it *And) NextPath() bool {
|
||||||
if it.primaryIt.NextResult() {
|
if it.primaryIt.NextPath() {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
for _, sub := range it.internalIterators {
|
for _, sub := range it.internalIterators {
|
||||||
if sub.NextResult() {
|
if sub.NextPath() {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -156,7 +156,7 @@ func (it *Fixed) Result() graph.Value {
|
||||||
return it.result
|
return it.result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *Fixed) NextResult() bool {
|
func (it *Fixed) NextPath() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,9 @@ package iterator
|
||||||
// value to check, it means "Check all predicates that have this value for your
|
// 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
|
// 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
|
// 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
|
// 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.
|
// 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.
|
// Get the next result that matches this branch.
|
||||||
func (it *HasA) NextResult() bool {
|
func (it *HasA) NextPath() bool {
|
||||||
// Order here is important. If the subiterator has a NextResult, then we
|
// 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.
|
// 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().
|
// 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.
|
// iterator tree up, and we need to respect that.
|
||||||
if it.primaryIt.NextResult() {
|
if it.primaryIt.NextPath() {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return it.NextContains()
|
return it.NextContains()
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ func (it *Null) SubIterators() []graph.Iterator {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *Null) NextResult() bool {
|
func (it *Null) NextPath() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -183,8 +183,8 @@ func (it *LinksTo) Close() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// We won't ever have a new result, but our subiterators might.
|
// We won't ever have a new result, but our subiterators might.
|
||||||
func (it *LinksTo) NextResult() bool {
|
func (it *LinksTo) NextPath() bool {
|
||||||
return it.primaryIt.NextResult()
|
return it.primaryIt.NextPath()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register the LinksTo.
|
// Register the LinksTo.
|
||||||
|
|
|
||||||
|
|
@ -88,9 +88,9 @@ func (it *Optional) Result() graph.Value {
|
||||||
// An optional iterator only has a next result if, (a) last time we checked
|
// 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
|
// we had any results whatsoever, and (b) there was another subresult in our
|
||||||
// optional subbranch.
|
// optional subbranch.
|
||||||
func (it *Optional) NextResult() bool {
|
func (it *Optional) NextPath() bool {
|
||||||
if it.lastCheck {
|
if it.lastCheck {
|
||||||
return it.subIt.NextResult()
|
return it.subIt.NextPath()
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -228,13 +228,13 @@ func (it *Or) Size() (int64, bool) {
|
||||||
return val, b
|
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
|
// 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
|
// subiterators might, however, so just pass the call recursively. In the case of
|
||||||
// shortcircuiting, only allow new results from the currently checked graph.iterator
|
// 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 {
|
if it.currentIterator != -1 {
|
||||||
return it.internalIterators[it.currentIterator].NextResult()
|
return it.internalIterators[it.currentIterator].NextPath()
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -152,9 +152,9 @@ func (it *Comparison) Result() graph.Value {
|
||||||
return it.result
|
return it.result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *Comparison) NextResult() bool {
|
func (it *Comparison) NextPath() bool {
|
||||||
for {
|
for {
|
||||||
hasNext := it.subIt.NextResult()
|
hasNext := it.subIt.NextPath()
|
||||||
if !hasNext {
|
if !hasNext {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,7 @@ func (it *AllIterator) Result() graph.Value {
|
||||||
return it.result
|
return it.result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *AllIterator) NextResult() bool {
|
func (it *AllIterator) NextPath() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -154,7 +154,7 @@ func (it *Iterator) Result() graph.Value {
|
||||||
return it.result
|
return it.result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *Iterator) NextResult() bool {
|
func (it *Iterator) NextPath() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@ func (it *Iterator) Result() graph.Value {
|
||||||
return it.result
|
return it.result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *Iterator) NextResult() bool {
|
func (it *Iterator) NextPath() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,7 @@ func TestIteratorsAndNextResultOrderA(t *testing.T) {
|
||||||
)
|
)
|
||||||
for {
|
for {
|
||||||
got = append(got, ts.NameOf(all.Result()))
|
got = append(got, ts.NameOf(all.Result()))
|
||||||
if !outerAnd.NextResult() {
|
if !outerAnd.NextPath() {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -165,7 +165,7 @@ func (it *Iterator) Result() graph.Value {
|
||||||
return it.result
|
return it.result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *Iterator) NextResult() bool {
|
func (it *Iterator) NextPath() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ func StringResultTreeEvaluator(it Nexter) string {
|
||||||
}
|
}
|
||||||
out += it.ResultTree().String()
|
out += it.ResultTree().String()
|
||||||
out += "\n"
|
out += "\n"
|
||||||
for it.NextResult() == true {
|
for it.NextPath() == true {
|
||||||
out += " "
|
out += " "
|
||||||
out += it.ResultTree().String()
|
out += it.ResultTree().String()
|
||||||
out += "\n"
|
out += "\n"
|
||||||
|
|
|
||||||
|
|
@ -162,7 +162,7 @@ func runIteratorToArray(it graph.Iterator, ses *Session, limit int) []map[string
|
||||||
if limit >= 0 && count >= limit {
|
if limit >= 0 && count >= limit {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
for it.NextResult() == true {
|
for it.NextPath() == true {
|
||||||
if ses.doHalt {
|
if ses.doHalt {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -220,7 +220,7 @@ func runIteratorWithCallback(it graph.Iterator, ses *Session, callback otto.Valu
|
||||||
if limit >= 0 && count >= limit {
|
if limit >= 0 && count >= limit {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
for it.NextResult() == true {
|
for it.NextPath() == true {
|
||||||
if ses.doHalt {
|
if ses.doHalt {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -259,7 +259,7 @@ func runIteratorOnSession(it graph.Iterator, ses *Session) {
|
||||||
if !cont {
|
if !cont {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
for it.NextResult() == true {
|
for it.NextPath() == true {
|
||||||
if ses.doHalt {
|
if ses.doHalt {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ func (s *Session) ExecInput(input string, c chan interface{}, limit int) {
|
||||||
tags := make(map[string]graph.Value)
|
tags := make(map[string]graph.Value)
|
||||||
it.TagResults(tags)
|
it.TagResults(tags)
|
||||||
c <- tags
|
c <- tags
|
||||||
for it.NextResult() == true {
|
for it.NextPath() == true {
|
||||||
tags := make(map[string]graph.Value)
|
tags := make(map[string]graph.Value)
|
||||||
it.TagResults(tags)
|
it.TagResults(tags)
|
||||||
c <- tags
|
c <- tags
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ func (s *Session) ExecInput(input string, out chan interface{}, limit int) {
|
||||||
if nResults > limit && limit != -1 {
|
if nResults > limit && limit != -1 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
for it.NextResult() == true {
|
for it.NextPath() == true {
|
||||||
tags := make(map[string]graph.Value)
|
tags := make(map[string]graph.Value)
|
||||||
it.TagResults(tags)
|
it.TagResults(tags)
|
||||||
out <- &tags
|
out <- &tags
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue