From 7a2ac1734484a6e3121b6d346627e42131e74e56 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Sun, 7 Jul 2019 21:45:15 +0000 Subject: [PATCH] Simulated minheap --- LayoutLink.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/LayoutLink.js b/LayoutLink.js index 7c8d4c9..2e0d4e1 100644 --- a/LayoutLink.js +++ b/LayoutLink.js @@ -50,7 +50,9 @@ class LayoutLink { }, ]; + let iter = 0; while (queue.length) { + ++iter; let next = queue.shift(); let pos = next.path[next.path.length - 1]; @@ -58,7 +60,7 @@ class LayoutLink { // Can't possibly find a cheaper route via this path // We check this twice (again below), to avoid excessive queueing but // to handle cheapestCostToGoal changing while we're in queue. - continue; + break; } let prevCost = cheapestCostByPos.get(pos); @@ -111,6 +113,7 @@ class LayoutLink { }); } } + queue.sort((a, b) => (a.cost - b.cost)); } for (let hop of this.path) { @@ -121,6 +124,8 @@ class LayoutLink { } links.push(this); } + + console.log(iter); } // Mapping to lines.svg clock-style numbering