MCPcopy Index your code
hub / github.com/graphhopper/graphhopper / BaseGraph

Class BaseGraph

core/src/main/java/com/graphhopper/storage/BaseGraph.java:49–1093  ·  view source on GitHub ↗

The base graph handles nodes and edges file format. It can be used with different Directory implementations like RAMDirectory for fast access or via MMapDirectory for virtual-memory and not thread safe usage. Note: A RAM DataAccess Object is thread-safe in itself but if used in this Graph implem

Source from the content-addressed store, hash-verified

47 * loadExisting, (4) usage, (5) flush, (6) close
48 */
49public class BaseGraph implements Graph, Closeable {
50 final static long MAX_UNSIGNED_INT = 0xFFFF_FFFFL;
51 final BaseGraphNodesAndEdges store;
52 final NodeAccess nodeAccess;
53 final KVStorage edgeKVStorage;
54 // can be null if turn costs are not supported
55 final TurnCostStorage turnCostStorage;
56 final BitUtil bitUtil;
57 // length | nodeA | nextNode | ... | nodeB
58 private final DataAccess wayGeometry;
59 private final Directory dir;
60 private final int segmentSize;
61 private boolean initialized = false;
62 private long minGeoRef;
63 private long maxGeoRef;
64 private final int eleBytesPerCoord;
65
66 public BaseGraph(Directory dir, boolean withElevation, boolean withTurnCosts, int segmentSize, int bytesForFlags) {
67 this.dir = dir;
68 this.bitUtil = BitUtil.LITTLE;
69 this.wayGeometry = dir.create("geometry", segmentSize);
70 this.edgeKVStorage = new KVStorage(dir, true);
71 this.store = new BaseGraphNodesAndEdges(dir, withElevation, withTurnCosts, segmentSize, bytesForFlags);
72 this.nodeAccess = new GHNodeAccess(store);
73 this.segmentSize = segmentSize;
74 this.turnCostStorage = withTurnCosts ? new TurnCostStorage(this, dir.create("turn_costs", dir.getDefaultType("turn_costs", true), segmentSize)) : null;
75 this.eleBytesPerCoord = (nodeAccess.getDimension() == 3 ? 3 : 0);
76 }
77
78 BaseGraphNodesAndEdges getStore() {
79 return store;
80 }
81
82 private int getOtherNode(int nodeThis, long edgePointer) {
83 int nodeA = store.getNodeA(edgePointer);
84 return nodeThis == nodeA ? store.getNodeB(edgePointer) : nodeA;
85 }
86
87 private boolean isAdjacentToNode(int node, long edgePointer) {
88 return store.getNodeA(edgePointer) == node || store.getNodeB(edgePointer) == node;
89 }
90
91 private static boolean isTestingEnabled() {
92 boolean enableIfAssert = false;
93 assert (enableIfAssert = true) : true;
94 return enableIfAssert;
95 }
96
97 public void debugPrint() {
98 store.debugPrint();
99 }
100
101 @Override
102 public BaseGraph getBaseGraph() {
103 return this;
104 }
105
106 public boolean isInitialized() {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected