mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-19 10:31:24 +01:00
added version to priority-queue and moved to utils to follow dom loading pattern
This commit is contained in:
parent
ae9d4d9967
commit
8a80faffa5
2 changed files with 2 additions and 1 deletions
29
utils/priority-queue.js
Normal file
29
utils/priority-queue.js
Normal 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;
|
||||
Loading…
Add table
Add a link
Reference in a new issue