-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutilities.ts
58 lines (46 loc) · 1.03 KB
/
utilities.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Advent of Code Toolbox
// TODO add all map functionality to class
export class GridMap {
_map: Map<string, number>;
constructor() {
// TODO take in array and initialize
this._map = new Map();
}
set(point: Array<number>, value: number) {
const key = point.join(",");
this._map.set(key, value);
return this;
}
get(point: Array<number>): number | undefined {
const key = point.join(",");
return this._map.get(key);
}
has(point: Array<number>): boolean {
const key = point.join(",");
return this._map.has(key);
}
entries() {
return this._map.entries();
}
}
export class GridSet {
// todo copy set methods and return values
_set: Set<string>;
constructor() {
this._set = new Set();
}
add(item: number[]) {
const key = item.join(",");
this._set.add(key);
}
has(item: number[]): boolean {
const key = item.join(",");
return this._set.has(key);
}
entries() {
return this._set.entries();
}
get size(): number {
return this._set.size;
}
}