export function pruneMapToMaxSize(map: Map, maxSize: number): void { const limit = Math.max(0, Math.floor(maxSize)); if (limit <= 0) { map.clear(); return; } while (map.size > limit) { const oldest = map.keys().next(); if (oldest.done) { break; } map.delete(oldest.value); } }