Skip to content

Commit cbf3b4e

Browse files
committed
Removes dequeue library
Using plain arrays ends up working fast enough here since I'm not making my frontiers over and over.
1 parent 8d726d6 commit cbf3b4e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

2019/18/maze.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const Queue = require('double-ended-queue');
21
const { InfiniteGrid } = require('./infinite-grid');
32

43
const ENTRANCE = '@';
@@ -213,7 +212,9 @@ class Maze {
213212
path.at_end = true;
214213
}
215214
const sorted_keys_str = path.keys_collected.split('').sort().join('');
216-
const path_id = `${JSON.stringify(path.robots_coords)};${sorted_keys_str}`;
215+
const path_id = `${JSON.stringify(
216+
path.robots_coords
217+
)};${sorted_keys_str}`;
217218
if (pruned_paths.has(path_id)) {
218219
// Don't store path if it is longer than current stored path
219220
if (pruned_paths.get(path_id, path).steps > path.steps) {
@@ -236,10 +237,11 @@ class Maze {
236237
for (let iter of [this.entrances, this.keys]) {
237238
for (let [, coord] of iter) {
238239
const [x, y] = coord;
239-
const frontier = new Queue();
240+
// Arrays as FIFO queues are slow, but fast enough here for these small(ish) numbers
241+
const frontier = [];
240242
frontier.push([x, y]);
241243
const came_from = new Map([[InfiniteGrid.toId(x, y), null]]);
242-
while (!frontier.isEmpty()) {
244+
while (frontier.length) {
243245
const current_coord = frontier.shift();
244246
const neighbor_coords = this.grid
245247
.neighbors(...current_coord)

0 commit comments

Comments
 (0)