private void buildPropagationPath() { byte[] state = new byte[types.length]; int[] path = new int[types.length]; int pathSize = 0; IntStack stack = new IntStack(); for (int i = 0; i < graph.size(); ++i) { if (graph.incomingEdgesCount(i) == 0 && types[i] != null) { stack.push(i); } } while (!stack.isEmpty()) { int node = stack.pop(); if (state[node] == FRESH) { state[node] = VISITING; stack.push(node); for (int successor : graph.outgoingEdges(node)) { if (state[successor] == FRESH) { stack.push(successor); } } } else if (state[node] == VISITING) { path[pathSize++] = node; state[node] = VISITED; } } propagationPath = Arrays.copyOf(path, pathSize); }
while (!procStack.isEmpty()) { int state = procStack.pop(); int v = procStack.pop();
GraphBuilder graphBuilder = new GraphBuilder(types.length); while (!stack.isEmpty()) { int entry = stack.pop();
/** * check if the popStack is empty * * @return */ public boolean isEmpty() { return popStack().isEmpty(); }
/** * check if the popStack is empty * * @return */ public boolean isEmpty() { return popStack().isEmpty(); }
/** * Linearization of states. */ private int[] linearize(final FSA fsa) { int[] linearized = new int[0]; int last = 0; BitSet visited = new BitSet(); IntStack nodes = new IntStack(); nodes.push(fsa.getRootNode()); while (!nodes.isEmpty()) { final int node = nodes.pop(); if (visited.get(node)) { continue; } if (last >= linearized.length) { linearized = Arrays.copyOf(linearized, linearized.length + 100000); } visited.set(node); linearized[last++] = node; for (int arc = fsa.getFirstArc(node); arc != 0; arc = fsa.getNextArc(arc)) { if (!fsa.isArcTerminal(arc)) { int target = fsa.getEndNode(arc); if (!visited.get(target)) nodes.push(target); } } } return Arrays.copyOf(linearized, last); }
/** * Linearization of states. */ private int[] linearize(final FSA fsa) { int[] linearized = new int[0]; int last = 0; BitSet visited = new BitSet(); IntStack nodes = new IntStack(); nodes.push(fsa.getRootNode()); while (!nodes.isEmpty()) { final int node = nodes.pop(); if (visited.get(node)) { continue; } if (last >= linearized.length) { linearized = Arrays.copyOf(linearized, linearized.length + 100000); } visited.set(node); linearized[last++] = node; for (int arc = fsa.getFirstArc(node); arc != 0; arc = fsa.getNextArc(arc)) { if (!fsa.isArcTerminal(arc)) { int target = fsa.getEndNode(arc); if (!visited.get(target)) nodes.push(target); } } } return Arrays.copyOf(linearized, last); }
/** * Compute in-link count for each state. */ private IntIntHashMap computeInlinkCount(final FSA fsa) { IntIntHashMap inlinkCount = new IntIntHashMap(); BitSet visited = new BitSet(); IntStack nodes = new IntStack(); nodes.push(fsa.getRootNode()); while (!nodes.isEmpty()) { final int node = nodes.pop(); if (visited.get(node)) continue; visited.set(node); for (int arc = fsa.getFirstArc(node); arc != 0; arc = fsa.getNextArc(arc)) { if (!fsa.isArcTerminal(arc)) { final int target = fsa.getEndNode(arc); inlinkCount.putOrAdd(target, 1, 1); if (!visited.get(target)) nodes.push(target); } } } return inlinkCount; }
/** * Compute in-link count for each state. */ private IntIntHashMap computeInlinkCount(final FSA fsa) { IntIntHashMap inlinkCount = new IntIntHashMap(); BitSet visited = new BitSet(); IntStack nodes = new IntStack(); nodes.push(fsa.getRootNode()); while (!nodes.isEmpty()) { final int node = nodes.pop(); if (visited.get(node)) continue; visited.set(node); for (int arc = fsa.getFirstArc(node); arc != 0; arc = fsa.getNextArc(arc)) { if (!fsa.isArcTerminal(arc)) { final int target = fsa.getEndNode(arc); inlinkCount.putOrAdd(target, 1, 1); if (!visited.get(target)) nodes.push(target); } } } return inlinkCount; }
@Override public void run() { final IntStack nodes = new IntStack(); final TerminationFlag flag = getTerminationFlag(); final int[] head = new int[1]; while ((head[0] = queue.getAndIncrement()) < nodeCount) { graph.forEachRelationship(head[0], direction, (s, t, r) -> { if (t > s) { nodes.push(t); } return flag.running(); }); while (!nodes.isEmpty()) { final int node = nodes.pop(); graph.forEachRelationship(node, direction, (s, t, r) -> { if (t > s && graph.exists(t, head[0], direction)) { triangles.incrementAndGet(head[0]); triangles.incrementAndGet(s); triangles.incrementAndGet(t); triangleCount.increment(); } return flag.running(); }); } getProgressLogger().logProgress(visitedNodes.incrementAndGet(), nodeCount); } } }
@Override public void run() { final IntStack nodes = new IntStack(); final TerminationFlag flag = getTerminationFlag(); final int[] head = new int[1]; while ((head[0] = queue.getAndIncrement()) < nodeCount) { graph.forEachRelationship(head[0], direction, (s, t, r) -> { if (t > s) { nodes.push(t); } return flag.running(); }); while (!nodes.isEmpty()) { final int node = nodes.pop(); graph.forEachRelationship(node, direction, (s, t, r) -> { if (t > s && graph.exists(t, head[0], direction)) { triangles.incrementAndGet(head[0]); triangles.incrementAndGet(s); triangles.incrementAndGet(t); triangleCount.increment(); } return flag.running(); }); } getProgressLogger().logProgress(visitedNodes.incrementAndGet(), nodeCount); } } }
@Override void evaluateNode(final int nodeId) { IntStack nodes = this.nodes; graph.forEachRelationship(nodeId, D, (s, t, r) -> { if (t > s) { nodes.add(t); } return running(); }); while (!nodes.isEmpty()) { final int node = nodes.pop(); graph.forEachRelationship(node, D, (s, t, r) -> { if (t > s && graph.exists(t, nodeId, D)) { emit(nodeId, s, t); } return running(); }); } } }
@Override void evaluateNode(final int nodeId) { IntStack nodes = this.nodes; graph.forEachRelationship(nodeId, D, (s, t, r) -> { if (t > s) { nodes.add(t); } return running(); }); while (!nodes.isEmpty()) { final int node = nodes.pop(); graph.forEachRelationship(node, D, (s, t, r) -> { if (t > s && graph.exists(t, nodeId, D)) { emit(nodeId, s, t); } return running(); }); } } }
private boolean compute(int nodeId) { if (!running()) { return false; } if (index[nodeId] != -1) { return true; } push(Action.VISIT, nodeId); while (!todo.isEmpty()) { final int action = todo.pop(); final int node = todo.pop(); if (action == Action.VISIT.code) { visit(node); } else if (action == Action.VISITEDGE.code) { visitEdge(node); } else { postVisit(node); } } getProgressLogger().logProgress((double) nodeId / (nodeCount - 1)); return true; }
}); while (!stack.isEmpty() && running()) { final int node = stack.pop(); if (null == paths[node]) {
private boolean compute(int nodeId) { if (!running()) { return false; } if (index[nodeId] != -1) { return true; } push(Action.VISIT, nodeId); while (!todo.isEmpty()) { final int action = todo.pop(); final int node = todo.pop(); if (action == Action.VISIT.code) { visit(node); } else if (action == Action.VISITEDGE.code) { visitEdge(node); } else { postVisit(node); } } getProgressLogger().logProgress((double) nodeId / (nodeCount - 1)); return true; }
while (!stack.isEmpty()) { int node = stack.pop(); paths.forEach(node, v -> {
private long execute(final int start, final int end) { final long triangles[] = {0L}; final IntStack nodes = new IntStack(); final TerminationFlag flag = getTerminationFlag(); final int[] head = {-1}; for (head[0] = start; head[0] < end; head[0]++) { graph.forEachRelationship(head[0], D, (s, t, r) -> { if (t > s) { nodes.push(t); } return flag.running(); }); while (!nodes.isEmpty()) { final int node = nodes.pop(); graph.forEachRelationship(node, D, (s, t, r) -> { if (t > s && graph.exists(t, head[0], D)) { exportTriangle(head[0], s, t); triangles[0]++; } return flag.running(); }); } nodeVisited(); } return triangles[0]; } }
while (!stack.isEmpty()) { int node = stack.pop(); paths.forEach(node, v -> {
private long execute(final int start, final int end) { final long triangles[] = {0L}; final IntStack nodes = new IntStack(); final TerminationFlag flag = getTerminationFlag(); final int[] head = {-1}; for (head[0] = start; head[0] < end; head[0]++) { graph.forEachRelationship(head[0], D, (s, t, r) -> { if (t > s) { nodes.push(t); } return flag.running(); }); while (!nodes.isEmpty()) { final int node = nodes.pop(); graph.forEachRelationship(node, D, (s, t, r) -> { if (t > s && graph.exists(t, head[0], D)) { exportTriangle(head[0], s, t); triangles[0]++; } return flag.running(); }); } nodeVisited(); } return triangles[0]; } }