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
|
|
@ -158,16 +158,13 @@ func (it *HasA) Contains(val graph.Value) bool {
|
|||
// result iterator (a triple iterator based on the last checked value) and returns true if
|
||||
// another match is made.
|
||||
func (it *HasA) NextContains() bool {
|
||||
for {
|
||||
linkVal, ok := graph.Next(it.resultIt)
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
for graph.Next(it.resultIt) {
|
||||
link := it.resultIt.Result()
|
||||
if glog.V(4) {
|
||||
glog.V(4).Infoln("Quad is", it.ts.Quad(linkVal))
|
||||
glog.V(4).Infoln("Quad is", it.ts.Quad(link))
|
||||
}
|
||||
if it.primaryIt.Contains(linkVal) {
|
||||
it.result = it.ts.TripleDirection(linkVal, it.dir)
|
||||
if it.primaryIt.Contains(link) {
|
||||
it.result = it.ts.TripleDirection(link, it.dir)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
|
@ -188,20 +185,20 @@ func (it *HasA) NextPath() bool {
|
|||
return it.NextContains()
|
||||
}
|
||||
|
||||
// Get the next result from this iterator. This is simpler than Contains. We have a
|
||||
// Next advances the iterator. This is simpler than Contains. We have a
|
||||
// subiterator we can get a value from, and we can take that resultant triple,
|
||||
// pull our direction out of it, and return that.
|
||||
func (it *HasA) Next() (graph.Value, bool) {
|
||||
func (it *HasA) Next() bool {
|
||||
graph.NextLogIn(it)
|
||||
if it.resultIt != nil {
|
||||
it.resultIt.Close()
|
||||
}
|
||||
it.resultIt = &Null{}
|
||||
|
||||
tID, ok := graph.Next(it.primaryIt)
|
||||
if !ok {
|
||||
if !graph.Next(it.primaryIt) {
|
||||
return graph.NextLogOut(it, 0, false)
|
||||
}
|
||||
tID := it.primaryIt.Result()
|
||||
name := it.ts.Quad(tID).Get(it.dir)
|
||||
val := it.ts.ValueOf(name)
|
||||
it.result = val
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue