Browse Source

add LRUCache.remove

dsehnal 1 year ago
parent
commit
e231fbf3d7
2 changed files with 11 additions and 1 deletions
  1. 1 0
      CHANGELOG.md
  2. 10 1
      src/mol-util/lru-cache.ts

+ 1 - 0
CHANGELOG.md

@@ -16,6 +16,7 @@ Note that since we don't clearly distinguish between a public and private interf
     - Pull position and group from texture
 - Add `Euler` math primitive
 - Add stride option to element sphere & point visuals
+- Add `LRUCache.remove`
 
 ## [v3.37.1] - 2023-06-20
 

+ 10 - 1
src/mol-util/lru-cache.ts

@@ -1,6 +1,6 @@
 
 /**
- * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2019-23 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * Adapted from LiteMol.
  * @author David Sehnal <david.sehnal@gmail.com>
@@ -53,4 +53,13 @@ namespace LRUCache {
         cache.entries.addLast(entry(key, data));
         return removed;
     }
+
+    export function remove<T>(cache: LRUCache<T>, key: string) {
+        for (let e = cache.entries.first; e; e = e.next) {
+            if (e.value.key === key) {
+                cache.entries.remove(e);
+                break;
+            }
+        }
+    }
 }