private void propagatePhiUsageInformation() { IntDeque worklist = new IntArrayDeque(); for (int receiverIndex : phisByReceiver.keys().toArray()) { if (usedPhis.get(receiverIndex)) { worklist.addLast(receiverIndex); } } IntSet visited = new IntHashSet(); while (!worklist.isEmpty()) { int varIndex = worklist.removeFirst(); if (!visited.add(varIndex)) { continue; } usedPhis.set(varIndex); Phi phi = phisByReceiver.get(varIndex); if (phi != null) { for (Incoming incoming : phi.getIncomings()) { if (!visited.contains(incoming.getValue().getIndex())) { worklist.addLast(incoming.getValue().getIndex()); } } } } }
/** * beginning with startNode add all following nodes to LIFO queue. If node has been already * explored before, skip reexploration. */ @Override public void start(EdgeExplorer explorer, int startNode) { IntArrayDeque stack = new IntArrayDeque(); GHBitSet explored = createBitSet(); stack.addLast(startNode); int current; while (stack.size() > 0) { current = stack.removeLast(); if (!explored.contains(current) && goFurther(current)) { EdgeIterator iter = explorer.setBaseNode(current); while (iter.next()) { int connectedId = iter.getAdjNode(); if (checkAdjacent(iter)) { stack.addLast(connectedId); } } explored.add(current); } } }
/** * Vararg-signature method for adding elements at the front of this deque. * * <p><b>This method is handy, but costly if used in tight loops (anonymous * array passing)</b></p> * * @param elements The elements to add. */ /* */ public final void addFirst(int... elements) { ensureBufferSpace(elements.length); for (int k : elements) { addFirst(k); } }
nodeLowLink[start] = index; index++; nodeStack.addLast(start); onStack.add(start); IntArrayList component = new IntArrayList(); int node; while ((node = nodeStack.removeLast()) != start) { component.add(node); onStack.remove(node);
/** * Create a new deque by pushing a variable number of arguments to the end of it. */ /* */ public static IntArrayDeque from(int... elements) { final IntArrayDeque coll = new IntArrayDeque(elements.length); coll.addLast(elements); return coll; } }
final IntArrayDeque nodeQueue = new IntArrayDeque(); nodeQueue.clear(); nodeQueue.addLast(i); nodesChecked[i] = true; IntArrayList clusterGroup = new IntArrayList(); while (!nodeQueue.isEmpty()) int node = nodeQueue.removeFirst(); nodeQueue.addLast(j); nodesChecked[j] = true;
private void iterateBFS(int startNode, RelationshipConsumer consumer) { IntArrayDeque queue = new IntArrayDeque(); BitSet seen = new BitSet(capacity); queue.addFirst(startNode); while (!queue.isEmpty()) { int node = queue.removeFirst(); int child = children[node]; if (child != INVALID_NODE) { do { if (!seen.getAndSet(child)) { queue.addLast(child); } if (!consumer.accept( node, child, RELATION_ID_NOT_SUPPORTED)) { return; } } while ((child = siblings[child]) != INVALID_NODE); } } }
sigma[startNodeId] = 1; distance[startNodeId] = 0; queue.addLast(startNodeId); while (!queue.isEmpty()) { int node = queue.removeFirst(); stack.push(node); graph.forEachRelationship(node, direction, (source, target, relationId) -> { if (distance[target] < 0) { queue.addLast(target); distance[target] = distance[node] + 1;
/** * Vararg-signature method for adding elements at the end of this deque. * * <p> * <b>This method is handy, but costly if used in tight loops (anonymous array * passing)</b> * </p> * * @param elements The elements to iterate over. */ /* */ public final void addLast(int... elements) { ensureBufferSpace(1); for (int k : elements) { addLast(k); } }
/** * {@inheritDoc} */ @Override public int getFirst() { assert size() > 0 : "The deque is empty."; return buffer[head]; }
/** * Inserts all elements from the given iterable to the end of this deque. * * @param iterable The iterable to iterate over. * * @return Returns the number of elements actually added as a result of this * call. */ public int addLast(Iterable<? extends IntCursor> iterable) { int size = 0; for (IntCursor cursor : iterable) { addLast(cursor.value); size++; } return size; }
/** * Ensure this container can hold at least the given number of elements * without resizing its buffers. * * @param expectedElements * The total number of elements, inclusive. */ @Override public void ensureCapacity(int expectedElements) { ensureBufferSpace(expectedElements - size()); }
/** * Compare order-aligned elements against another {@link IntDeque}. */ protected boolean equalElements(IntArrayDeque other) { int max = size(); if (other.size() != max) { return false; } Iterator<IntCursor> i1 = this.iterator(); Iterator<? extends IntCursor> i2 = other.iterator(); while (i1.hasNext() && i2.hasNext()) { if (!((i2.next().value) == ( i1.next().value))) { return false; } } return !i1.hasNext() && !i2.hasNext(); }
/** * Inserts all elements from the given iterable to the front of this deque. * * @param iterable The iterable to iterate over. * * @return Returns the number of elements actually added as a result of this * call. */ public int addFirst(Iterable<? extends IntCursor> iterable) { int size = 0; for (IntCursor cursor : iterable) { addFirst(cursor.value); size++; } return size; }
private DequeMapping(IdMapping mapping, IntArrayDeque data) { this.mapping = mapping; if (data.head <= data.tail) { this.data = data.buffer; this.offset = data.head; this.length = data.tail - data.head; } else { this.data = data.toArray(); this.offset = 0; this.length = this.data.length; } }
private boolean compute(int startNode) { clearPaths(); stack.clear(); queue.clear(); depth.clear(); Arrays.fill(sigma, 0); Arrays.fill(delta, 0); sigma[startNode] = 1; distance[startNode] = 0; queue.addLast(startNode); depth.addLast(0); while (!queue.isEmpty() && running()) { int node = queue.removeFirst(); int dp = depth.removeFirst(); if (dp > maxDepth) { break; graph.forEachRelationship(node, direction, (source, target, relationId) -> { if (distance[target] < 0) { queue.addLast(target); depth.addLast(dp + 1); distance[target] = distance[node] + 1;
private void iterateBFS(int startNode, RelationshipConsumer consumer) { IntArrayDeque queue = new IntArrayDeque(); BitSet seen = new BitSet(capacity); queue.addFirst(startNode); while (!queue.isEmpty()) { int node = queue.removeFirst(); int child = children[node]; if (child != INVALID_NODE) { do { if (!seen.getAndSet(child)) { queue.addLast(child); } if (!consumer.accept( node, child, RELATION_ID_NOT_SUPPORTED)) { return; } } while ((child = siblings[child]) != INVALID_NODE); } } }