@Test public void testBidirectionalReachability() { assertThat(index.canReach(a, c), is(true)); assertThat(index.canReach(b, c), is(false)); }
public boolean canReach(Node startNode, Node endNode) { if (!indexExists()) { throw new IllegalStateException("Reachability index must be created first."); } try (Transaction tx = graphDb.beginTx()) { long[] outList = (long[]) startNode.getProperty(OUT_LIST_PROPERTY); long[] inList = (long[]) endNode.getProperty(IN_LIST_PROPERTY); int i = 0, j = 0; while (i < outList.length && j < inList.length) { if (outList[i] < inList[j]) { i++; } else if (inList[j] < outList[i]) { j++; } else { return true; } } return false; } }
ReachabilityIndex { public boolean canReach(Node startNode, Node endNode) { if (!indexExists()) { throw new IllegalStateException("Reachability index must be created first."); } try (Transaction tx = graphDb.beginTx()) { long[] outList = (long[]) startNode.getProperty(OUT_LIST_PROPERTY); long[] inList = (long[]) endNode.getProperty(IN_LIST_PROPERTY); int i = 0, j = 0; while (i < outList.length && j < inList.length) { if (outList[i] < inList[j]) { i++; } else if (inList[j] < outList[i]) { j++; } else { return true; } } return false; } } }
ReachabilityIndex { public boolean canReach(Node startNode, Node endNode) { if (!indexExists()) { throw new IllegalStateException("Reachability index must be created first."); } try (Transaction tx = graphDb.beginTx()) { long[] outList = (long[]) startNode.getProperty(OUT_LIST_PROPERTY); long[] inList = (long[]) endNode.getProperty(IN_LIST_PROPERTY); int i = 0, j = 0; while (i < outList.length && j < inList.length) { if (outList[i] < inList[j]) { i++; } else if (inList[j] < outList[i]) { j++; } else { return true; } } return false; } } @Inject  ReachabilityIndex(GraphDatabaseService graphDb); }
ReachabilityIndex { public boolean canReach(Node startNode, Node endNode) { if (!indexExists()) { throw new IllegalStateException("Reachability index must be created first."); } try (Transaction tx = graphDb.beginTx()) { long[] outList = (long[]) startNode.getProperty(OUT_LIST_PROPERTY); long[] inList = (long[]) endNode.getProperty(IN_LIST_PROPERTY); int i = 0, j = 0; while (i < outList.length && j < inList.length) { if (outList[i] < inList[j]) { i++; } else if (inList[j] < outList[i]) { j++; } else { return true; } } return false; } } @Inject  ReachabilityIndex(GraphDatabaseService graphDb); boolean indexExists(); void createIndex(); void setTransactionBatchSize(int size); void createIndex(Predicate<Node> nodePredicate); void dropIndex(); boolean canReach(Node startNode, Node endNode); Set<Pair<Node, Node>> getConnectedPairs(Set<Node> sources, Set<Node> targets); Set<Pair<Node, Node>> getDisconnectedPairs(Set<Node> sources, Set<Node> targets); boolean allReachable(Set<Node> sources, Set<Node> targets); }
ReachabilityIndex { public boolean canReach(Node startNode, Node endNode) { if (!indexExists()) { throw new IllegalStateException("Reachability index must be created first."); } try (Transaction tx = graphDb.beginTx()) { long[] outList = (long[]) startNode.getProperty(OUT_LIST_PROPERTY); long[] inList = (long[]) endNode.getProperty(IN_LIST_PROPERTY); int i = 0, j = 0; while (i < outList.length && j < inList.length) { if (outList[i] < inList[j]) { i++; } else if (inList[j] < outList[i]) { j++; } else { return true; } } return false; } } @Inject  ReachabilityIndex(GraphDatabaseService graphDb); boolean indexExists(); void createIndex(); void setTransactionBatchSize(int size); void createIndex(Predicate<Node> nodePredicate); void dropIndex(); boolean canReach(Node startNode, Node endNode); Set<Pair<Node, Node>> getConnectedPairs(Set<Node> sources, Set<Node> targets); Set<Pair<Node, Node>> getDisconnectedPairs(Set<Node> sources, Set<Node> targets); boolean allReachable(Set<Node> sources, Set<Node> targets);  }