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

@ -518,7 +518,7 @@ window.Cultures = (function () {
TIME && console.time("expandCultures");
const {cells, cultures} = pack;
const queue = new PriorityQueue({comparator: (a, b) => a.priority - b.priority});
const queue = new FlatQueue();
const cost = [];
const neutralRate = byId("neutralRate")?.valueAsNumber || 1;
@ -538,11 +538,11 @@ window.Cultures = (function () {
for (const culture of cultures) {
if (!culture.i || culture.removed || culture.lock) continue;
queue.queue({cellId: culture.center, cultureId: culture.i, priority: 0});
queue.push({cellId: culture.center, cultureId: culture.i, priority: 0}, 0);
}
while (queue.length) {
const {cellId, priority, cultureId} = queue.dequeue();
const {cellId, priority, cultureId} = queue.pop();
const {type, expansionism} = cultures[cultureId];
cells.c[cellId].forEach(neibCellId => {
@ -566,7 +566,7 @@ window.Cultures = (function () {
if (!cost[neibCellId] || totalCost < cost[neibCellId]) {
if (cells.pop[neibCellId] > 0) cells.culture[neibCellId] = cultureId; // assign culture to populated cell
cost[neibCellId] = totalCost;
queue.queue({cellId: neibCellId, cultureId, priority: totalCost});
queue.push({cellId: neibCellId, cultureId, priority: totalCost}, totalCost);
}
});
}