Converted the Not operator to a complement operator in terms of functionality.

This commit is contained in:
Matei Chiperi 2014-08-27 13:42:56 -07:00
parent a0318aa7b2
commit 5d4e22498d
3 changed files with 35 additions and 48 deletions

View file

@ -299,28 +299,14 @@ func buildIteratorTreeHelper(obj *otto.Object, ts graph.TripleStore, base graph.
case "in":
it = buildInOutIterator(obj, ts, subIt, true)
case "not":
// Not is implemented as the difference between the primary iterator
// and the iterator chain composed of (primaryIt->Follow->FollowR).
// arg, _ := obj.Get("_gremlin_values")
// firstArg, _ := arg.Object().Get("0")
// if !isVertexChain(firstArg.Object()) {
// return iterator.NewNull()
// }
// forbiddenIt := buildIteratorTree(firstArg.Object(), ts)
// Arguments for follow iterator
arg, _ := obj.Get("_gremlin_values")
firstArg, _ := arg.Object().Get("0")
if isVertexChain(firstArg.Object()) {
return iterator.NewNull()
}
// 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)
it = iterator.NewNot(ts, subIt)
case "loop":
arg, _ := obj.Get("_gremlin_values")
firstArg, _ := arg.Object().Get("0")

View file

@ -38,8 +38,8 @@ func (wk *worker) embedTraversals(env *otto.Otto, obj *otto.Object) {
obj.Set("Has", wk.gremlinFunc("has", obj, env))
obj.Set("Save", wk.gremlinFunc("save", obj, env))
obj.Set("SaveR", wk.gremlinFunc("saver", obj, env))
obj.Set("Loop", gremlinFunc("loop", obj, env, ses))
obj.Set("Not", gremlinFollowR("not", obj, env, ses))
obj.Set("Loop", wk.gremlinFunc("loop", obj, env))
obj.Set("Not", wk.gremlinFunc("not", obj, env))
}
func (wk *worker) gremlinFunc(kind string, prev *otto.Object, env *otto.Otto) func(otto.FunctionCall) otto.Value {