export class JSONSet { constructor(private readonly items: Set = new Set()) {} public add(item: T): void { const itemJson = JSON.stringify(item, Object.keys(item).sort()); this.items.add(itemJson); } public has(item: T): boolean { const itemJson = JSON.stringify(item, Object.keys(item).sort()); return this.items.has(itemJson); } public delete(item: T): boolean { const itemJson = JSON.stringify(item, Object.keys(item).sort()); return this.items.delete(itemJson); } public clear(): void { this.items.clear(); } public size(): number { return this.items.size; } } export class JSONHashMap { constructor(private readonly map: Map = new Map()) {} public set(key: T, value: R): void { const keyJson = JSON.stringify(key, Object.keys(key).sort()); this.map.set(keyJson, value); } public get(key: T): R | undefined { const keyJson = JSON.stringify(key, Object.keys(key).sort()); return this.map.get(keyJson); } public has(key: T): boolean { const keyJson = JSON.stringify(key, Object.keys(key).sort()); return this.map.has(keyJson); } public keys(): T[] { return Array.from(this.map.keys()).map((x) => JSON.parse(x) as T); } public delete(key: T): boolean { const keyJson = JSON.stringify(key, Object.keys(key).sort()); return this.map.delete(keyJson); } public clear(): void { this.map.clear(); } public size(): number { return this.map.size; } }