while (nodeEdges.hasNext()) { ObjectId otherNode = nodeEdges.next(); edges.add(new GraphEdge(new RocksGraphNode(getNodeInternal(otherNode, true)), this)); while (nodeEdges.hasNext()) { ObjectId otherNode = nodeEdges.next(); edges.add(new GraphEdge(this, new RocksGraphNode(getNodeInternal(otherNode, true))));
while (edges.hasNext()) { GraphEdge parent = edges.next(); GraphNode parentNode = parent.getToNode(); if (parentNode.getIdentifier() != ancestor.getIdentifier()) { if (leftSet.contains(parentNode) || rightSet.contains(parentNode)) {
while (edges.hasNext()) { GraphEdge parent = edges.next(); GraphNode parentNode = parent.getToNode(); if (parentNode.getIdentifier() != ancestor.getIdentifier()) { if (leftSet.contains(parentNode) || rightSet.contains(parentNode)) {
while (nodeEdges.hasNext()) { ObjectId otherNode = nodeEdges.next(); edges.add(new GraphEdge(new RocksGraphNode(getNodeInternal(otherNode, true)), this)); while (nodeEdges.hasNext()) { ObjectId otherNode = nodeEdges.next(); edges.add(new GraphEdge(this, new RocksGraphNode(getNodeInternal(otherNode, true))));
while (nodeEdges.hasNext()) { ObjectId otherNode = nodeEdges.next(); edges.add(new GraphEdge(new JEGraphNode(getNodeInternal(otherNode, true)), this)); while (nodeEdges.hasNext()) { ObjectId otherNode = nodeEdges.next(); edges.add(new GraphEdge(this, new JEGraphNode(getNodeInternal(otherNode, true))));
while (edges.hasNext()) { GraphEdge relationship = edges.next(); GraphNode parentNode = relationship.getToNode(); if (theirSet.contains(parentNode)) { if (!processed.contains(parentNode)) {
while (edges.hasNext()) { GraphEdge relationship = edges.next(); GraphNode parentNode = relationship.getToNode(); if (theirSet.contains(parentNode)) { if (!processed.contains(parentNode)) {
/** * Process a commit to see if it has already been seen. If it has, prevent unnecessary work from * continuing on the other traversal queue. If it hasn't, add it's parents to the traversal * queue. * * @param commit commit to process * @param myQueue my traversal queue * @param mySet my visited nodes * @param theirQueue other traversal queue * @param theirSet other traversal's visited nodes * @return */ private boolean processCommit(GraphNode commit, Queue<GraphNode> myQueue, Set<GraphNode> mySet, Queue<GraphNode> theirQueue, Set<GraphNode> theirSet) { if (mySet.add(commit)) { if (theirSet.contains(commit)) { stopAncestryPath(commit, theirQueue, theirSet); return true; } Iterator<GraphEdge> edges = commit.getEdges(Direction.OUT); while (edges.hasNext()) { GraphEdge parentEdge = edges.next(); GraphNode parent = parentEdge.getToNode(); myQueue.add(parent); } } return false; }
/** * Process a commit to see if it has already been seen. If it has, prevent unnecessary work from * continuing on the other traversal queue. If it hasn't, add it's parents to the traversal * queue. * * @param commit commit to process * @param myQueue my traversal queue * @param mySet my visited nodes * @param theirQueue other traversal queue * @param theirSet other traversal's visited nodes * @return */ private boolean processCommit(GraphNode commit, Queue<GraphNode> myQueue, Set<GraphNode> mySet, Queue<GraphNode> theirQueue, Set<GraphNode> theirSet) { if (mySet.add(commit)) { if (theirSet.contains(commit)) { stopAncestryPath(commit, theirQueue, theirSet); return true; } Iterator<GraphEdge> edges = commit.getEdges(Direction.OUT); while (edges.hasNext()) { GraphEdge parentEdge = edges.next(); GraphNode parent = parentEdge.getToNode(); myQueue.add(parent); } } return false; }
@Test public void testEdges() throws IOException { ObjectId rootId = RevObjectTestSupport.hashString("root"); database.put(rootId, ImmutableList.of()); ObjectId commit1 = RevObjectTestSupport.hashString("c1"); database.put(commit1, ImmutableList.of(rootId)); ObjectId commit2 = RevObjectTestSupport.hashString("c2"); database.put(commit2, ImmutableList.of(commit1, rootId)); GraphNode node; List<GraphEdge> edges; node = database.getNode(commit2); assertNotNull(node); edges = ImmutableList.copyOf(node.getEdges(Direction.IN)); assertTrue(edges.isEmpty()); edges = ImmutableList.copyOf(node.getEdges(Direction.OUT)); assertEquals(2, edges.size()); assertEquals(commit1, edges.get(0).getToNode().getIdentifier()); assertEquals(rootId, edges.get(1).getToNode().getIdentifier()); node = database.getNode(commit1); assertNotNull(node); edges = ImmutableList.copyOf(node.getEdges(Direction.IN)); assertEquals(1, edges.size()); edges = ImmutableList.copyOf(node.getEdges(Direction.OUT)); assertEquals(1, edges.size()); }
@Override public void run() { GraphNode commit2Node = database.getNode(commit2); GraphNode commit1Node = database.getNode(commit1); GraphNode rootNode = database.getNode(rootId); List<GraphEdge> edges; assertNotNull(commit2Node); assertNotNull(commit1Node); assertNotNull(rootNode); edges = ImmutableList.copyOf(commit2Node.getEdges(Direction.IN)); assertTrue(edges.isEmpty()); edges = ImmutableList.copyOf(commit2Node.getEdges(Direction.OUT)); assertEquals(2, edges.size()); assertEquals(commit1, edges.get(0).getToNode().getIdentifier()); assertEquals(rootId, edges.get(1).getToNode().getIdentifier()); edges = ImmutableList.copyOf(commit1Node.getEdges(Direction.IN)); assertEquals(1, edges.size()); edges = ImmutableList.copyOf(commit1Node.getEdges(Direction.OUT)); assertEquals(1, edges.size()); edges = ImmutableList.copyOf(rootNode.getEdges(Direction.IN)); assertEquals(2, edges.size()); edges = ImmutableList.copyOf(rootNode.getEdges(Direction.OUT)); assertTrue(edges.isEmpty()); } });
@Test public void testEdges() throws IOException { ObjectId rootId = RevObjectTestSupport.hashString("root"); database.put(rootId, ImmutableList.of()); ObjectId commit1 = RevObjectTestSupport.hashString("c1"); database.put(commit1, ImmutableList.of(rootId)); ObjectId commit2 = RevObjectTestSupport.hashString("c2"); database.put(commit2, ImmutableList.of(commit1, rootId)); GraphNode node; List<GraphEdge> edges; node = database.getNode(commit2); assertNotNull(node); edges = ImmutableList.copyOf(node.getEdges(Direction.IN)); assertTrue(edges.isEmpty()); edges = ImmutableList.copyOf(node.getEdges(Direction.OUT)); assertEquals(2, edges.size()); assertEquals(commit1, edges.get(0).getToNode().getIdentifier()); assertEquals(rootId, edges.get(1).getToNode().getIdentifier()); node = database.getNode(commit1); assertNotNull(node); edges = ImmutableList.copyOf(node.getEdges(Direction.IN)); assertEquals(1, edges.size()); edges = ImmutableList.copyOf(node.getEdges(Direction.OUT)); assertEquals(1, edges.size()); }
@Override public void run() { GraphNode commit2Node = database.getNode(commit2); GraphNode commit1Node = database.getNode(commit1); GraphNode rootNode = database.getNode(rootId); List<GraphEdge> edges; assertNotNull(commit2Node); assertNotNull(commit1Node); assertNotNull(rootNode); edges = ImmutableList.copyOf(commit2Node.getEdges(Direction.IN)); assertTrue(edges.isEmpty()); edges = ImmutableList.copyOf(commit2Node.getEdges(Direction.OUT)); assertEquals(2, edges.size()); assertEquals(commit1, edges.get(0).getToNode().getIdentifier()); assertEquals(rootId, edges.get(1).getToNode().getIdentifier()); edges = ImmutableList.copyOf(commit1Node.getEdges(Direction.IN)); assertEquals(1, edges.size()); edges = ImmutableList.copyOf(commit1Node.getEdges(Direction.OUT)); assertEquals(1, edges.size()); edges = ImmutableList.copyOf(rootNode.getEdges(Direction.IN)); assertEquals(2, edges.size()); edges = ImmutableList.copyOf(rootNode.getEdges(Direction.OUT)); assertTrue(edges.isEmpty()); } });
/** * Recursive brute force function to exhaustively search for all paths between the start and end * node. This should be optimized to avoid unnecessary work in the future. */ private boolean isSparsePath(GraphNode node, ObjectId end, boolean sparse) { if (node.getIdentifier().equals(end)) { return sparse; } Iterator<GraphEdge> outgoing = node.getEdges(Direction.OUT); if (outgoing.hasNext()) { boolean node_sparse = node.isSparse(); boolean combined_sparse = false; while (outgoing.hasNext()) { GraphEdge parent = outgoing.next(); GraphNode parentNode = parent.getToNode(); combined_sparse = combined_sparse || isSparsePath(parentNode, end, sparse || node_sparse); } return combined_sparse; } return false; } }
/** * Recursive brute force function to exhaustively search for all paths between the start and end * node. This should be optimized to avoid unnecessary work in the future. */ private boolean isSparsePath(GraphNode node, ObjectId end, boolean sparse) { if (node.getIdentifier().equals(end)) { return sparse; } Iterator<GraphEdge> outgoing = node.getEdges(Direction.OUT); if (outgoing.hasNext()) { boolean node_sparse = node.isSparse(); boolean combined_sparse = false; while (outgoing.hasNext()) { GraphEdge parent = outgoing.next(); GraphNode parentNode = parent.getToNode(); combined_sparse = combined_sparse || isSparsePath(parentNode, end, sparse || node_sparse); } return combined_sparse; } return false; } }
@Override public Iterator<GraphEdge> getEdges(final Direction direction) { Iterator<Edge> nodeEdges; switch (direction) { case OUT: nodeEdges = node.out.iterator(); break; case IN: nodeEdges = node.in.iterator(); break; default: nodeEdges = Iterators.concat(node.in.iterator(), node.out.iterator()); } List<GraphEdge> edges = new LinkedList<GraphEdge>(); while (nodeEdges.hasNext()) { Edge nodeEdge = nodeEdges.next(); Node src = nodeEdge.src; Node dst = nodeEdge.dst; edges.add(new GraphEdge(new HeapGraphNode(src), new HeapGraphNode(dst))); } return edges.iterator(); }