fix for slow excluded id check
This commit is contained in:
parent
5143f186d5
commit
c6be1a9c10
1 changed files with 32 additions and 12 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;
|
||||||
|
@ -73,6 +76,7 @@ public class RoutingContext {
|
||||||
|
|
||||||
// 2. Routing memory cache (big objects)
|
// 2. Routing memory cache (big objects)
|
||||||
TLongObjectHashMap<List<RoutingSubregionTile>> indexedSubregions = new TLongObjectHashMap<List<RoutingSubregionTile>>();
|
TLongObjectHashMap<List<RoutingSubregionTile>> indexedSubregions = new TLongObjectHashMap<List<RoutingSubregionTile>>();
|
||||||
|
TLongObjectHashMap<List<TLongHashSet>> excludedIdsByTile = new TLongObjectHashMap<List<TLongHashSet>>();
|
||||||
|
|
||||||
// Needs to be a sorted array list . Another option to use hashmap but it will be more memory expensive
|
// Needs to be a sorted array list . Another option to use hashmap but it will be more memory expensive
|
||||||
List<RoutingSubregionTile> subregionTiles = new ArrayList<RoutingSubregionTile>();
|
List<RoutingSubregionTile> subregionTiles = new ArrayList<RoutingSubregionTile>();
|
||||||
|
@ -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);
|
||||||
|
@ -230,6 +233,7 @@ public class RoutingContext {
|
||||||
}
|
}
|
||||||
subregionTiles.clear();
|
subregionTiles.clear();
|
||||||
indexedSubregions.clear();
|
indexedSubregions.clear();
|
||||||
|
excludedIdsByTile.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int searchSubregionTile(RouteSubregion subregion){
|
private int searchSubregionTile(RouteSubregion subregion){
|
||||||
|
@ -272,16 +276,19 @@ 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,
|
excludedIdsByTile.get(tileId), original, j);
|
||||||
original);
|
if(j < subregions.size()- 1) {
|
||||||
if(rs.excludedIds != null) {
|
if (excludedIdsByTile.get(tileId) == null) {
|
||||||
excludeIds.addAll(rs.excludedIds);
|
excludedIdsByTile.put(tileId, new ArrayList<>());
|
||||||
|
}
|
||||||
|
if (excludedIdsByTile.get(tileId).size() < j) {
|
||||||
|
excludedIdsByTile.get(tileId).add(subregions.get(j).excludedIds);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -654,7 +661,8 @@ 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, List<TLongHashSet> excludedIdsInTile,
|
||||||
|
RouteSegment original, int subIndex) {
|
||||||
access++;
|
access++;
|
||||||
if (routes != null) {
|
if (routes != null) {
|
||||||
long l = (((long) x31) << 31) + (long) y31;
|
long l = (((long) x31) << 31) + (long) y31;
|
||||||
|
@ -663,7 +671,7 @@ public class RoutingContext {
|
||||||
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 ((toCmp == null || toCmp.getPointsLength() < ro.getPointsLength())
|
||||||
&& !excludeIds.contains(ro.id)) {
|
&& !isExcluded(ro.id, excludedIdsInTile, subIndex)) {
|
||||||
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 +685,18 @@ public class RoutingContext {
|
||||||
return original;
|
return original;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isExcluded(long id, List<TLongHashSet> excludedIdsBySub, int subIndex) {
|
||||||
|
if (subIndex == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < subIndex-1; i++) {
|
||||||
|
if (excludedIdsBySub.get(i) != null && excludedIdsBySub.get(i).contains(id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isLoaded() {
|
public boolean isLoaded() {
|
||||||
return isLoaded > 0;
|
return isLoaded > 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue