final long writeEdge(int edgeId, int nodeThis, int nodeOther, int nextEdge, int nextEdgeOther) { if (nodeThis > nodeOther) { int tmp = nodeThis; nodeThis = nodeOther; nodeOther = tmp; tmp = nextEdge; nextEdge = nextEdgeOther; nextEdgeOther = tmp; } if (edgeId < 0 || edgeId == EdgeIterator.NO_EDGE) throw new IllegalStateException("Cannot write edge with illegal ID:" + edgeId + "; nodeThis:" + nodeThis + ", nodeOther:" + nodeOther); long edgePointer = toPointer(edgeId); edges.setInt(edgePointer + E_NODEA, nodeThis); edges.setInt(edgePointer + E_NODEB, nodeOther); edges.setInt(edgePointer + E_LINKA, nextEdge); edges.setInt(edgePointer + E_LINKB, nextEdgeOther); return edgePointer; }
final void connectNewEdge(int fromNode, int otherNode, int newOrExistingEdge) { int edge = getEdgeRef(fromNode); if (edge > EdgeIterator.NO_EDGE) { long edgePointer = toPointer(newOrExistingEdge); long lastLink = _getLinkPosInEdgeArea(fromNode, otherNode, edgePointer); edges.setInt(lastLink, edge); } setEdgeRef(fromNode, newOrExistingEdge); }
final boolean init(int tmpEdgeId, int expectedAdjNode) { setEdgeId(tmpEdgeId); if (!EdgeIterator.Edge.isValid(edgeId)) throw new IllegalArgumentException("fetching the edge requires a valid edgeId but was " + edgeId); selectEdgeAccess(); edgePointer = edgeAccess.toPointer(tmpEdgeId); baseNode = edgeAccess.edges.getInt(edgePointer + edgeAccess.E_NODEA); if (baseNode == EdgeAccess.NO_NODE) throw new IllegalStateException("content of edgeId " + edgeId + " is marked as invalid - ie. the edge is already removed!"); adjNode = edgeAccess.edges.getInt(edgePointer + edgeAccess.E_NODEB); // a next() call should return false nextEdgeId = EdgeIterator.NO_EDGE; if (expectedAdjNode == adjNode || expectedAdjNode == Integer.MIN_VALUE) { reverse = false; return true; } else if (expectedAdjNode == baseNode) { reverse = true; baseNode = adjNode; adjNode = expectedAdjNode; return true; } return false; }
@Override public final boolean next() { while (true) { if (nextEdgeId == EdgeIterator.NO_EDGE) return false; selectEdgeAccess(); edgePointer = edgeAccess.toPointer(nextEdgeId); edgeId = nextEdgeId; adjNode = edgeAccess.getOtherNode(baseNode, edgePointer); reverse = baseNode > adjNode; freshFlags = false; // position to next edge nextEdgeId = edgeAccess.getEdgeRef(baseNode, adjNode, edgePointer); assert nextEdgeId != edgeId : ("endless loop detected for base node: " + baseNode + ", adj node: " + adjNode + ", edge pointer: " + edgePointer + ", edge: " + edgeId); if (filter.accept(this)) return true; } }
/** * This method disconnects the specified edge from the list of edges of the specified node. It * does not release the freed space to be reused. * <p> * * @param edgeToUpdatePointer if it is negative then the nextEdgeId will be saved to refToEdges * of nodes */ final long internalEdgeDisconnect(int edgeToRemove, long edgeToUpdatePointer, int baseNode, int adjNode) { long edgeToRemovePointer = toPointer(edgeToRemove); // an edge is shared across the two nodes even if the edge is not in both directions // so we need to know two edge-pointers pointing to the edge before edgeToRemovePointer int nextEdgeId = getEdgeRef(baseNode, adjNode, edgeToRemovePointer); if (edgeToUpdatePointer < 0) { setEdgeRef(baseNode, nextEdgeId); } else { // adjNode is different for the edge we want to update with the new link long link = edges.getInt(edgeToUpdatePointer + E_NODEA) == baseNode ? edgeToUpdatePointer + E_LINKA : edgeToUpdatePointer + E_LINKB; edges.setInt(link, nextEdgeId); } return edgeToRemovePointer; }
@Override public void disconnect(CHEdgeExplorer explorer, EdgeIteratorState edgeState) { // search edge with opposite direction but we need to know the previousEdge for the internalEdgeDisconnect so we cannot simply do: // EdgeIteratorState tmpIter = getEdgeProps(iter.getEdge(), iter.getBaseNode()); CHEdgeIterator tmpIter = explorer.setBaseNode(edgeState.getAdjNode()); int tmpPrevEdge = EdgeIterator.NO_EDGE; while (tmpIter.next()) { if (tmpIter.isShortcut() && tmpIter.getEdge() == edgeState.getEdge()) { // TODO this is ugly, move this somehow into the underlying iteration logic long edgePointer = tmpPrevEdge == EdgeIterator.NO_EDGE ? -1 : isShortcut(tmpPrevEdge) ? chEdgeAccess.toPointer(tmpPrevEdge) : baseGraph.edgeAccess.toPointer(tmpPrevEdge); chEdgeAccess.internalEdgeDisconnect(edgeState.getEdge(), edgePointer, edgeState.getAdjNode(), edgeState.getBaseNode()); break; } tmpPrevEdge = tmpIter.getEdge(); } }
long edgeToRemovePointer = edgeAccess.toPointer(edgeToRemove); edgeAccess.internalEdgeDisconnect(edgeToRemove, prev, removeNode, nodeId); edgeAccess.invalidateEdge(edgeToRemovePointer); long edgePointer = edgeAccess.toPointer(edgeId); int linkA = edgeAccess.getEdgeRef(nodeA, nodeB, edgePointer); int linkB = edgeAccess.getEdgeRef(nodeB, nodeA, edgePointer);
final long writeEdge(int edgeId, int nodeThis, int nodeOther, int nextEdge, int nextEdgeOther) { if (nodeThis > nodeOther) { int tmp = nodeThis; nodeThis = nodeOther; nodeOther = tmp; tmp = nextEdge; nextEdge = nextEdgeOther; nextEdgeOther = tmp; } if (edgeId < 0 || edgeId == EdgeIterator.NO_EDGE) throw new IllegalStateException("Cannot write edge with illegal ID:" + edgeId + "; nodeThis:" + nodeThis + ", nodeOther:" + nodeOther); long edgePointer = toPointer(edgeId); edges.setInt(edgePointer + E_NODEA, nodeThis); edges.setInt(edgePointer + E_NODEB, nodeOther); edges.setInt(edgePointer + E_LINKA, nextEdge); edges.setInt(edgePointer + E_LINKB, nextEdgeOther); return edgePointer; }
final long writeEdge(int edgeId, int nodeThis, int nodeOther, int nextEdge, int nextEdgeOther) { if (nodeThis > nodeOther) { int tmp = nodeThis; nodeThis = nodeOther; nodeOther = tmp; tmp = nextEdge; nextEdge = nextEdgeOther; nextEdgeOther = tmp; } if (edgeId < 0 || edgeId == EdgeIterator.NO_EDGE) throw new IllegalStateException("Cannot write edge with illegal ID:" + edgeId + "; nodeThis:" + nodeThis + ", nodeOther:" + nodeOther); long edgePointer = toPointer(edgeId); edges.setInt(edgePointer + E_NODEA, nodeThis); edges.setInt(edgePointer + E_NODEB, nodeOther); edges.setInt(edgePointer + E_LINKA, nextEdge); edges.setInt(edgePointer + E_LINKB, nextEdgeOther); return edgePointer; }
final void connectNewEdge(int fromNode, int otherNode, int newOrExistingEdge) { int edge = getEdgeRef(fromNode); if (edge > EdgeIterator.NO_EDGE) { long edgePointer = toPointer(newOrExistingEdge); long lastLink = _getLinkPosInEdgeArea(fromNode, otherNode, edgePointer); edges.setInt(lastLink, edge); } setEdgeRef(fromNode, newOrExistingEdge); }
final long writeEdge( int edgeId, int nodeThis, int nodeOther, int nextEdge, int nextEdgeOther ) { if (nodeThis > nodeOther) { int tmp = nodeThis; nodeThis = nodeOther; nodeOther = tmp; tmp = nextEdge; nextEdge = nextEdgeOther; nextEdgeOther = tmp; } if (edgeId < 0 || edgeId == EdgeIterator.NO_EDGE) throw new IllegalStateException("Cannot write edge with illegal ID:" + edgeId + "; nodeThis:" + nodeThis + ", nodeOther:" + nodeOther); long edgePointer = toPointer(edgeId); edges.setInt(edgePointer + E_NODEA, nodeThis); edges.setInt(edgePointer + E_NODEB, nodeOther); edges.setInt(edgePointer + E_LINKA, nextEdge); edges.setInt(edgePointer + E_LINKB, nextEdgeOther); return edgePointer; }
final boolean init(int tmpEdgeId, int expectedAdjNode) { setEdgeId(tmpEdgeId); if (tmpEdgeId != EdgeIterator.NO_EDGE) { selectEdgeAccess(); this.edgePointer = edgeAccess.toPointer(tmpEdgeId); } // expect only edgePointer is properly initialized via setEdgeId baseNode = edgeAccess.edges.getInt(edgePointer + edgeAccess.E_NODEA); if (baseNode == EdgeAccess.NO_NODE) throw new IllegalStateException("content of edgeId " + edgeId + " is marked as invalid - ie. the edge is already removed!"); adjNode = edgeAccess.edges.getInt(edgePointer + edgeAccess.E_NODEB); // a next() call should return false nextEdgeId = EdgeIterator.NO_EDGE; if (expectedAdjNode == adjNode || expectedAdjNode == Integer.MIN_VALUE) { reverse = false; return true; } else if (expectedAdjNode == baseNode) { reverse = true; baseNode = adjNode; adjNode = expectedAdjNode; return true; } return false; }
@Override public final boolean next() { while (true) { if (nextEdgeId == EdgeIterator.NO_EDGE) return false; selectEdgeAccess(); edgePointer = edgeAccess.toPointer(nextEdgeId); edgeId = nextEdgeId; adjNode = edgeAccess.getOtherNode(baseNode, edgePointer); reverse = baseNode > adjNode; freshFlags = false; // position to next edge nextEdgeId = edgeAccess.getEdgeRef(baseNode, adjNode, edgePointer); assert nextEdgeId != edgeId : ("endless loop detected for base node: " + baseNode + ", adj node: " + adjNode + ", edge pointer: " + edgePointer + ", edge: " + edgeId); if (filter.accept(this)) return true; } }
final void connectNewEdge( int fromNode, int newOrExistingEdge ) { int edge = getEdgeRef(fromNode); if (edge > EdgeIterator.NO_EDGE) { long edgePointer = toPointer(newOrExistingEdge); int otherNode = getOtherNode(fromNode, edgePointer); long lastLink = _getLinkPosInEdgeArea(fromNode, otherNode, edgePointer); edges.setInt(lastLink, edge); } setEdgeRef(fromNode, newOrExistingEdge); }
final void connectNewEdge(int fromNode, int newOrExistingEdge) { int edge = getEdgeRef(fromNode); if (edge > EdgeIterator.NO_EDGE) { long edgePointer = toPointer(newOrExistingEdge); int otherNode = getOtherNode(fromNode, edgePointer); long lastLink = _getLinkPosInEdgeArea(fromNode, otherNode, edgePointer); edges.setInt(lastLink, edge); } setEdgeRef(fromNode, newOrExistingEdge); }
@Override public final boolean next() { while (true) { if (nextEdgeId == EdgeIterator.NO_EDGE) return false; selectEdgeAccess(); edgePointer = edgeAccess.toPointer(nextEdgeId); edgeId = nextEdgeId; adjNode = edgeAccess.getOtherNode(baseNode, edgePointer); reverse = baseNode > adjNode; freshFlags = false; // position to next edge nextEdgeId = edgeAccess.getEdgeRef(baseNode, adjNode, edgePointer); assert nextEdgeId != edgeId : ("endless loop detected for base node: " + baseNode + ", adj node: " + adjNode + ", edge pointer: " + edgePointer + ", edge: " + edgeId); if (filter.accept(this)) return true; } }
@Override public final boolean next() { while (true) { if (nextEdgeId == EdgeIterator.NO_EDGE) return false; selectEdgeAccess(); edgePointer = edgeAccess.toPointer(nextEdgeId); edgeId = nextEdgeId; adjNode = edgeAccess.getOtherNode(baseNode, edgePointer); reverse = baseNode > adjNode; freshFlags = false; // position to next edge nextEdgeId = edgeAccess.getEdgeRef(baseNode, adjNode, edgePointer); assert nextEdgeId != edgeId : ("endless loop detected for base node: " + baseNode + ", adj node: " + adjNode + ", edge pointer: " + edgePointer + ", edge: " + edgeId); if (filter.accept(this)) return true; } }
/** * This method disconnects the specified edge from the list of edges of the specified node. It * does not release the freed space to be reused. * <p> * * @param edgeToUpdatePointer if it is negative then the nextEdgeId will be saved to refToEdges * of nodes */ final long internalEdgeDisconnect(int edgeToRemove, long edgeToUpdatePointer, int baseNode, int adjNode) { long edgeToRemovePointer = toPointer(edgeToRemove); // an edge is shared across the two nodes even if the edge is not in both directions // so we need to know two edge-pointers pointing to the edge before edgeToRemovePointer int nextEdgeId = getEdgeRef(baseNode, adjNode, edgeToRemovePointer); if (edgeToUpdatePointer < 0) { setEdgeRef(baseNode, nextEdgeId); } else { // adjNode is different for the edge we want to update with the new link long link = edges.getInt(edgeToUpdatePointer + E_NODEA) == baseNode ? edgeToUpdatePointer + E_LINKA : edgeToUpdatePointer + E_LINKB; edges.setInt(link, nextEdgeId); } return edgeToRemovePointer; }
/** * Disconnects the edges (higher to lower node) via the specified edgeState pointing from lower to * higher node. * <p> * * @param edgeState the edge from lower to higher */ public void disconnect(CHEdgeExplorer explorer, EdgeIteratorState edgeState) { // search edge with opposite direction but we need to know the previousEdge for the internalEdgeDisconnect so we cannot simply do: // EdgeIteratorState tmpIter = getEdgeProps(iter.getEdge(), iter.getBaseNode()); CHEdgeIterator tmpIter = explorer.setBaseNode(edgeState.getAdjNode()); int tmpPrevEdge = EdgeIterator.NO_EDGE; while (tmpIter.next()) { if (tmpIter.isShortcut() && tmpIter.getEdge() == edgeState.getEdge()) { // TODO this is ugly, move this somehow into the underlying iteration logic long edgePointer = tmpPrevEdge == EdgeIterator.NO_EDGE ? -1 : isShortcut(tmpPrevEdge) ? chEdgeAccess.toPointer(tmpPrevEdge) : baseGraph.edgeAccess.toPointer(tmpPrevEdge); chEdgeAccess.internalEdgeDisconnect(edgeState.getEdge(), edgePointer, edgeState.getAdjNode(), edgeState.getBaseNode()); break; } tmpPrevEdge = tmpIter.getEdge(); } }
/** * Disconnects the edges (higher to lower node) via the specified edgeState pointing from lower to * higher node. * <p> * * @param edgeState the edge from lower to higher */ public void disconnect(CHEdgeExplorer explorer, EdgeIteratorState edgeState) { // search edge with opposite direction but we need to know the previousEdge for the internalEdgeDisconnect so we cannot simply do: // EdgeIteratorState tmpIter = getEdgeProps(iter.getEdge(), iter.getBaseNode()); CHEdgeIterator tmpIter = explorer.setBaseNode(edgeState.getAdjNode()); int tmpPrevEdge = EdgeIterator.NO_EDGE; while (tmpIter.next()) { if (tmpIter.isShortcut() && tmpIter.getEdge() == edgeState.getEdge()) { // TODO this is ugly, move this somehow into the underlying iteration logic long edgePointer = tmpPrevEdge == EdgeIterator.NO_EDGE ? -1 : isShortcut(tmpPrevEdge) ? chEdgeAccess.toPointer(tmpPrevEdge) : baseGraph.edgeAccess.toPointer(tmpPrevEdge); chEdgeAccess.internalEdgeDisconnect(edgeState.getEdge(), edgePointer, edgeState.getAdjNode(), edgeState.getBaseNode()); break; } tmpPrevEdge = tmpIter.getEdge(); } }