Skip to content

Commit

Permalink
Merge pull request #3580 from steffenaxer/SquareGridZoneSystemFaster
Browse files Browse the repository at this point in the history
Remove redundant zoneToLinksMap
  • Loading branch information
steffenaxer authored Nov 26, 2024
2 parents 5cb44ba + 37ba3ee commit 3f66f59
Showing 1 changed file with 1 addition and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public class SquareGridZoneSystem implements GridZoneSystem {

private final IdMap<Zone, Zone> zones = new IdMap<>(Zone.class);

private final IdMap<Zone, List<Link>> zoneToLinksMap = new IdMap<>(Zone.class);
private final Map<Integer, List<Link>> index2Links;
private final Network network;

Expand Down Expand Up @@ -114,7 +113,7 @@ public Optional<Zone> getZoneForCoord(Coord coord) {

@Override
public List<Link> getLinksForZoneId(Id<Zone> zone) {
return zoneToLinksMap.get(zone);
return this.index2Links.get(Integer.parseInt(zone.toString()));
}

private Optional<Zone> getOrCreateZone(Coord coord) {
Expand All @@ -129,12 +128,6 @@ private Optional<Zone> getOrCreateZone(Coord coord) {
if(zoneFilter.test(zone)) {
internalZones[index] = zone;
zones.put(zone.getId(), zone);
List<Link> linkList = zoneToLinksMap.computeIfAbsent(zone.getId(), zoneId -> new ArrayList<>());
List<Link> links = index2Links.get(index);
if(links!=null)
{
linkList.addAll(links);
}
} else {
return Optional.empty();
}
Expand Down

0 comments on commit 3f66f59

Please sign in to comment.