Merge pull request #7636 from osmandapp/routing_fix
fix for slow excluded id check
This commit is contained in:
commit
30f257dc8b
1 changed files with 20 additions and 13 deletions
|
@ -6,10 +6,13 @@ import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
@ -33,6 +36,7 @@ import net.osmand.router.BinaryRoutePlanner.FinalRouteSegment;
|
||||||
import net.osmand.router.BinaryRoutePlanner.RouteSegment;
|
import net.osmand.router.BinaryRoutePlanner.RouteSegment;
|
||||||
import net.osmand.router.BinaryRoutePlanner.RouteSegmentVisitor;
|
import net.osmand.router.BinaryRoutePlanner.RouteSegmentVisitor;
|
||||||
import net.osmand.router.RoutePlannerFrontEnd.RouteCalculationMode;
|
import net.osmand.router.RoutePlannerFrontEnd.RouteCalculationMode;
|
||||||
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
|
|
||||||
public class RoutingContext {
|
public class RoutingContext {
|
||||||
|
@ -108,7 +112,6 @@ public class RoutingContext {
|
||||||
// old planner
|
// old planner
|
||||||
public FinalRouteSegment finalRouteSegment;
|
public FinalRouteSegment finalRouteSegment;
|
||||||
|
|
||||||
|
|
||||||
RoutingContext(RoutingContext cp) {
|
RoutingContext(RoutingContext cp) {
|
||||||
this.config = cp.config;
|
this.config = cp.config;
|
||||||
this.map.putAll(cp.map);
|
this.map.putAll(cp.map);
|
||||||
|
@ -272,17 +275,12 @@ public class RoutingContext {
|
||||||
public RouteSegment loadRouteSegment(int x31, int y31, int memoryLimit) {
|
public RouteSegment loadRouteSegment(int x31, int y31, int memoryLimit) {
|
||||||
long tileId = getRoutingTile(x31, y31, memoryLimit, OPTION_SMART_LOAD);
|
long tileId = getRoutingTile(x31, y31, memoryLimit, OPTION_SMART_LOAD);
|
||||||
TLongObjectHashMap<RouteDataObject> excludeDuplications = new TLongObjectHashMap<RouteDataObject>();
|
TLongObjectHashMap<RouteDataObject> excludeDuplications = new TLongObjectHashMap<RouteDataObject>();
|
||||||
TLongSet excludeIds = new TLongHashSet();
|
|
||||||
RouteSegment original = null;
|
RouteSegment original = null;
|
||||||
List<RoutingSubregionTile> subregions = indexedSubregions.get(tileId);
|
List<RoutingSubregionTile> subregions = indexedSubregions.get(tileId);
|
||||||
if (subregions != null) {
|
if (subregions != null) {
|
||||||
for (RoutingSubregionTile rs : subregions) {
|
for (int j = 0; j < subregions.size(); j++) {
|
||||||
// TODO
|
original = subregions.get(j).loadRouteSegment(x31, y31, this, excludeDuplications,
|
||||||
original = rs.loadRouteSegment(x31, y31, this, excludeDuplications, excludeIds,
|
original, subregions, j);
|
||||||
original);
|
|
||||||
if(rs.excludedIds != null) {
|
|
||||||
excludeIds.addAll(rs.excludedIds);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return original;
|
return original;
|
||||||
|
@ -654,7 +652,7 @@ public class RoutingContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
private RouteSegment loadRouteSegment(int x31, int y31, RoutingContext ctx,
|
private RouteSegment loadRouteSegment(int x31, int y31, RoutingContext ctx,
|
||||||
TLongObjectHashMap<RouteDataObject> excludeDuplications, TLongSet excludeIds, RouteSegment original) {
|
TLongObjectHashMap<RouteDataObject> excludeDuplications, RouteSegment original, List<RoutingSubregionTile> subregions, int subregionIndex) {
|
||||||
access++;
|
access++;
|
||||||
if (routes != null) {
|
if (routes != null) {
|
||||||
long l = (((long) x31) << 31) + (long) y31;
|
long l = (((long) x31) << 31) + (long) y31;
|
||||||
|
@ -662,8 +660,8 @@ public class RoutingContext {
|
||||||
while (segment != null) {
|
while (segment != null) {
|
||||||
RouteDataObject ro = segment.road;
|
RouteDataObject ro = segment.road;
|
||||||
RouteDataObject toCmp = excludeDuplications.get(calcRouteId(ro, segment.getSegmentStart()));
|
RouteDataObject toCmp = excludeDuplications.get(calcRouteId(ro, segment.getSegmentStart()));
|
||||||
if ((toCmp == null || toCmp.getPointsLength() < ro.getPointsLength())
|
if (!isExcluded(ro.id, subregions, subregionIndex)
|
||||||
&& !excludeIds.contains(ro.id)) {
|
&& (toCmp == null || toCmp.getPointsLength() < ro.getPointsLength())) {
|
||||||
excludeDuplications.put(calcRouteId(ro, segment.getSegmentStart()), ro);
|
excludeDuplications.put(calcRouteId(ro, segment.getSegmentStart()), ro);
|
||||||
RouteSegment s = new RouteSegment(ro, segment.getSegmentStart());
|
RouteSegment s = new RouteSegment(ro, segment.getSegmentStart());
|
||||||
s.next = original;
|
s.next = original;
|
||||||
|
@ -677,6 +675,15 @@ public class RoutingContext {
|
||||||
return original;
|
return original;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isExcluded(long id, List<RoutingSubregionTile> subregions, int subregionIndex) {
|
||||||
|
for (int i = 0; i < subregionIndex; i++ ) {
|
||||||
|
if (subregions.get(i).excludedIds != null && subregions.get(i).excludedIds.contains(id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isLoaded() {
|
public boolean isLoaded() {
|
||||||
return isLoaded > 0;
|
return isLoaded > 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue