mirror of
https://github.com/immich-app/immich.git
synced 2025-12-21 01:11:16 +03:00
22 lines
474 B
TypeScript
22 lines
474 B
TypeScript
|
|
export class PriorityQueue<T> {
|
||
|
|
private items: { value: T; priority: number }[] = [];
|
||
|
|
|
||
|
|
push(value: T, priority: number) {
|
||
|
|
for (let i = 0; i < this.items.length; i++) {
|
||
|
|
if (this.items[i].priority > priority) {
|
||
|
|
this.items.splice(i, 0, { value, priority });
|
||
|
|
return this.length;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return this.items.push({ value, priority });
|
||
|
|
}
|
||
|
|
|
||
|
|
shift() {
|
||
|
|
return this.items.shift();
|
||
|
|
}
|
||
|
|
|
||
|
|
get length() {
|
||
|
|
return this.items.length;
|
||
|
|
}
|
||
|
|
}
|