use of org.neo4j.graphdb.traversal.BranchSelector in project neo4j by neo4j.
the class ExactDepthPathFinder method instantiateTraverser.
@Override
protected Traverser instantiateTraverser(Node start, Node end) {
GraphDatabaseService db = start.getGraphDatabase();
TraversalDescription side = db.traversalDescription().breadthFirst().uniqueness(uniqueness).order(new BranchOrderingPolicy() {
@Override
public BranchSelector create(TraversalBranch startSource, PathExpander expander) {
return new LiteDepthFirstSelector(startSource, startThreshold, expander);
}
});
return db.bidirectionalTraversalDescription().startSide(side.expand(expander).evaluator(toDepth(onDepth / 2))).endSide(side.expand(expander.reverse()).evaluator(toDepth(onDepth - onDepth / 2))).collisionEvaluator(atDepth(onDepth)).traverse(start, end);
}
use of org.neo4j.graphdb.traversal.BranchSelector in project neo4j-mobile-android by neo4j-contrib.
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.BranchSelector 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;
}
};
}
Aggregations