Add self loop example to Cycle Detection recipe.#921
Conversation
| addE('knows').from('c').to('d'). | ||
| addE('self').from('a').to('a').iterate() | ||
| g.V().as('a').emit().repeat(out().simplePath()).times(2). | ||
| where(out().as('a')).path() |
There was a problem hiding this comment.
I would tweak the traversal a little bit to make the output easier to grasp:
gremlin> g.V().as('a').
......1> emit().
......2> repeat(outE().inV().simplePath()).
......3> times(2).
......4> outE().inV().where(eq('a')).
......5> path().
......6> by(id).
......7> by(label)
==>[a,self,a]
==>[a,knows,b,knows,c,knows,a]
==>[b,knows,c,knows,a,knows,b]
==>[c,knows,a,knows,b,knows,c]
There was a problem hiding this comment.
@dkuppitz what is the added value of outE().inV() compared to out()?
There was a problem hiding this comment.
Really just readability. To me [a,self,a] looks better than just [a,a].
| by(id). | ||
| by(label) | ||
| ---- | ||
|
|
There was a problem hiding this comment.
Cool, much better. What I didn't notice in the first place, was that the paragraph below really only refers to the previous code snippets. I think you should move it above you changes.
There was a problem hiding this comment.
Hm the issue with the Traversal below is that it improves things further by formatting results more and doing unidirectional traversing on an unrestricted path length. Since the examples get more complicated as you progress through the document, if I put this self loop traversal under the more complicated one it feels like going backwards. Additionally the traversal below refers to the modern graph, whereas the first one and this self-loop one are similar, wdyt?
There was a problem hiding this comment.
I mean just put the paragraph that starts with
The above case assumed that ...
above your new block that starts with
Note that these ...
That would make more sense, no?
There was a problem hiding this comment.
The above case assumed that the need was to only detect cycles over a path length of three.
It also respected the directionality of the edges by only considering outgoing ones.
Also note that this traversal won't detect self-loops [....]
--
[self-loop code example]
--
What would need to change to detect cycles of arbitrary length over both incoming and
outgoing edges, in the modern graph?
--
[bi-directional code example]
--
[...]
Is that what you meant?
There was a problem hiding this comment.
Okay. well no strong opinion here I can change it for that
|
VOTE +1 |
5dfcdfc to
3afc576
Compare
Not sure if it is worth it but I figured out that self loops weren't detected in the given example.