use of org.neo4j.graphdb.traversal.TraversalBranch in project graphdb by neo4j-attic.
the class ExactDepthPathFinder method paths.
private Iterator<Path> paths(final Node start, final Node end) {
TraversalDescription base = Traversal.description().uniqueness(Uniqueness.RELATIONSHIP_PATH).order(new BranchOrderingPolicy() {
public BranchSelector create(TraversalBranch startSource) {
return new LiteDepthFirstSelector(startSource, startThreshold);
}
});
final int firstHalf = onDepth / 2;
Traverser startTraverser = base.prune(Traversal.pruneAfterDepth(firstHalf)).expand(expander).filter(new Predicate<Path>() {
public boolean accept(Path item) {
return item.length() == firstHalf;
}
}).traverse(start);
final int secondHalf = onDepth - firstHalf;
Traverser endTraverser = base.prune(Traversal.pruneAfterDepth(secondHalf)).expand(expander.reversed()).filter(new Predicate<Path>() {
public boolean accept(Path item) {
return item.length() == secondHalf;
}
}).traverse(end);
final Iterator<Path> startIterator = startTraverser.iterator();
final Iterator<Path> endIterator = endTraverser.iterator();
final Map<Node, Visit> visits = new HashMap<Node, Visit>();
return new PrefetchingIterator<Path>() {
@Override
protected Path fetchNextOrNull() {
Path[] found = null;
while (found == null && (startIterator.hasNext() || endIterator.hasNext())) {
found = goOneStep(start, startIterator, visits);
if (found == null) {
found = goOneStep(end, endIterator, visits);
}
}
return found != null ? toPath(found, start) : null;
}
};
}
use of org.neo4j.graphdb.traversal.TraversalBranch in project graphdb by neo4j-attic.
the class PostorderBreadthFirstSelector method gatherOneLevel.
private List<TraversalBranch> gatherOneLevel(List<TraversalBranch> queue) {
List<TraversalBranch> level = new LinkedList<TraversalBranch>();
Integer depth = null;
for (TraversalBranch source : queue) {
if (depth == null) {
depth = source.depth();
} else if (source.depth() != depth) {
break;
}
while (true) {
TraversalBranch next = source.next();
if (next == null) {
break;
}
level.add(next);
}
}
return level;
}
use of org.neo4j.graphdb.traversal.TraversalBranch in project graphdb by neo4j-attic.
the class PreorderBreadthFirstSelector method next.
public TraversalBranch next() {
TraversalBranch result = null;
while (result == null) {
TraversalBranch next = current.next();
if (next != null) {
queue.add(next);
result = next;
} else {
current = queue.poll();
if (current == null) {
return null;
}
}
}
return result;
}
use of org.neo4j.graphdb.traversal.TraversalBranch in project graphdb by neo4j-attic.
the class PostorderDepthFirstSelector method next.
public TraversalBranch next() {
TraversalBranch result = null;
while (result == null) {
if (current == null) {
return null;
}
TraversalBranch next = current.next();
if (next != null) {
current = next;
} else {
result = current;
current = current.parent();
}
}
return result;
}
use of org.neo4j.graphdb.traversal.TraversalBranch in project graphdb by neo4j-attic.
the class TraversalBranchImpl method next.
public TraversalBranch next() {
while (relationships.hasNext()) {
Relationship relationship = relationships.next();
if (relationship.equals(howIGotHere)) {
continue;
}
expandedCount++;
Node node = relationship.getOtherNode(source);
TraversalBranch next = new TraversalBranchImpl(traverser, this, depth + 1, node, traverser.description.expander, relationship);
if (traverser.okToProceed(next)) {
next.initialize();
return next;
}
}
return null;
}
Aggregations