refactor: fix

This commit is contained in:
手瓜一十雪 committed 2024-11-14 11:24:00 +08:00
1 parent fc5889b99c
commit 4969ad0ec8
7 files changed
+54 -48

No files matched your search

+9
View File
@@ -30,4 +30,13 @@ export class LRUCache<K, V> {
}
this.cache.set(key, value);
}
public resetCapacity(newCapacity: number): void {
this.capacity = newCapacity;
while (this.cache.size > this.capacity) {
const firstKey = this.cache.keys().next().value;
if (firstKey !== undefined) {
this.cache.delete(firstKey);
}
}
}
}