From a8baa76f6d5fefe832213027a83d172f891c1c09 Mon Sep 17 00:00:00 2001 From: Mike Barry Date: Sat, 9 Nov 2024 16:11:30 -0500 Subject: [PATCH] remove unnecessary visited set --- .../onthegomap/planetiler/util/LoopLineMerger.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/planetiler-core/src/main/java/com/onthegomap/planetiler/util/LoopLineMerger.java b/planetiler-core/src/main/java/com/onthegomap/planetiler/util/LoopLineMerger.java index 6a8b6e729f..98a2f62925 100644 --- a/planetiler-core/src/main/java/com/onthegomap/planetiler/util/LoopLineMerger.java +++ b/planetiler-core/src/main/java/com/onthegomap/planetiler/util/LoopLineMerger.java @@ -2,7 +2,6 @@ import com.onthegomap.planetiler.geo.GeoUtils; import java.util.ArrayList; -import java.util.BitSet; import java.util.Comparator; import java.util.HashMap; import java.util.List; @@ -123,13 +122,11 @@ record HasLoop(Edge edge, double distance) {} private double shortestDistance(Node start, Node end, Node exclude, double maxLength) { Map bestDistance = new HashMap<>(); - BitSet visitedNodes = new BitSet(); - visitedNodes.set(exclude.id); + // BitSet visitedNodes = new BitSet(); record Candidate(Node node, double cost, double heuristic) {} PriorityQueue frontier = new PriorityQueue<>(Comparator.comparingDouble(Candidate::heuristic)); - if (!visitedNodes.get(start.id)) { + if (exclude != start) { frontier.offer(new Candidate(start, 0, start.distance(end))); - visitedNodes.set(start.id); } while (!frontier.isEmpty()) { Candidate candidate = frontier.poll(); @@ -140,7 +137,7 @@ record Candidate(Node node, double cost, double heuristic) {} for (var edge : current.getEdges()) { var neighbor = edge.to; - if (!visitedNodes.get(neighbor.id)) { + if (neighbor != exclude) { double newDist = candidate.cost + edge.length; double prev = bestDistance.getOrDefault(neighbor.id, Double.POSITIVE_INFINITY); if (newDist < prev) { @@ -148,7 +145,7 @@ record Candidate(Node node, double cost, double heuristic) {} double heuristic = newDist + neighbor.distance(end); if (heuristic <= maxLength) { frontier.offer(new Candidate(neighbor, newDist, heuristic)); - visitedNodes.set(neighbor.id); + // visitedNodes.set(neighbor.id); } } }