export class Counter { private readonly count = new Map(); add(key: string, amount: number): void { this.count.set(key, this.get(key) + amount); } get(key: string): number { return this.count.get(key) ?? 0; } update(other: Counter): void { for (const [key, amount] of other.entries()) this.add(key, amount); } entries(): IterableIterator<[string, number]> { return this.count.entries(); } }