mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2026-02-05 01:51:23 +01:00
36 lines
474 B
JavaScript
36 lines
474 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;
|
|
|