mirror of
https://github.com/immich-app/immich.git
synced 2025-12-20 01:11:46 +03:00
* Squashed * Change strategy - now pre-measure buckets offscreen, so don't need to worry about sub-bucket scroll preservation * Reduce jank on scroll, delay DOM updates until after scroll * css opt, log measure time * Trickle out queue while scrolling, flush when stopped * yay * Cleanup cleanup... * everybody... * everywhere... * Clean up cleanup! * Everybody do their share * CLEANUP! * package-lock ? * dynamic measure, todo * Fix web test * type lint * fix e2e * e2e test * Better scrollbar * Tuning, and more tunables * Tunable tweaks, more tunables * Scrollbar dots and viewport events * lint * Tweaked tunnables, use requestIdleCallback for garbage tasks, bug fixes * New tunables, and don't update url by default * Bug fixes * Bug fix, with debug * Fix flickr, fix graybox bug, reduced debug * Refactor/cleanup * Fix * naming * Final cleanup * review comment * Forgot to update this after naming change * scrubber works, with debug * cleanup * Rename scrollbar to scrubber * rename to * left over rename and change to previous album bar * bugfix addassets, comments * missing destroy(), cleanup --------- Co-authored-by: Alex <alex.tran1502@gmail.com>
51 lines
1.1 KiB
TypeScript
51 lines
1.1 KiB
TypeScript
export class KeyedPriorityQueue<K, T> {
|
|
private items: { key: K; value: T; priority: number }[] = [];
|
|
private set: Set<K> = new Set();
|
|
|
|
clear() {
|
|
this.items = [];
|
|
this.set.clear();
|
|
}
|
|
|
|
remove(key: K) {
|
|
const removed = this.set.delete(key);
|
|
if (removed) {
|
|
const idx = this.items.findIndex((i) => i.key === key);
|
|
if (idx >= 0) {
|
|
this.items.splice(idx, 1);
|
|
}
|
|
}
|
|
return removed;
|
|
}
|
|
|
|
push(key: K, value: T, priority: number) {
|
|
if (this.set.has(key)) {
|
|
return this.length;
|
|
}
|
|
for (let i = 0; i < this.items.length; i++) {
|
|
if (this.items[i].priority > priority) {
|
|
this.set.add(key);
|
|
this.items.splice(i, 0, { key, value, priority });
|
|
return this.length;
|
|
}
|
|
}
|
|
this.set.add(key);
|
|
return this.items.push({ key, value, priority });
|
|
}
|
|
|
|
shift() {
|
|
let item = this.items.shift();
|
|
while (item) {
|
|
if (this.set.has(item.key)) {
|
|
this.set.delete(item.key);
|
|
return item;
|
|
}
|
|
item = this.items.shift();
|
|
}
|
|
}
|
|
|
|
get length() {
|
|
return this.set.size;
|
|
}
|
|
}
|