This commit is contained in:
MadWasp79 2019-10-07 17:55:40 +03:00
parent 2ee126419f
commit 534f03d558

View file

@ -77,7 +77,6 @@ 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<TLongHashSet> excludedIdsByTile = new TLongObjectHashMap<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>();
@ -234,7 +233,6 @@ public class RoutingContext {
} }
subregionTiles.clear(); subregionTiles.clear();
indexedSubregions.clear(); indexedSubregions.clear();
excludedIdsByTile.clear();
} }
private int searchSubregionTile(RouteSubregion subregion){ private int searchSubregionTile(RouteSubregion subregion){
@ -282,7 +280,7 @@ public class RoutingContext {
if (subregions != null) { if (subregions != null) {
for (int j = 0; j < subregions.size(); j++) { for (int j = 0; j < subregions.size(); j++) {
original = subregions.get(j).loadRouteSegment(x31, y31, this, excludeDuplications, original = subregions.get(j).loadRouteSegment(x31, y31, this, excludeDuplications,
excludedIdsByTile.get(tileId), original, j); original, subregions, j);
} }
} }
return original; return original;
@ -495,7 +493,6 @@ public class RoutingContext {
List<RoutingSubregionTile> subregions = indexedSubregions.get(tileId); List<RoutingSubregionTile> subregions = indexedSubregions.get(tileId);
if (subregions != null) { if (subregions != null) {
boolean load = false; boolean load = false;
TLongHashSet excludedIdsForTile = new TLongHashSet();
for (RoutingSubregionTile ts : subregions) { for (RoutingSubregionTile ts : subregions) {
if (!ts.isLoaded()) { if (!ts.isLoaded()) {
load = true; load = true;
@ -511,12 +508,8 @@ public class RoutingContext {
excludeIds.addAll(ts.excludedIds); excludeIds.addAll(ts.excludedIds);
} }
} }
if (excludeIds != null) {
excludedIdsForTile.addAll(excludeIds);
} }
} }
excludedIdsByTile.put(tileId, excludedIdsForTile);
}
} }
} }
// timeToLoad += (System.nanoTime() - now); // timeToLoad += (System.nanoTime() - now);
@ -622,7 +615,6 @@ public class RoutingContext {
private int isLoaded = 0; private int isLoaded = 0;
private TLongObjectMap<RouteSegment> routes = null; private TLongObjectMap<RouteSegment> routes = null;
private TLongHashSet excludedIds = null; private TLongHashSet excludedIds = null;
private TLongHashSet excludedIdsForTile = null;
public RoutingSubregionTile(RouteSubregion subregion) { public RoutingSubregionTile(RouteSubregion subregion) {
this.subregion = subregion; this.subregion = subregion;
@ -660,8 +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, TLongObjectHashMap<RouteDataObject> excludeDuplications, RouteSegment original, List<RoutingSubregionTile> subregions, int subregionIndex) {
TLongHashSet excludedIdsForTile, 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;
@ -669,7 +660,7 @@ 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 (!isExcluded(ro.id, excludedIdsForTile) if (!isExcluded(ro.id, subregions, subregionIndex)
&& (toCmp == null || toCmp.getPointsLength() < ro.getPointsLength())) { && (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());
@ -684,10 +675,12 @@ public class RoutingContext {
return original; return original;
} }
private boolean isExcluded(long id, TLongHashSet excludedIdsForTile) { private static boolean isExcluded(long id, List<RoutingSubregionTile> subregions, int subregionIndex) {
if (excludedIdsForTile != null && excludedIdsForTile.contains(id)) { for (int i = 0; i < subregionIndex; i++ ) {
if (subregions.get(i).excludedIds != null && subregions.get(i).excludedIds.contains(id)) {
return true; return true;
} }
}
return false; return false;
} }