Skip to content

Commit

Permalink
fix #288, Bug in LevelEdgeFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter committed Jan 23, 2015
1 parent a80ea42 commit be4dd6b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/com/graphhopper/routing/QueryGraph.java
Expand Up @@ -624,7 +624,7 @@ public AllEdgesIterator getAllEdges()
public int getLevel( int nodeId ) public int getLevel( int nodeId )
{ {
if (isVirtualNode(nodeId)) if (isVirtualNode(nodeId))
return 0; throw new IllegalStateException("LevelEdgeFilter should prevent fetching level for virtual nodes: " + nodeId + ", See #288");


return ((LevelGraph) mainGraph).getLevel(nodeId); return ((LevelGraph) mainGraph).getLevel(nodeId);
} }
Expand Down
Expand Up @@ -28,21 +28,21 @@
public class LevelEdgeFilter implements EdgeFilter public class LevelEdgeFilter implements EdgeFilter
{ {
private final LevelGraph graph; private final LevelGraph graph;
private final int nodes; private final int maxNodes;


public LevelEdgeFilter( LevelGraph g ) public LevelEdgeFilter( LevelGraph g )
{ {
graph = g; graph = g;
nodes = g.getNodes(); maxNodes = g.getNodes();
} }


@Override @Override
public boolean accept( EdgeIteratorState edgeIterState ) public boolean accept( EdgeIteratorState edgeIterState )
{ {
int base = edgeIterState.getBaseNode(); int base = edgeIterState.getBaseNode();
int adj = edgeIterState.getAdjNode(); int adj = edgeIterState.getAdjNode();
// for now workaround for #288 // always accept virtual edges, see #288
if (base >= nodes || adj >= nodes) if (base >= maxNodes || adj >= maxNodes)
return true; return true;


return graph.getLevel(base) <= graph.getLevel(adj); return graph.getLevel(base) <= graph.getLevel(adj);
Expand Down
Expand Up @@ -80,7 +80,7 @@ public final int getLevel( int nodeIndex )
{ {
// automatically allocate new nodes only via creating edges or setting node properties // automatically allocate new nodes only via creating edges or setting node properties
if (nodeIndex >= getNodes()) if (nodeIndex >= getNodes())
return 0; throw new IllegalStateException("node " + nodeIndex + " is invalid. Not in [0," + getNodes() + ")");


return nodes.getInt((long) nodeIndex * nodeEntryBytes + I_LEVEL); return nodes.getInt((long) nodeIndex * nodeEntryBytes + I_LEVEL);
} }
Expand Down

0 comments on commit be4dd6b

Please sign in to comment.