Removed priority queue in favor of FlatQueue (#1157)

* removed priority queue in favor of simple array extension as it will be easier to migrate to esm

* patch: bump version

* spacing

* moved references to globalThis

* demonstrate module interop

* added version to priority-queue and moved to utils to follow dom loading pattern

* removed PriorityQueue in favor of FlatQueue

* update index.html

* never mind that force push I don't know how to amend commits right

* missing capitalization

* priority set to 0 on 541

---------

Co-authored-by: RyanGuild <ryan.guild@us-ignite.org>
This commit is contained in:
Ryan D. Guild 2024-10-26 08:26:59 -04:00 committed by GitHub
parent 54491cfd09
commit d7f5cae229
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 40 additions and 39 deletions

View file

@ -77,18 +77,18 @@ window.Provinces = (function () {
});
// expand generated provinces
const queue = new PriorityQueue({comparator: (a, b) => a.p - b.p});
const queue = new FlatQueue();
const cost = [];
provinces.forEach(p => {
if (!p.i || p.removed || isProvinceLocked(p)) return;
provinceIds[p.center] = p.i;
queue.queue({e: p.center, p: 0, province: p.i, state: p.state});
queue.push({e: p.center, province: p.i, state: p.state, p: 0}, 0);
cost[p.center] = 1;
});
while (queue.length) {
const {e, p, province, state} = queue.dequeue();
const {e, p, province, state} = queue.pop();
cells.c[e].forEach(e => {
if (isProvinceCellLocked(e)) return; // do not overwrite cell of locked provinces
@ -103,7 +103,7 @@ window.Provinces = (function () {
if (!cost[e] || totalCost < cost[e]) {
if (land) provinceIds[e] = province; // assign province to a cell
cost[e] = totalCost;
queue.queue({e, p: totalCost, province, state});
queue.push({e, province, state, p: totalCost}, totalCost);
}
});
}
@ -158,9 +158,9 @@ window.Provinces = (function () {
// expand province
const cost = [];
cost[center] = 1;
queue.queue({e: center, p: 0});
queue.push({e: center, p: 0}, 0);
while (queue.length) {
const {e, p} = queue.dequeue();
const {e, p} = queue.pop();
cells.c[e].forEach(nextCellId => {
if (provinceIds[nextCellId]) return;
@ -173,7 +173,7 @@ window.Provinces = (function () {
if (!cost[nextCellId] || totalCost < cost[nextCellId]) {
if (land && cells.state[nextCellId] === s.i) provinceIds[nextCellId] = provinceId; // assign province to a cell
cost[nextCellId] = totalCost;
queue.queue({e: nextCellId, p: totalCost});
queue.push({e: nextCellId, p: totalCost}, totalCost);
}
});
}
@ -216,15 +216,15 @@ window.Provinces = (function () {
// check if there is a land way within the same state between two cells
function isPassable(from, to) {
if (cells.f[from] !== cells.f[to]) return false; // on different islands
const queue = [from],
const passableQueue = [from],
used = new Uint8Array(cells.i.length),
state = cells.state[from];
while (queue.length) {
const current = queue.pop();
while (passableQueue.length) {
const current = passableQueue.pop();
if (current === to) return true; // way is found
cells.c[current].forEach(c => {
if (used[c] || cells.h[c] < 20 || cells.state[c] !== state) return;
queue.push(c);
passableQueue.push(c);
used[c] = 1;
});
}