From d9b67c8335ffe68c25cae0f5af603f62f9317ab5 Mon Sep 17 00:00:00 2001 From: Matei Chiperi Date: Tue, 26 Aug 2014 11:59:14 -0700 Subject: [PATCH] Added comments for the not operator. --- graph/iterator/not_iterator.go | 10 ++++++++-- query/gremlin/build_iterator.go | 9 ++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/graph/iterator/not_iterator.go b/graph/iterator/not_iterator.go index 8b2d0c9..2c6182f 100644 --- a/graph/iterator/not_iterator.go +++ b/graph/iterator/not_iterator.go @@ -2,6 +2,8 @@ package iterator import "github.com/google/cayley/graph" +// Not iterator acts like a set difference between the primary iterator +// and the forbidden iterator. type Not struct { uid uint64 tags graph.Tagger @@ -33,6 +35,7 @@ func (it *Not) Tagger() *graph.Tagger { return &it.tags } +// TODO func (it *Not) TagResults(dst map[string]graph.Value) { for _, tag := range it.tags.Tags() { dst[tag] = it.Result() @@ -45,8 +48,6 @@ func (it *Not) TagResults(dst map[string]graph.Value) { if it.primaryIt != nil { it.primaryIt.TagResults(dst) } - - // todo } func (it *Not) Clone() graph.Iterator { @@ -73,7 +74,10 @@ func (it *Not) DebugString(indent int) string { func (it *Not) Next() bool { graph.NextLogIn(it) it.runstats.Next += 1 + 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) { it.result = curr it.runstats.ContainsNext += 1 @@ -112,11 +116,13 @@ func (it *Not) Close() { func (it *Not) Type() graph.Type { return graph.Not } +// TODO func (it *Not) Optimize() (graph.Iterator, bool) { //it.forbiddenIt = NewMaterialize(it.forbiddenIt) return it, false } +// TODO func (it *Not) Stats() graph.IteratorStats { subitStats := it.primaryIt.Stats() // TODO(barakmich): These should really come from the triplestore itself diff --git a/query/gremlin/build_iterator.go b/query/gremlin/build_iterator.go index 85ad3a5..f7e69c7 100644 --- a/query/gremlin/build_iterator.go +++ b/query/gremlin/build_iterator.go @@ -300,21 +300,24 @@ func buildIteratorTreeHelper(obj *otto.Object, ts graph.TripleStore, base graph. it = buildInOutIterator(obj, ts, subIt, true) case "not": // Not is implemented as the difference between the primary iterator - // and the iterator chain of (primaryIt, follow, followR). - // Build the follow iterator + // and the iterator chain composed of (primaryIt->Follow->FollowR). + + // Arguments for follow iterator arg, _ := obj.Get("_gremlin_values") firstArg, _ := arg.Object().Get("0") if isVertexChain(firstArg.Object()) { return iterator.NewNull() } - // Build the followR iterator + // Arguments for followR iterator revArg, _ := obj.Get("_gremlin_followr") if isVertexChain(revArg.Object()) { return iterator.NewNull() } + // Build the primaryIt->Follow iterator followIt := buildIteratorTreeHelper(firstArg.Object(), ts, subIt) + // Build the primaryIt->Follow->FollowR iterator forbiddenIt := buildIteratorTreeHelper(revArg.Object(), ts, followIt) it = iterator.NewNot(subIt, forbiddenIt)