mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-19 02:21:24 +01:00
29 lines
No EOL
466 B
JavaScript
29 lines
No EOL
466 B
JavaScript
/**
|
|
* @template T
|
|
*/
|
|
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();
|
|
}
|
|
}
|
|
|
|
globalThis.PriorityQueue = PriorityQueue; |