-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathDoubleDict.js
More file actions
28 lines (23 loc) · 775 Bytes
/
DoubleDict.js
File metadata and controls
28 lines (23 loc) · 775 Bytes
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
/* Copyright (c) 2012-2022 The ANTLR Project Contributors. All rights reserved.
* Use is of this file is governed by the BSD 3-clause license that
* can be found in the LICENSE.txt file in the project root.
*/
import HashMap from "../misc/HashMap.js";
export default class DoubleDict {
constructor(defaultMapCtor) {
this.defaultMapCtor = defaultMapCtor || HashMap;
this.cacheMap = new this.defaultMapCtor();
}
get(a, b) {
let d = this.cacheMap.get(a) || null;
return d === null ? null : (d.get(b) || null);
}
set(a, b, o) {
let d = this.cacheMap.get(a) || null;
if (d === null) {
d = new this.defaultMapCtor();
this.cacheMap.set(a, d);
}
d.set(b, o);
}
}