code clean-up

This commit is contained in:
MadWasp79 2019-10-07 13:23:30 +03:00
parent c6be1a9c10
commit 2ee126419f

View file

@ -36,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 {
@ -76,7 +77,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>>(); 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>();
@ -282,14 +283,6 @@ public class RoutingContext {
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); excludedIdsByTile.get(tileId), original, j);
if(j < subregions.size()- 1) {
if (excludedIdsByTile.get(tileId) == null) {
excludedIdsByTile.put(tileId, new ArrayList<>());
}
if (excludedIdsByTile.get(tileId).size() < j) {
excludedIdsByTile.get(tileId).add(subregions.get(j).excludedIds);
}
}
} }
} }
return original; return original;
@ -502,6 +495,7 @@ 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;
@ -517,8 +511,12 @@ 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);
@ -624,6 +622,7 @@ 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;
@ -661,8 +660,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, List<TLongHashSet> excludedIdsInTile, TLongObjectHashMap<RouteDataObject> excludeDuplications,
RouteSegment original, int subIndex) { 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;
@ -670,8 +669,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, excludedIdsForTile)
&& !isExcluded(ro.id, excludedIdsInTile, subIndex)) { && (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;
@ -685,15 +684,10 @@ public class RoutingContext {
return original; return original;
} }
private boolean isExcluded(long id, List<TLongHashSet> excludedIdsBySub, int subIndex) { private boolean isExcluded(long id, TLongHashSet excludedIdsForTile) {
if (subIndex == 0) { if (excludedIdsForTile != null && excludedIdsForTile.contains(id)) {
return false;
}
for (int i = 0; i < subIndex-1; i++) {
if (excludedIdsBySub.get(i) != null && excludedIdsBySub.get(i).contains(id)) {
return true; return true;
} }
}
return false; return false;
} }