@blackglory/structures 0.5.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/README.md +14 -6
  2. package/dist/es2015/index.min.mjs +2 -2
  3. package/dist/es2015/index.min.mjs.map +1 -1
  4. package/dist/es2015/index.mjs +132 -153
  5. package/dist/es2015/index.mjs.map +1 -1
  6. package/dist/es2015/index.umd.js +132 -153
  7. package/dist/es2015/index.umd.js.map +1 -1
  8. package/dist/es2015/index.umd.min.js +2 -2
  9. package/dist/es2015/index.umd.min.js.map +1 -1
  10. package/dist/es2018/index.min.mjs +2 -2
  11. package/dist/es2018/index.min.mjs.map +1 -1
  12. package/dist/es2018/index.mjs +132 -153
  13. package/dist/es2018/index.mjs.map +1 -1
  14. package/dist/es2018/index.umd.js +132 -153
  15. package/dist/es2018/index.umd.js.map +1 -1
  16. package/dist/es2018/index.umd.min.js +2 -2
  17. package/dist/es2018/index.umd.min.js.map +1 -1
  18. package/lib/es2015/box.d.ts +1 -1
  19. package/lib/es2015/box.js +3 -17
  20. package/lib/es2015/box.js.map +1 -1
  21. package/lib/es2015/emitter.d.ts +4 -4
  22. package/lib/es2015/emitter.js +26 -22
  23. package/lib/es2015/emitter.js.map +1 -1
  24. package/lib/es2015/expirable-map.d.ts +2 -1
  25. package/lib/es2015/expirable-map.js +14 -27
  26. package/lib/es2015/expirable-map.js.map +1 -1
  27. package/lib/es2015/finite-state-machine.d.ts +1 -1
  28. package/lib/es2015/finite-state-machine.js +4 -18
  29. package/lib/es2015/finite-state-machine.js.map +1 -1
  30. package/lib/es2015/hash-map.d.ts +1 -1
  31. package/lib/es2015/hash-map.js +8 -14
  32. package/lib/es2015/hash-map.js.map +1 -1
  33. package/lib/es2015/hash-set.d.ts +1 -1
  34. package/lib/es2015/hash-set.js +9 -15
  35. package/lib/es2015/hash-set.js.map +1 -1
  36. package/lib/es2015/lru-map.d.ts +2 -1
  37. package/lib/es2015/lru-map.js +15 -28
  38. package/lib/es2015/lru-map.js.map +1 -1
  39. package/lib/es2015/queue.d.ts +1 -1
  40. package/lib/es2015/queue.js +8 -14
  41. package/lib/es2015/queue.js.map +1 -1
  42. package/lib/es2015/tlru-map.d.ts +4 -2
  43. package/lib/es2015/tlru-map.js +21 -35
  44. package/lib/es2015/tlru-map.js.map +1 -1
  45. package/lib/es2015/trie-map.d.ts +4 -1
  46. package/lib/es2015/trie-map.js +25 -12
  47. package/lib/es2015/trie-map.js.map +1 -1
  48. package/lib/es2018/box.d.ts +1 -1
  49. package/lib/es2018/box.js +3 -17
  50. package/lib/es2018/box.js.map +1 -1
  51. package/lib/es2018/emitter.d.ts +4 -4
  52. package/lib/es2018/emitter.js +26 -22
  53. package/lib/es2018/emitter.js.map +1 -1
  54. package/lib/es2018/expirable-map.d.ts +2 -1
  55. package/lib/es2018/expirable-map.js +14 -27
  56. package/lib/es2018/expirable-map.js.map +1 -1
  57. package/lib/es2018/finite-state-machine.d.ts +1 -1
  58. package/lib/es2018/finite-state-machine.js +4 -18
  59. package/lib/es2018/finite-state-machine.js.map +1 -1
  60. package/lib/es2018/hash-map.d.ts +1 -1
  61. package/lib/es2018/hash-map.js +8 -14
  62. package/lib/es2018/hash-map.js.map +1 -1
  63. package/lib/es2018/hash-set.d.ts +1 -1
  64. package/lib/es2018/hash-set.js +9 -15
  65. package/lib/es2018/hash-set.js.map +1 -1
  66. package/lib/es2018/lru-map.d.ts +2 -1
  67. package/lib/es2018/lru-map.js +15 -28
  68. package/lib/es2018/lru-map.js.map +1 -1
  69. package/lib/es2018/queue.d.ts +1 -1
  70. package/lib/es2018/queue.js +8 -14
  71. package/lib/es2018/queue.js.map +1 -1
  72. package/lib/es2018/tlru-map.d.ts +4 -2
  73. package/lib/es2018/tlru-map.js +21 -35
  74. package/lib/es2018/tlru-map.js.map +1 -1
  75. package/lib/es2018/trie-map.d.ts +4 -1
  76. package/lib/es2018/trie-map.js +25 -12
  77. package/lib/es2018/trie-map.js.map +1 -1
  78. package/package.json +13 -13
@@ -1,45 +1,14 @@
1
- /******************************************************************************
2
- Copyright (c) Microsoft Corporation.
3
-
4
- Permission to use, copy, modify, and/or distribute this software for any
5
- purpose with or without fee is hereby granted.
6
-
7
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
- PERFORMANCE OF THIS SOFTWARE.
14
- ***************************************************************************** */
15
-
16
- function __classPrivateFieldGet(receiver, state, kind, f) {
17
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
18
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
19
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
20
- }
21
-
22
- function __classPrivateFieldSet(receiver, state, value, kind, f) {
23
- if (kind === "m") throw new TypeError("Private method is not writable");
24
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
25
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
26
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
27
- }
28
-
29
- var _Box_value;
30
1
  class Box {
31
2
  constructor(value) {
32
- _Box_value.set(this, void 0);
33
- __classPrivateFieldSet(this, _Box_value, value, "f");
3
+ this.value = value;
34
4
  }
35
5
  set(value) {
36
- __classPrivateFieldSet(this, _Box_value, value, "f");
6
+ this.value = value;
37
7
  }
38
8
  get() {
39
- return __classPrivateFieldGet(this, _Box_value, "f");
9
+ return this.value;
40
10
  }
41
11
  }
42
- _Box_value = new WeakMap();
43
12
 
44
13
  function convertConsToArray([value, next]) {
45
14
  if (next === null)
@@ -50,127 +19,130 @@ function convertArrayToCons([value, ...next]) {
50
19
  return [value, next.length ? convertArrayToCons(next) : null];
51
20
  }
52
21
 
53
- var _Emitter_map;
54
22
  class Emitter {
55
23
  constructor() {
56
- _Emitter_map.set(this, new Map());
24
+ this.map = new Map();
57
25
  }
58
- get [(_Emitter_map = new WeakMap(), Symbol.toStringTag)]() {
26
+ get [Symbol.toStringTag]() {
59
27
  return this.constructor.name;
60
28
  }
61
- /**
62
- * The same handler will only be registered once.
63
- */
64
- on(event, handler) {
65
- if (!__classPrivateFieldGet(this, _Emitter_map, "f").has(event)) {
66
- __classPrivateFieldGet(this, _Emitter_map, "f").set(event, new Set());
29
+ on(event, listener) {
30
+ if (!this.map.has(event)) {
31
+ this.map.set(event, new Set());
67
32
  }
68
- const set = __classPrivateFieldGet(this, _Emitter_map, "f").get(event);
33
+ const set = this.map.get(event);
69
34
  set.add(handler);
70
- }
71
- off(event, handler) {
72
- if (!__classPrivateFieldGet(this, _Emitter_map, "f").has(event))
73
- return;
74
- const handlers = __classPrivateFieldGet(this, _Emitter_map, "f").get(event);
75
- handlers.delete(handler);
76
- if (handlers.size === 0) {
77
- __classPrivateFieldGet(this, _Emitter_map, "f").delete(event);
35
+ return () => {
36
+ if (!this.map.has(event))
37
+ return;
38
+ const handlers = this.map.get(event);
39
+ handlers.delete(handler);
40
+ if (handlers.size === 0) {
41
+ this.map.delete(event);
42
+ }
43
+ };
44
+ function handler(...args) {
45
+ listener(...args);
78
46
  }
79
47
  }
48
+ once(event, listener) {
49
+ const removeListener = this.on(event, (...args) => {
50
+ listener(...args);
51
+ removeListener();
52
+ });
53
+ return removeListener;
54
+ }
80
55
  emit(event, ...args) {
81
- if (!__classPrivateFieldGet(this, _Emitter_map, "f").has(event))
56
+ if (!this.map.has(event))
82
57
  return;
83
- __classPrivateFieldGet(this, _Emitter_map, "f").get(event).forEach(cb => cb(...args));
58
+ this.map.get(event).forEach(cb => cb(...args));
84
59
  }
85
60
  }
86
61
 
87
- var _HashMap_map;
88
62
  class HashMap {
89
63
  constructor(hash) {
90
64
  this.hash = hash;
91
- _HashMap_map.set(this, new Map());
65
+ this.map = new Map();
92
66
  }
93
- get [(_HashMap_map = new WeakMap(), Symbol.toStringTag)]() {
67
+ get [Symbol.toStringTag]() {
94
68
  return this.constructor.name;
95
69
  }
96
70
  get size() {
97
- return __classPrivateFieldGet(this, _HashMap_map, "f").size;
71
+ return this.map.size;
98
72
  }
99
73
  set(key, value) {
100
- __classPrivateFieldGet(this, _HashMap_map, "f").set(this.hash(key), value);
74
+ this.map.set(this.hash(key), value);
101
75
  return this;
102
76
  }
103
77
  has(key) {
104
- return __classPrivateFieldGet(this, _HashMap_map, "f").has(this.hash(key));
78
+ return this.map.has(this.hash(key));
105
79
  }
106
80
  get(key) {
107
- return __classPrivateFieldGet(this, _HashMap_map, "f").get(this.hash(key));
81
+ return this.map.get(this.hash(key));
108
82
  }
109
83
  delete(key) {
110
- return __classPrivateFieldGet(this, _HashMap_map, "f").delete(this.hash(key));
84
+ return this.map.delete(this.hash(key));
111
85
  }
112
86
  clear() {
113
- __classPrivateFieldGet(this, _HashMap_map, "f").clear();
87
+ this.map.clear();
114
88
  }
115
89
  }
116
90
 
117
- var _HashSet_map;
118
91
  class HashSet {
119
92
  constructor(hash) {
120
93
  this.hash = hash;
121
- _HashSet_map.set(this, new Map());
94
+ this.map = new Map();
122
95
  }
123
- get [(_HashSet_map = new WeakMap(), Symbol.toStringTag)]() {
96
+ get [Symbol.toStringTag]() {
124
97
  return this.constructor.name;
125
98
  }
126
99
  get size() {
127
- return __classPrivateFieldGet(this, _HashSet_map, "f").size;
100
+ return this.map.size;
128
101
  }
129
102
  [Symbol.iterator]() {
130
- return __classPrivateFieldGet(this, _HashSet_map, "f").values();
103
+ return this.map.values();
131
104
  }
132
105
  add(value) {
133
- __classPrivateFieldGet(this, _HashSet_map, "f").set(this.hash(value), value);
106
+ this.map.set(this.hash(value), value);
134
107
  return this;
135
108
  }
136
109
  delete(value) {
137
- return __classPrivateFieldGet(this, _HashSet_map, "f").delete(this.hash(value));
110
+ return this.map.delete(this.hash(value));
138
111
  }
139
112
  has(value) {
140
- return __classPrivateFieldGet(this, _HashSet_map, "f").has(this.hash(value));
113
+ return this.map.has(this.hash(value));
141
114
  }
142
115
  clear() {
143
- __classPrivateFieldGet(this, _HashSet_map, "f").clear();
116
+ this.map.clear();
144
117
  }
145
118
  values() {
146
- return __classPrivateFieldGet(this, _HashSet_map, "f").values();
119
+ return this.map.values();
147
120
  }
148
121
  }
149
122
 
150
- var _Queue_items;
151
123
  class Queue {
152
124
  constructor() {
153
- _Queue_items.set(this, []);
125
+ this.items = [];
154
126
  }
155
- get [(_Queue_items = new WeakMap(), Symbol.toStringTag)]() {
127
+ get [Symbol.toStringTag]() {
156
128
  return this.constructor.name;
157
129
  }
158
130
  get size() {
159
- return __classPrivateFieldGet(this, _Queue_items, "f").length;
131
+ return this.items.length;
160
132
  }
161
133
  empty() {
162
- __classPrivateFieldGet(this, _Queue_items, "f").length = 0;
134
+ this.items.length = 0;
163
135
  }
164
136
  enqueue(...items) {
165
- __classPrivateFieldGet(this, _Queue_items, "f").push(...items);
137
+ this.items.push(...items);
166
138
  }
167
139
  dequeue() {
168
- return __classPrivateFieldGet(this, _Queue_items, "f").shift();
140
+ return this.items.shift();
169
141
  }
170
142
  remove(item) {
171
143
  let index;
172
- while ((index = __classPrivateFieldGet(this, _Queue_items, "f").indexOf(item)) >= 0) {
173
- __classPrivateFieldGet(this, _Queue_items, "f").splice(index, 1);
144
+ while ((index = this.items.indexOf(item)) >= 0) {
145
+ this.items.splice(index, 1);
174
146
  }
175
147
  }
176
148
  }
@@ -7116,61 +7088,59 @@ countAsync$1.countAsync = countAsync;
7116
7088
 
7117
7089
  } (es2018$4));
7118
7090
 
7119
- var _LRUMap_limit, _LRUMap_map;
7120
7091
  class LRUMap {
7121
7092
  constructor(limit) {
7122
- _LRUMap_limit.set(this, void 0);
7123
- _LRUMap_map.set(this, new Map());
7093
+ this.map = new Map();
7124
7094
  es2018$d.assert(Number.isInteger(limit), 'The parameter limit must be an integer');
7125
7095
  es2018$d.assert(limit > 0, 'The parameter limit must be a positive value');
7126
- __classPrivateFieldSet(this, _LRUMap_limit, limit, "f");
7096
+ this.limit = limit;
7127
7097
  }
7128
- get [(_LRUMap_limit = new WeakMap(), _LRUMap_map = new WeakMap(), Symbol.toStringTag)]() {
7098
+ get [Symbol.toStringTag]() {
7129
7099
  return this.constructor.name;
7130
7100
  }
7131
7101
  get size() {
7132
- return __classPrivateFieldGet(this, _LRUMap_map, "f").size;
7102
+ return this.map.size;
7133
7103
  }
7134
7104
  set(key, value) {
7135
- if (__classPrivateFieldGet(this, _LRUMap_map, "f").has(key)) {
7105
+ if (this.map.has(key)) {
7136
7106
  this.updateItem(key, value);
7137
7107
  }
7138
7108
  else {
7139
- if (__classPrivateFieldGet(this, _LRUMap_map, "f").size === __classPrivateFieldGet(this, _LRUMap_limit, "f")) {
7140
- __classPrivateFieldGet(this, _LRUMap_map, "f").delete(this.getColdestKey());
7109
+ if (this.map.size === this.limit) {
7110
+ this.map.delete(this.getColdestKey());
7141
7111
  }
7142
- __classPrivateFieldGet(this, _LRUMap_map, "f").set(key, value);
7112
+ this.map.set(key, value);
7143
7113
  }
7144
7114
  return this;
7145
7115
  }
7146
7116
  has(key) {
7147
- return __classPrivateFieldGet(this, _LRUMap_map, "f").has(key);
7117
+ return this.map.has(key);
7148
7118
  }
7149
7119
  get(key) {
7150
7120
  if (!this.has(key))
7151
7121
  return undefined;
7152
- const value = __classPrivateFieldGet(this, _LRUMap_map, "f").get(key);
7122
+ const value = this.map.get(key);
7153
7123
  this.updateItem(key, value);
7154
7124
  return value;
7155
7125
  }
7156
7126
  delete(key) {
7157
- return __classPrivateFieldGet(this, _LRUMap_map, "f").delete(key);
7127
+ return this.map.delete(key);
7158
7128
  }
7159
7129
  clear() {
7160
- __classPrivateFieldGet(this, _LRUMap_map, "f").clear();
7130
+ this.map.clear();
7161
7131
  }
7162
7132
  /**
7163
7133
  * Reinsert the item.
7164
7134
  */
7165
7135
  updateItem(key, value) {
7166
- __classPrivateFieldGet(this, _LRUMap_map, "f").delete(key);
7167
- __classPrivateFieldGet(this, _LRUMap_map, "f").set(key, value);
7136
+ this.map.delete(key);
7137
+ this.map.set(key, value);
7168
7138
  }
7169
7139
  /**
7170
7140
  * Return the earliest key inserted in the Map
7171
7141
  */
7172
7142
  getColdestKey() {
7173
- return es2018$4.first(__classPrivateFieldGet(this, _LRUMap_map, "f").keys());
7143
+ return es2018$4.first(this.map.keys());
7174
7144
  }
7175
7145
  }
7176
7146
 
@@ -7342,36 +7312,34 @@ setDynamicTimeoutLoop$1.setDynamicTimeoutLoop = setDynamicTimeoutLoop;
7342
7312
 
7343
7313
  } (es2018$1));
7344
7314
 
7345
- var _ExpirableMap_map, _ExpirableMap_cancelClearTimeout;
7346
7315
  class ExpirableMap {
7347
7316
  constructor() {
7348
- _ExpirableMap_map.set(this, new Map());
7349
- _ExpirableMap_cancelClearTimeout.set(this, void 0);
7317
+ this.map = new Map();
7350
7318
  /**
7351
7319
  * 按过期时间升序排列所有项目的元数据
7352
7320
  */
7353
7321
  this.itemMetadataSortedByExpirationTime = [];
7354
7322
  }
7355
- get [(_ExpirableMap_map = new WeakMap(), _ExpirableMap_cancelClearTimeout = new WeakMap(), Symbol.toStringTag)]() {
7323
+ get [Symbol.toStringTag]() {
7356
7324
  return this.constructor.name;
7357
7325
  }
7358
7326
  get size() {
7359
- return __classPrivateFieldGet(this, _ExpirableMap_map, "f").size;
7327
+ return this.map.size;
7360
7328
  }
7361
7329
  set(key, value, maxAge) {
7362
- __classPrivateFieldGet(this, _ExpirableMap_map, "f").set(key, value);
7330
+ this.map.set(key, value);
7363
7331
  this.removeItemMetadata(key);
7364
7332
  this.addItemMetadata(key, Date.now() + maxAge);
7365
7333
  return this;
7366
7334
  }
7367
7335
  has(key) {
7368
- return __classPrivateFieldGet(this, _ExpirableMap_map, "f").has(key);
7336
+ return this.map.has(key);
7369
7337
  }
7370
7338
  get(key) {
7371
- return __classPrivateFieldGet(this, _ExpirableMap_map, "f").get(key);
7339
+ return this.map.get(key);
7372
7340
  }
7373
7341
  delete(key) {
7374
- const exists = __classPrivateFieldGet(this, _ExpirableMap_map, "f").delete(key);
7342
+ const exists = this.map.delete(key);
7375
7343
  if (exists) {
7376
7344
  const index = this.itemMetadataSortedByExpirationTime.findIndex(x => x.key === key);
7377
7345
  this.itemMetadataSortedByExpirationTime.splice(index, 1);
@@ -7384,8 +7352,8 @@ class ExpirableMap {
7384
7352
  }
7385
7353
  clear() {
7386
7354
  var _a;
7387
- __classPrivateFieldGet(this, _ExpirableMap_map, "f").clear();
7388
- (_a = __classPrivateFieldGet(this, _ExpirableMap_cancelClearTimeout, "f")) === null || _a === void 0 ? void 0 : _a.call(this);
7355
+ this.map.clear();
7356
+ (_a = this.cancelClearTimeout) === null || _a === void 0 ? void 0 : _a.call(this);
7389
7357
  this.itemMetadataSortedByExpirationTime = [];
7390
7358
  }
7391
7359
  addItemMetadata(key, expirationTime) {
@@ -7422,11 +7390,11 @@ class ExpirableMap {
7422
7390
  const expiredItemKeys = indexOfFirstUnexpired >= 0
7423
7391
  ? this.itemMetadataSortedByExpirationTime.splice(0, indexOfFirstUnexpired)
7424
7392
  : this.itemMetadataSortedByExpirationTime.splice(0, this.itemMetadataSortedByExpirationTime.length);
7425
- expiredItemKeys.forEach(x => __classPrivateFieldGet(this, _ExpirableMap_map, "f").delete(x.key));
7393
+ expiredItemKeys.forEach(x => this.map.delete(x.key));
7426
7394
  }
7427
7395
  rescheduleClearTimeout() {
7428
7396
  var _a;
7429
- (_a = __classPrivateFieldGet(this, _ExpirableMap_cancelClearTimeout, "f")) === null || _a === void 0 ? void 0 : _a.call(this);
7397
+ (_a = this.cancelClearTimeout) === null || _a === void 0 ? void 0 : _a.call(this);
7430
7398
  if (this.itemMetadataSortedByExpirationTime.length > 0) {
7431
7399
  const item = this.itemMetadataSortedByExpirationTime[0];
7432
7400
  if (Number.isFinite(item.expirationTime)) {
@@ -7434,59 +7402,56 @@ class ExpirableMap {
7434
7402
  this.clearExpiredItems(Date.now());
7435
7403
  this.rescheduleClearTimeout();
7436
7404
  });
7437
- __classPrivateFieldSet(this, _ExpirableMap_cancelClearTimeout, () => {
7405
+ this.cancelClearTimeout = () => {
7438
7406
  cancel();
7439
- __classPrivateFieldSet(this, _ExpirableMap_cancelClearTimeout, undefined, "f");
7440
- }, "f");
7407
+ this.cancelClearTimeout = undefined;
7408
+ };
7441
7409
  }
7442
7410
  }
7443
7411
  }
7444
7412
  }
7445
7413
 
7446
- var _TLRUMap_limit, _TLRUMap_map, _TLRUMap_cancelClearTimeout;
7447
7414
  /**
7448
7415
  * TLRUMap = LRUMap + ExpirableMap
7449
7416
  */
7450
7417
  class TLRUMap {
7451
7418
  constructor(limit) {
7452
- _TLRUMap_limit.set(this, void 0);
7453
- _TLRUMap_map.set(this, new Map());
7454
- _TLRUMap_cancelClearTimeout.set(this, void 0);
7419
+ this.map = new Map();
7455
7420
  /**
7456
7421
  * 按过期时间升序排列所有项目的元数据
7457
7422
  */
7458
7423
  this.itemMetadataSortedByExpirationTime = [];
7459
7424
  es2018$d.assert(Number.isInteger(limit), 'The parameter limit must be an integer');
7460
7425
  es2018$d.assert(limit > 0, 'The parameter limit must be a positive value');
7461
- __classPrivateFieldSet(this, _TLRUMap_limit, limit, "f");
7426
+ this.limit = limit;
7462
7427
  }
7463
- get [(_TLRUMap_limit = new WeakMap(), _TLRUMap_map = new WeakMap(), _TLRUMap_cancelClearTimeout = new WeakMap(), Symbol.toStringTag)]() {
7428
+ get [Symbol.toStringTag]() {
7464
7429
  return this.constructor.name;
7465
7430
  }
7466
7431
  get size() {
7467
- return __classPrivateFieldGet(this, _TLRUMap_map, "f").size;
7432
+ return this.map.size;
7468
7433
  }
7469
7434
  set(key, value, maxAge) {
7470
- if (__classPrivateFieldGet(this, _TLRUMap_map, "f").has(key)) {
7435
+ if (this.map.has(key)) {
7471
7436
  this.updateItem(key, value);
7472
7437
  this.removeItemMetadata(key);
7473
7438
  this.addItemMetadata(key, Date.now() + maxAge);
7474
7439
  }
7475
7440
  else {
7476
- if (__classPrivateFieldGet(this, _TLRUMap_map, "f").size === __classPrivateFieldGet(this, _TLRUMap_limit, "f")) {
7477
- __classPrivateFieldGet(this, _TLRUMap_map, "f").delete(this.getColdestKey());
7441
+ if (this.map.size === this.limit) {
7442
+ this.map.delete(this.getColdestKey());
7478
7443
  }
7479
- __classPrivateFieldGet(this, _TLRUMap_map, "f").set(key, value);
7444
+ this.map.set(key, value);
7480
7445
  this.addItemMetadata(key, Date.now() + maxAge);
7481
7446
  }
7482
7447
  return this;
7483
7448
  }
7484
7449
  has(key) {
7485
- return __classPrivateFieldGet(this, _TLRUMap_map, "f").has(key);
7450
+ return this.map.has(key);
7486
7451
  }
7487
7452
  get(key) {
7488
7453
  if (this.has(key)) {
7489
- const value = __classPrivateFieldGet(this, _TLRUMap_map, "f").get(key);
7454
+ const value = this.map.get(key);
7490
7455
  this.updateItem(key, value);
7491
7456
  return value;
7492
7457
  }
@@ -7495,7 +7460,7 @@ class TLRUMap {
7495
7460
  }
7496
7461
  }
7497
7462
  delete(key) {
7498
- const result = __classPrivateFieldGet(this, _TLRUMap_map, "f").delete(key);
7463
+ const result = this.map.delete(key);
7499
7464
  if (result) {
7500
7465
  const index = this.itemMetadataSortedByExpirationTime.findIndex(x => x.key === key);
7501
7466
  this.itemMetadataSortedByExpirationTime.splice(index, 1);
@@ -7508,16 +7473,16 @@ class TLRUMap {
7508
7473
  }
7509
7474
  clear() {
7510
7475
  var _a;
7511
- __classPrivateFieldGet(this, _TLRUMap_map, "f").clear();
7512
- (_a = __classPrivateFieldGet(this, _TLRUMap_cancelClearTimeout, "f")) === null || _a === void 0 ? void 0 : _a.call(this);
7476
+ this.map.clear();
7477
+ (_a = this.cancelClearTimeout) === null || _a === void 0 ? void 0 : _a.call(this);
7513
7478
  this.itemMetadataSortedByExpirationTime = [];
7514
7479
  }
7515
7480
  /**
7516
7481
  * 重新插入项目, 这会使项目置于#map迭代器的末端.
7517
7482
  */
7518
7483
  updateItem(key, value) {
7519
- __classPrivateFieldGet(this, _TLRUMap_map, "f").delete(key);
7520
- __classPrivateFieldGet(this, _TLRUMap_map, "f").set(key, value);
7484
+ this.map.delete(key);
7485
+ this.map.set(key, value);
7521
7486
  }
7522
7487
  addItemMetadata(key, expirationTime) {
7523
7488
  for (let i = 0; i < this.itemMetadataSortedByExpirationTime.length; i++) {
@@ -7553,11 +7518,11 @@ class TLRUMap {
7553
7518
  const expiredItemKeys = indexOfFirstUnexpiredItem >= 0
7554
7519
  ? this.itemMetadataSortedByExpirationTime.splice(0, indexOfFirstUnexpiredItem)
7555
7520
  : this.itemMetadataSortedByExpirationTime.splice(0, this.itemMetadataSortedByExpirationTime.length);
7556
- expiredItemKeys.forEach(x => __classPrivateFieldGet(this, _TLRUMap_map, "f").delete(x.key));
7521
+ expiredItemKeys.forEach(x => this.map.delete(x.key));
7557
7522
  }
7558
7523
  rescheduleClearTimeout() {
7559
7524
  var _a;
7560
- (_a = __classPrivateFieldGet(this, _TLRUMap_cancelClearTimeout, "f")) === null || _a === void 0 ? void 0 : _a.call(this);
7525
+ (_a = this.cancelClearTimeout) === null || _a === void 0 ? void 0 : _a.call(this);
7561
7526
  if (this.itemMetadataSortedByExpirationTime.length > 0) {
7562
7527
  const item = this.itemMetadataSortedByExpirationTime[0];
7563
7528
  if (Number.isFinite(item.expirationTime)) {
@@ -7565,10 +7530,10 @@ class TLRUMap {
7565
7530
  this.clearExpiredItems(Date.now());
7566
7531
  this.rescheduleClearTimeout();
7567
7532
  });
7568
- __classPrivateFieldSet(this, _TLRUMap_cancelClearTimeout, () => {
7533
+ this.cancelClearTimeout = () => {
7569
7534
  cancel();
7570
- __classPrivateFieldSet(this, _TLRUMap_cancelClearTimeout, undefined, "f");
7571
- }, "f");
7535
+ this.cancelClearTimeout = undefined;
7536
+ };
7572
7537
  }
7573
7538
  }
7574
7539
  }
@@ -7576,11 +7541,10 @@ class TLRUMap {
7576
7541
  * Return the earliest key inserted in the Map
7577
7542
  */
7578
7543
  getColdestKey() {
7579
- return es2018$4.first(__classPrivateFieldGet(this, _TLRUMap_map, "f").keys());
7544
+ return es2018$4.first(this.map.keys());
7580
7545
  }
7581
7546
  }
7582
7547
 
7583
- var _TrieMap_root;
7584
7548
  class TrieNode {
7585
7549
  constructor(value) {
7586
7550
  this.value = value;
@@ -7589,13 +7553,31 @@ class TrieNode {
7589
7553
  }
7590
7554
  class TrieMap {
7591
7555
  constructor() {
7592
- _TrieMap_root.set(this, new TrieNode());
7556
+ this.root = new TrieNode();
7593
7557
  }
7594
- get [(_TrieMap_root = new WeakMap(), Symbol.toStringTag)]() {
7558
+ get [Symbol.toStringTag]() {
7595
7559
  return this.constructor.name;
7596
7560
  }
7561
+ *entries() {
7562
+ yield* dfs(this.root, []);
7563
+ function* dfs(node, paths) {
7564
+ for (const [path, childNode] of node.children) {
7565
+ const newPaths = [...paths, path];
7566
+ if (es2018$2.isntUndefined(childNode.value)) {
7567
+ yield [newPaths, childNode.value];
7568
+ }
7569
+ yield* dfs(childNode, newPaths);
7570
+ }
7571
+ }
7572
+ }
7573
+ keys() {
7574
+ return es2018$4.map(this.entries(), ([key]) => key);
7575
+ }
7576
+ values() {
7577
+ return es2018$4.map(this.entries(), ([_, value]) => value);
7578
+ }
7597
7579
  set(key, value) {
7598
- let node = __classPrivateFieldGet(this, _TrieMap_root, "f");
7580
+ let node = this.root;
7599
7581
  for (const part of key) {
7600
7582
  if (!node.children.has(part)) {
7601
7583
  node.children.set(part, new TrieNode());
@@ -7606,7 +7588,7 @@ class TrieMap {
7606
7588
  return this;
7607
7589
  }
7608
7590
  has(key) {
7609
- let node = __classPrivateFieldGet(this, _TrieMap_root, "f");
7591
+ let node = this.root;
7610
7592
  for (const part of key) {
7611
7593
  if (node.children.has(part)) {
7612
7594
  node = node.children.get(part);
@@ -7618,7 +7600,7 @@ class TrieMap {
7618
7600
  return node.value !== undefined;
7619
7601
  }
7620
7602
  get(key) {
7621
- let node = __classPrivateFieldGet(this, _TrieMap_root, "f");
7603
+ let node = this.root;
7622
7604
  for (const part of key) {
7623
7605
  if (node.children.has(part)) {
7624
7606
  node = node.children.get(part);
@@ -7631,7 +7613,7 @@ class TrieMap {
7631
7613
  }
7632
7614
  delete(key) {
7633
7615
  const parentNodes = [];
7634
- let node = __classPrivateFieldGet(this, _TrieMap_root, "f");
7616
+ let node = this.root;
7635
7617
  for (const part of key) {
7636
7618
  if (node.children.has(part)) {
7637
7619
  parentNodes.push(node);
@@ -7654,18 +7636,16 @@ class TrieMap {
7654
7636
  }
7655
7637
  }
7656
7638
 
7657
- var _FiniteStateMachine_state;
7658
7639
  class FiniteStateMachine {
7659
7640
  constructor(schema, initialState) {
7660
7641
  this.schema = schema;
7661
- _FiniteStateMachine_state.set(this, void 0);
7662
- __classPrivateFieldSet(this, _FiniteStateMachine_state, initialState, "f");
7642
+ this._state = initialState;
7663
7643
  }
7664
7644
  get state() {
7665
- return __classPrivateFieldGet(this, _FiniteStateMachine_state, "f");
7645
+ return this._state;
7666
7646
  }
7667
7647
  matches(state) {
7668
- return __classPrivateFieldGet(this, _FiniteStateMachine_state, "f") === state;
7648
+ return this._state === state;
7669
7649
  }
7670
7650
  can(event) {
7671
7651
  return event in this.schema[this.state];
@@ -7675,14 +7655,13 @@ class FiniteStateMachine {
7675
7655
  */
7676
7656
  send(event) {
7677
7657
  if (this.can(event)) {
7678
- __classPrivateFieldSet(this, _FiniteStateMachine_state, this.schema[this.state][event], "f");
7658
+ this._state = this.schema[this.state][event];
7679
7659
  }
7680
7660
  else {
7681
7661
  throw new BadEventError(this.state, event);
7682
7662
  }
7683
7663
  }
7684
7664
  }
7685
- _FiniteStateMachine_state = new WeakMap();
7686
7665
  class BadEventError extends es2018$d.CustomError {
7687
7666
  constructor(state, event) {
7688
7667
  super(`State ${state} cannot react to event ${event}`);