Save all generated chunks instead of only chunks that were changed

This commit is contained in:
2026-10-11 02:02:01 -03:00
parent 44a39bf8ec
commit 5a59a63862
17 changed files with 644 additions and 314 deletions
+12 -2
View File
@@ -3,9 +3,12 @@ export class LruMap<K, V> {
#map = new Map<K, V>();
#newest: K | undefined;
readonly max_size: number;
// called with what's forgotten for being the least recently used
#on_evict?: (key: K, value: V) => void;
constructor(max_size: number) {
constructor(max_size: number, on_evict?: (key: K, value: V) => void) {
this.max_size = max_size;
this.#on_evict = on_evict;
}
get(key: K): V | undefined {
@@ -26,7 +29,9 @@ export class LruMap<K, V> {
this.#map.delete(key);
this.#map.set(key, value);
if (this.#map.size > this.max_size) {
this.#map.delete(this.#map.keys().next().value!);
const [oldest, value] = this.#map.entries().next().value!;
this.#map.delete(oldest);
this.#on_evict?.(oldest, value);
}
}
@@ -35,6 +40,11 @@ export class LruMap<K, V> {
return this.#map.has(key);
}
// get without counting as a use
peek(key: K): V | undefined {
return this.#map.get(key);
}
delete(key: K) {
this.#map.delete(key);
}