Added comments for the not operator.
This commit is contained in:
parent
d3bc8c1736
commit
d9b67c8335
2 changed files with 14 additions and 5 deletions
|
|
@ -2,6 +2,8 @@ package iterator
|
||||||
|
|
||||||
import "github.com/google/cayley/graph"
|
import "github.com/google/cayley/graph"
|
||||||
|
|
||||||
|
// Not iterator acts like a set difference between the primary iterator
|
||||||
|
// and the forbidden iterator.
|
||||||
type Not struct {
|
type Not struct {
|
||||||
uid uint64
|
uid uint64
|
||||||
tags graph.Tagger
|
tags graph.Tagger
|
||||||
|
|
@ -33,6 +35,7 @@ func (it *Not) Tagger() *graph.Tagger {
|
||||||
return &it.tags
|
return &it.tags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO
|
||||||
func (it *Not) TagResults(dst map[string]graph.Value) {
|
func (it *Not) TagResults(dst map[string]graph.Value) {
|
||||||
for _, tag := range it.tags.Tags() {
|
for _, tag := range it.tags.Tags() {
|
||||||
dst[tag] = it.Result()
|
dst[tag] = it.Result()
|
||||||
|
|
@ -45,8 +48,6 @@ func (it *Not) TagResults(dst map[string]graph.Value) {
|
||||||
if it.primaryIt != nil {
|
if it.primaryIt != nil {
|
||||||
it.primaryIt.TagResults(dst)
|
it.primaryIt.TagResults(dst)
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *Not) Clone() graph.Iterator {
|
func (it *Not) Clone() graph.Iterator {
|
||||||
|
|
@ -73,7 +74,10 @@ func (it *Not) DebugString(indent int) string {
|
||||||
func (it *Not) Next() bool {
|
func (it *Not) Next() bool {
|
||||||
graph.NextLogIn(it)
|
graph.NextLogIn(it)
|
||||||
it.runstats.Next += 1
|
it.runstats.Next += 1
|
||||||
|
|
||||||
for graph.Next(it.primaryIt) {
|
for graph.Next(it.primaryIt) {
|
||||||
|
// Consider only the elements from the primary set which are not
|
||||||
|
// contained in the forbidden set.
|
||||||
if curr := it.primaryIt.Result(); !it.forbiddenIt.Contains(curr) {
|
if curr := it.primaryIt.Result(); !it.forbiddenIt.Contains(curr) {
|
||||||
it.result = curr
|
it.result = curr
|
||||||
it.runstats.ContainsNext += 1
|
it.runstats.ContainsNext += 1
|
||||||
|
|
@ -112,11 +116,13 @@ func (it *Not) Close() {
|
||||||
|
|
||||||
func (it *Not) Type() graph.Type { return graph.Not }
|
func (it *Not) Type() graph.Type { return graph.Not }
|
||||||
|
|
||||||
|
// TODO
|
||||||
func (it *Not) Optimize() (graph.Iterator, bool) {
|
func (it *Not) Optimize() (graph.Iterator, bool) {
|
||||||
//it.forbiddenIt = NewMaterialize(it.forbiddenIt)
|
//it.forbiddenIt = NewMaterialize(it.forbiddenIt)
|
||||||
return it, false
|
return it, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO
|
||||||
func (it *Not) Stats() graph.IteratorStats {
|
func (it *Not) Stats() graph.IteratorStats {
|
||||||
subitStats := it.primaryIt.Stats()
|
subitStats := it.primaryIt.Stats()
|
||||||
// TODO(barakmich): These should really come from the triplestore itself
|
// TODO(barakmich): These should really come from the triplestore itself
|
||||||
|
|
|
||||||
|
|
@ -300,21 +300,24 @@ func buildIteratorTreeHelper(obj *otto.Object, ts graph.TripleStore, base graph.
|
||||||
it = buildInOutIterator(obj, ts, subIt, true)
|
it = buildInOutIterator(obj, ts, subIt, true)
|
||||||
case "not":
|
case "not":
|
||||||
// Not is implemented as the difference between the primary iterator
|
// Not is implemented as the difference between the primary iterator
|
||||||
// and the iterator chain of (primaryIt, follow, followR).
|
// and the iterator chain composed of (primaryIt->Follow->FollowR).
|
||||||
// Build the follow iterator
|
|
||||||
|
// Arguments for follow iterator
|
||||||
arg, _ := obj.Get("_gremlin_values")
|
arg, _ := obj.Get("_gremlin_values")
|
||||||
firstArg, _ := arg.Object().Get("0")
|
firstArg, _ := arg.Object().Get("0")
|
||||||
if isVertexChain(firstArg.Object()) {
|
if isVertexChain(firstArg.Object()) {
|
||||||
return iterator.NewNull()
|
return iterator.NewNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the followR iterator
|
// Arguments for followR iterator
|
||||||
revArg, _ := obj.Get("_gremlin_followr")
|
revArg, _ := obj.Get("_gremlin_followr")
|
||||||
if isVertexChain(revArg.Object()) {
|
if isVertexChain(revArg.Object()) {
|
||||||
return iterator.NewNull()
|
return iterator.NewNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Build the primaryIt->Follow iterator
|
||||||
followIt := buildIteratorTreeHelper(firstArg.Object(), ts, subIt)
|
followIt := buildIteratorTreeHelper(firstArg.Object(), ts, subIt)
|
||||||
|
// Build the primaryIt->Follow->FollowR iterator
|
||||||
forbiddenIt := buildIteratorTreeHelper(revArg.Object(), ts, followIt)
|
forbiddenIt := buildIteratorTreeHelper(revArg.Object(), ts, followIt)
|
||||||
|
|
||||||
it = iterator.NewNot(subIt, forbiddenIt)
|
it = iterator.NewNot(subIt, forbiddenIt)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue