diff options
Diffstat (limited to 'utils')
-rw-r--r-- | utils/jsonds.ts | 14 | ||||
-rw-r--r-- | utils/point2d.ts | 2 |
2 files changed, 9 insertions, 7 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); diff --git a/utils/point2d.ts b/utils/point2d.ts index 45bee2e..1c968a0 100644 --- a/utils/point2d.ts +++ b/utils/point2d.ts @@ -27,5 +27,3 @@ export const neighbors = (p1: Vec2, max: Vec2) => { } return ns; }; - -export const; |