MCPcopy Create free account
hub / github.com/block/buzz / trimMapToSize

Function trimMapToSize

desktop/src/shared/lib/trimMapToSize.ts:6–15  ·  view source on GitHub ↗
(map: Map<K, V>, maxSize: number)

Source from the content-addressed store, hash-verified

4 * first keys are the oldest.
5 */
6export function trimMapToSize<K, V>(map: Map<K, V>, maxSize: number): void {
7 if (map.size <= maxSize) return;
8 const excess = map.size - maxSize;
9 let removed = 0;
10 for (const key of map.keys()) {
11 if (removed >= excess) break;
12 map.delete(key);
13 removed++;
14 }
15}

Callers 3

useMentionsFunction · 0.90
useDraftsFunction · 0.90
useBackForwardControlsFunction · 0.90

Calls 2

keysMethod · 0.80
deleteMethod · 0.45

Tested by

no test coverage detected