1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.InternMap = void 0;
|
4 | function internGet({ map, initKey }, value) {
|
5 | const key = initKey(value);
|
6 | return map.has(key) ? map.get(key) : value;
|
7 | }
|
8 | function internSet({ map, initKey }, value) {
|
9 | const key = initKey(value);
|
10 | if (map.has(key))
|
11 | return map.get(key);
|
12 | map.set(key, value);
|
13 | return value;
|
14 | }
|
15 | function internDelete({ map, initKey }, value) {
|
16 | const key = initKey(value);
|
17 | if (map.has(key)) {
|
18 | value = map.get(key);
|
19 | map.delete(key);
|
20 | }
|
21 | return value;
|
22 | }
|
23 | function keyof(value) {
|
24 | return typeof value === 'object' ? value.valueOf() : value;
|
25 | }
|
26 |
|
27 |
|
28 |
|
29 | class InternMap extends Map {
|
30 | constructor(entries) {
|
31 | super();
|
32 | this.map = new Map();
|
33 | this.initKey = keyof;
|
34 | if (entries !== null) {
|
35 | for (const [key, value] of entries) {
|
36 | this.set(key, value);
|
37 | }
|
38 | }
|
39 | }
|
40 | get(key) {
|
41 | return super.get(internGet({ map: this.map, initKey: this.initKey }, key));
|
42 | }
|
43 | has(key) {
|
44 | return super.has(internGet({ map: this.map, initKey: this.initKey }, key));
|
45 | }
|
46 | set(key, value) {
|
47 | return super.set(internSet({ map: this.map, initKey: this.initKey }, key), value);
|
48 | }
|
49 | delete(key) {
|
50 | return super.delete(internDelete({ map: this.map, initKey: this.initKey }, key));
|
51 | }
|
52 | }
|
53 | exports.InternMap = InternMap;
|
54 |
|
\ | No newline at end of file |