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

This commit is contained in:
RyanGuild 2024-10-22 15:41:21 -04:00
parent ae9d4d9967
commit 8a80faffa5
2 changed files with 2 additions and 1 deletions

29
utils/priority-queue.js Normal file
View file

@ -0,0 +1,29 @@
/**
* @template T
*/
export class PriorityQueue extends Array {
/**
* @param {{comparator: (a:T, B:T) => number | boolean}} options
*/
constructor({comparator}) {
super();
}
/**
* @param {T} value
*/
enqueue(value) {
this.push(value);
this.sort(comparator);
}
/**
* @returns {T}
*/
dequeue() {
return this.shift();
}
}
export default PriorityQueue;
globalThis.PriorityQueue = PriorityQueue;