summaryrefslogtreecommitdiff
path: root/utils/jsonds.ts
diff options
context:
space:
mode:
authorElizabeth Hunt <elizabeth.hunt@simponic.xyz>2023-12-05 20:42:06 -0700
committerElizabeth Hunt <elizabeth.hunt@simponic.xyz>2023-12-05 20:42:06 -0700
commitc874f28eec621a0fe8c86a5e586ac34b43acca6e (patch)
treefacdacb5c19d74c06cea3e7faa01c921395f7135 /utils/jsonds.ts
parent97095a87955191f273d068889e8e62266472121b (diff)
downloadaoc-c874f28eec621a0fe8c86a5e586ac34b43acca6e.tar.gz
aoc-c874f28eec621a0fe8c86a5e586ac34b43acca6e.zip
composition of piecewise functions (jesus)
Diffstat (limited to 'utils/jsonds.ts')
-rw-r--r--utils/jsonds.ts14
1 files changed, 9 insertions, 5 deletions
diff --git a/utils/jsonds.ts b/utils/jsonds.ts
index c717232..657c787 100644
--- a/utils/jsonds.ts
+++ b/utils/jsonds.ts
@@ -29,19 +29,19 @@ export class JSONSet<T extends Object> {
}
}
-export class JSONHashMap<T extends Object> {
- private map: Map<string, T>;
+export class JSONHashMap<T extends Object, R extends Object> {
+ private map: Map<string, R>;
constructor() {
- this.map = new Map<string, T>();
+ this.map = new Map<string, R>();
}
- set(key: T, value: T): void {
+ set(key: T, value: R): void {
const keyJson = JSON.stringify(key, Object.keys(key).sort());
this.map.set(keyJson, value);
}
- get(key: T): T | undefined {
+ get(key: T): R | undefined {
const keyJson = JSON.stringify(key, Object.keys(key).sort());
return this.map.get(keyJson);
}
@@ -51,6 +51,10 @@ export class JSONHashMap<T extends Object> {
return this.map.has(keyJson);
}
+ keys(): T[] {
+ return Array.from(this.map.keys()).map((x) => JSON.parse(x) as T);
+ }
+
delete(key: T): boolean {
const keyJson = JSON.stringify(key, Object.keys(key).sort());
return this.map.delete(keyJson);