I need to all blue nodes or the node that the id match between different nodes in the tree, based on the maximum levels. I have this code
GraphTraversal<Vertex, Map<String, List>> values = graphDbConnection.getGraphTraversalSource().V()
.hasLabel('uuid').has('uuid', uuid).emit()
.repeat(in().choose(values('color').is('blue'), identity(), in()))
.times(levels)
.map(or(has('color', 'blue'),
has('uuid', uuid)))
.valueMap('uuid', 'color');
if between one blue node and another blue node are more than 3 or 4 incorrect nodes, the algorithm will left out the last possible one.
For example, with that code, if I ask all blues four levels above from uuid=1
including one, it will returns 1,2,3 and will not returns 4 because between 3 and 4 are 3 black.
but for this example it will returns 1,2,3,4 because between 3 and 4 are just one or two incorrect nodes
Note: One detail here, if I remove times(levels)
call, all blue colors will be shown no matter how many wrong colors are in between but without an stop condition, which is the key.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…