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