@blackglory/structures 0.5.0 → 0.5.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.
- package/dist/es2015/index.min.mjs +2 -2
- package/dist/es2015/index.min.mjs.map +1 -1
- package/dist/es2015/index.mjs +98 -144
- package/dist/es2015/index.mjs.map +1 -1
- package/dist/es2015/index.umd.js +98 -144
- package/dist/es2015/index.umd.js.map +1 -1
- package/dist/es2015/index.umd.min.js +2 -2
- package/dist/es2015/index.umd.min.js.map +1 -1
- package/dist/es2018/index.min.mjs +2 -2
- package/dist/es2018/index.min.mjs.map +1 -1
- package/dist/es2018/index.mjs +98 -144
- package/dist/es2018/index.mjs.map +1 -1
- package/dist/es2018/index.umd.js +98 -144
- package/dist/es2018/index.umd.js.map +1 -1
- package/dist/es2018/index.umd.min.js +2 -2
- package/dist/es2018/index.umd.min.js.map +1 -1
- package/lib/es2015/box.d.ts +1 -1
- package/lib/es2015/box.js +3 -17
- package/lib/es2015/box.js.map +1 -1
- package/lib/es2015/emitter.d.ts +1 -1
- package/lib/es2015/emitter.js +10 -16
- package/lib/es2015/emitter.js.map +1 -1
- package/lib/es2015/expirable-map.d.ts +2 -1
- package/lib/es2015/expirable-map.js +14 -27
- package/lib/es2015/expirable-map.js.map +1 -1
- package/lib/es2015/finite-state-machine.d.ts +1 -1
- package/lib/es2015/finite-state-machine.js +4 -18
- package/lib/es2015/finite-state-machine.js.map +1 -1
- package/lib/es2015/hash-map.d.ts +1 -1
- package/lib/es2015/hash-map.js +8 -14
- package/lib/es2015/hash-map.js.map +1 -1
- package/lib/es2015/hash-set.d.ts +1 -1
- package/lib/es2015/hash-set.js +9 -15
- package/lib/es2015/hash-set.js.map +1 -1
- package/lib/es2015/lru-map.d.ts +2 -1
- package/lib/es2015/lru-map.js +15 -28
- package/lib/es2015/lru-map.js.map +1 -1
- package/lib/es2015/queue.d.ts +1 -1
- package/lib/es2015/queue.js +8 -14
- package/lib/es2015/queue.js.map +1 -1
- package/lib/es2015/tlru-map.d.ts +4 -2
- package/lib/es2015/tlru-map.js +21 -35
- package/lib/es2015/tlru-map.js.map +1 -1
- package/lib/es2015/trie-map.d.ts +1 -1
- package/lib/es2015/trie-map.js +6 -12
- package/lib/es2015/trie-map.js.map +1 -1
- package/lib/es2018/box.d.ts +1 -1
- package/lib/es2018/box.js +3 -17
- package/lib/es2018/box.js.map +1 -1
- package/lib/es2018/emitter.d.ts +1 -1
- package/lib/es2018/emitter.js +10 -16
- package/lib/es2018/emitter.js.map +1 -1
- package/lib/es2018/expirable-map.d.ts +2 -1
- package/lib/es2018/expirable-map.js +14 -27
- package/lib/es2018/expirable-map.js.map +1 -1
- package/lib/es2018/finite-state-machine.d.ts +1 -1
- package/lib/es2018/finite-state-machine.js +4 -18
- package/lib/es2018/finite-state-machine.js.map +1 -1
- package/lib/es2018/hash-map.d.ts +1 -1
- package/lib/es2018/hash-map.js +8 -14
- package/lib/es2018/hash-map.js.map +1 -1
- package/lib/es2018/hash-set.d.ts +1 -1
- package/lib/es2018/hash-set.js +9 -15
- package/lib/es2018/hash-set.js.map +1 -1
- package/lib/es2018/lru-map.d.ts +2 -1
- package/lib/es2018/lru-map.js +15 -28
- package/lib/es2018/lru-map.js.map +1 -1
- package/lib/es2018/queue.d.ts +1 -1
- package/lib/es2018/queue.js +8 -14
- package/lib/es2018/queue.js.map +1 -1
- package/lib/es2018/tlru-map.d.ts +4 -2
- package/lib/es2018/tlru-map.js +21 -35
- package/lib/es2018/tlru-map.js.map +1 -1
- package/lib/es2018/trie-map.d.ts +1 -1
- package/lib/es2018/trie-map.js +6 -12
- package/lib/es2018/trie-map.js.map +1 -1
- package/package.json +1 -1
package/dist/es2018/index.mjs
CHANGED
|
@@ -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
|
-
|
|
33
|
-
__classPrivateFieldSet(this, _Box_value, value, "f");
|
|
3
|
+
this.value = value;
|
|
34
4
|
}
|
|
35
5
|
set(value) {
|
|
36
|
-
|
|
6
|
+
this.value = value;
|
|
37
7
|
}
|
|
38
8
|
get() {
|
|
39
|
-
return
|
|
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,123 @@ 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
|
-
|
|
24
|
+
this.map = new Map();
|
|
57
25
|
}
|
|
58
|
-
get [
|
|
26
|
+
get [Symbol.toStringTag]() {
|
|
59
27
|
return this.constructor.name;
|
|
60
28
|
}
|
|
61
29
|
/**
|
|
62
30
|
* The same handler will only be registered once.
|
|
63
31
|
*/
|
|
64
32
|
on(event, handler) {
|
|
65
|
-
if (!
|
|
66
|
-
|
|
33
|
+
if (!this.map.has(event)) {
|
|
34
|
+
this.map.set(event, new Set());
|
|
67
35
|
}
|
|
68
|
-
const set =
|
|
36
|
+
const set = this.map.get(event);
|
|
69
37
|
set.add(handler);
|
|
70
38
|
}
|
|
71
39
|
off(event, handler) {
|
|
72
|
-
if (!
|
|
40
|
+
if (!this.map.has(event))
|
|
73
41
|
return;
|
|
74
|
-
const handlers =
|
|
42
|
+
const handlers = this.map.get(event);
|
|
75
43
|
handlers.delete(handler);
|
|
76
44
|
if (handlers.size === 0) {
|
|
77
|
-
|
|
45
|
+
this.map.delete(event);
|
|
78
46
|
}
|
|
79
47
|
}
|
|
80
48
|
emit(event, ...args) {
|
|
81
|
-
if (!
|
|
49
|
+
if (!this.map.has(event))
|
|
82
50
|
return;
|
|
83
|
-
|
|
51
|
+
this.map.get(event).forEach(cb => cb(...args));
|
|
84
52
|
}
|
|
85
53
|
}
|
|
86
54
|
|
|
87
|
-
var _HashMap_map;
|
|
88
55
|
class HashMap {
|
|
89
56
|
constructor(hash) {
|
|
90
57
|
this.hash = hash;
|
|
91
|
-
|
|
58
|
+
this.map = new Map();
|
|
92
59
|
}
|
|
93
|
-
get [
|
|
60
|
+
get [Symbol.toStringTag]() {
|
|
94
61
|
return this.constructor.name;
|
|
95
62
|
}
|
|
96
63
|
get size() {
|
|
97
|
-
return
|
|
64
|
+
return this.map.size;
|
|
98
65
|
}
|
|
99
66
|
set(key, value) {
|
|
100
|
-
|
|
67
|
+
this.map.set(this.hash(key), value);
|
|
101
68
|
return this;
|
|
102
69
|
}
|
|
103
70
|
has(key) {
|
|
104
|
-
return
|
|
71
|
+
return this.map.has(this.hash(key));
|
|
105
72
|
}
|
|
106
73
|
get(key) {
|
|
107
|
-
return
|
|
74
|
+
return this.map.get(this.hash(key));
|
|
108
75
|
}
|
|
109
76
|
delete(key) {
|
|
110
|
-
return
|
|
77
|
+
return this.map.delete(this.hash(key));
|
|
111
78
|
}
|
|
112
79
|
clear() {
|
|
113
|
-
|
|
80
|
+
this.map.clear();
|
|
114
81
|
}
|
|
115
82
|
}
|
|
116
83
|
|
|
117
|
-
var _HashSet_map;
|
|
118
84
|
class HashSet {
|
|
119
85
|
constructor(hash) {
|
|
120
86
|
this.hash = hash;
|
|
121
|
-
|
|
87
|
+
this.map = new Map();
|
|
122
88
|
}
|
|
123
|
-
get [
|
|
89
|
+
get [Symbol.toStringTag]() {
|
|
124
90
|
return this.constructor.name;
|
|
125
91
|
}
|
|
126
92
|
get size() {
|
|
127
|
-
return
|
|
93
|
+
return this.map.size;
|
|
128
94
|
}
|
|
129
95
|
[Symbol.iterator]() {
|
|
130
|
-
return
|
|
96
|
+
return this.map.values();
|
|
131
97
|
}
|
|
132
98
|
add(value) {
|
|
133
|
-
|
|
99
|
+
this.map.set(this.hash(value), value);
|
|
134
100
|
return this;
|
|
135
101
|
}
|
|
136
102
|
delete(value) {
|
|
137
|
-
return
|
|
103
|
+
return this.map.delete(this.hash(value));
|
|
138
104
|
}
|
|
139
105
|
has(value) {
|
|
140
|
-
return
|
|
106
|
+
return this.map.has(this.hash(value));
|
|
141
107
|
}
|
|
142
108
|
clear() {
|
|
143
|
-
|
|
109
|
+
this.map.clear();
|
|
144
110
|
}
|
|
145
111
|
values() {
|
|
146
|
-
return
|
|
112
|
+
return this.map.values();
|
|
147
113
|
}
|
|
148
114
|
}
|
|
149
115
|
|
|
150
|
-
var _Queue_items;
|
|
151
116
|
class Queue {
|
|
152
117
|
constructor() {
|
|
153
|
-
|
|
118
|
+
this.items = [];
|
|
154
119
|
}
|
|
155
|
-
get [
|
|
120
|
+
get [Symbol.toStringTag]() {
|
|
156
121
|
return this.constructor.name;
|
|
157
122
|
}
|
|
158
123
|
get size() {
|
|
159
|
-
return
|
|
124
|
+
return this.items.length;
|
|
160
125
|
}
|
|
161
126
|
empty() {
|
|
162
|
-
|
|
127
|
+
this.items.length = 0;
|
|
163
128
|
}
|
|
164
129
|
enqueue(...items) {
|
|
165
|
-
|
|
130
|
+
this.items.push(...items);
|
|
166
131
|
}
|
|
167
132
|
dequeue() {
|
|
168
|
-
return
|
|
133
|
+
return this.items.shift();
|
|
169
134
|
}
|
|
170
135
|
remove(item) {
|
|
171
136
|
let index;
|
|
172
|
-
while ((index =
|
|
173
|
-
|
|
137
|
+
while ((index = this.items.indexOf(item)) >= 0) {
|
|
138
|
+
this.items.splice(index, 1);
|
|
174
139
|
}
|
|
175
140
|
}
|
|
176
141
|
}
|
|
@@ -7116,61 +7081,59 @@ countAsync$1.countAsync = countAsync;
|
|
|
7116
7081
|
|
|
7117
7082
|
} (es2018$4));
|
|
7118
7083
|
|
|
7119
|
-
var _LRUMap_limit, _LRUMap_map;
|
|
7120
7084
|
class LRUMap {
|
|
7121
7085
|
constructor(limit) {
|
|
7122
|
-
|
|
7123
|
-
_LRUMap_map.set(this, new Map());
|
|
7086
|
+
this.map = new Map();
|
|
7124
7087
|
es2018$d.assert(Number.isInteger(limit), 'The parameter limit must be an integer');
|
|
7125
7088
|
es2018$d.assert(limit > 0, 'The parameter limit must be a positive value');
|
|
7126
|
-
|
|
7089
|
+
this.limit = limit;
|
|
7127
7090
|
}
|
|
7128
|
-
get [
|
|
7091
|
+
get [Symbol.toStringTag]() {
|
|
7129
7092
|
return this.constructor.name;
|
|
7130
7093
|
}
|
|
7131
7094
|
get size() {
|
|
7132
|
-
return
|
|
7095
|
+
return this.map.size;
|
|
7133
7096
|
}
|
|
7134
7097
|
set(key, value) {
|
|
7135
|
-
if (
|
|
7098
|
+
if (this.map.has(key)) {
|
|
7136
7099
|
this.updateItem(key, value);
|
|
7137
7100
|
}
|
|
7138
7101
|
else {
|
|
7139
|
-
if (
|
|
7140
|
-
|
|
7102
|
+
if (this.map.size === this.limit) {
|
|
7103
|
+
this.map.delete(this.getColdestKey());
|
|
7141
7104
|
}
|
|
7142
|
-
|
|
7105
|
+
this.map.set(key, value);
|
|
7143
7106
|
}
|
|
7144
7107
|
return this;
|
|
7145
7108
|
}
|
|
7146
7109
|
has(key) {
|
|
7147
|
-
return
|
|
7110
|
+
return this.map.has(key);
|
|
7148
7111
|
}
|
|
7149
7112
|
get(key) {
|
|
7150
7113
|
if (!this.has(key))
|
|
7151
7114
|
return undefined;
|
|
7152
|
-
const value =
|
|
7115
|
+
const value = this.map.get(key);
|
|
7153
7116
|
this.updateItem(key, value);
|
|
7154
7117
|
return value;
|
|
7155
7118
|
}
|
|
7156
7119
|
delete(key) {
|
|
7157
|
-
return
|
|
7120
|
+
return this.map.delete(key);
|
|
7158
7121
|
}
|
|
7159
7122
|
clear() {
|
|
7160
|
-
|
|
7123
|
+
this.map.clear();
|
|
7161
7124
|
}
|
|
7162
7125
|
/**
|
|
7163
7126
|
* Reinsert the item.
|
|
7164
7127
|
*/
|
|
7165
7128
|
updateItem(key, value) {
|
|
7166
|
-
|
|
7167
|
-
|
|
7129
|
+
this.map.delete(key);
|
|
7130
|
+
this.map.set(key, value);
|
|
7168
7131
|
}
|
|
7169
7132
|
/**
|
|
7170
7133
|
* Return the earliest key inserted in the Map
|
|
7171
7134
|
*/
|
|
7172
7135
|
getColdestKey() {
|
|
7173
|
-
return es2018$4.first(
|
|
7136
|
+
return es2018$4.first(this.map.keys());
|
|
7174
7137
|
}
|
|
7175
7138
|
}
|
|
7176
7139
|
|
|
@@ -7342,36 +7305,34 @@ setDynamicTimeoutLoop$1.setDynamicTimeoutLoop = setDynamicTimeoutLoop;
|
|
|
7342
7305
|
|
|
7343
7306
|
} (es2018$1));
|
|
7344
7307
|
|
|
7345
|
-
var _ExpirableMap_map, _ExpirableMap_cancelClearTimeout;
|
|
7346
7308
|
class ExpirableMap {
|
|
7347
7309
|
constructor() {
|
|
7348
|
-
|
|
7349
|
-
_ExpirableMap_cancelClearTimeout.set(this, void 0);
|
|
7310
|
+
this.map = new Map();
|
|
7350
7311
|
/**
|
|
7351
7312
|
* 按过期时间升序排列所有项目的元数据
|
|
7352
7313
|
*/
|
|
7353
7314
|
this.itemMetadataSortedByExpirationTime = [];
|
|
7354
7315
|
}
|
|
7355
|
-
get [
|
|
7316
|
+
get [Symbol.toStringTag]() {
|
|
7356
7317
|
return this.constructor.name;
|
|
7357
7318
|
}
|
|
7358
7319
|
get size() {
|
|
7359
|
-
return
|
|
7320
|
+
return this.map.size;
|
|
7360
7321
|
}
|
|
7361
7322
|
set(key, value, maxAge) {
|
|
7362
|
-
|
|
7323
|
+
this.map.set(key, value);
|
|
7363
7324
|
this.removeItemMetadata(key);
|
|
7364
7325
|
this.addItemMetadata(key, Date.now() + maxAge);
|
|
7365
7326
|
return this;
|
|
7366
7327
|
}
|
|
7367
7328
|
has(key) {
|
|
7368
|
-
return
|
|
7329
|
+
return this.map.has(key);
|
|
7369
7330
|
}
|
|
7370
7331
|
get(key) {
|
|
7371
|
-
return
|
|
7332
|
+
return this.map.get(key);
|
|
7372
7333
|
}
|
|
7373
7334
|
delete(key) {
|
|
7374
|
-
const exists =
|
|
7335
|
+
const exists = this.map.delete(key);
|
|
7375
7336
|
if (exists) {
|
|
7376
7337
|
const index = this.itemMetadataSortedByExpirationTime.findIndex(x => x.key === key);
|
|
7377
7338
|
this.itemMetadataSortedByExpirationTime.splice(index, 1);
|
|
@@ -7384,8 +7345,8 @@ class ExpirableMap {
|
|
|
7384
7345
|
}
|
|
7385
7346
|
clear() {
|
|
7386
7347
|
var _a;
|
|
7387
|
-
|
|
7388
|
-
(_a =
|
|
7348
|
+
this.map.clear();
|
|
7349
|
+
(_a = this.cancelClearTimeout) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
7389
7350
|
this.itemMetadataSortedByExpirationTime = [];
|
|
7390
7351
|
}
|
|
7391
7352
|
addItemMetadata(key, expirationTime) {
|
|
@@ -7422,11 +7383,11 @@ class ExpirableMap {
|
|
|
7422
7383
|
const expiredItemKeys = indexOfFirstUnexpired >= 0
|
|
7423
7384
|
? this.itemMetadataSortedByExpirationTime.splice(0, indexOfFirstUnexpired)
|
|
7424
7385
|
: this.itemMetadataSortedByExpirationTime.splice(0, this.itemMetadataSortedByExpirationTime.length);
|
|
7425
|
-
expiredItemKeys.forEach(x =>
|
|
7386
|
+
expiredItemKeys.forEach(x => this.map.delete(x.key));
|
|
7426
7387
|
}
|
|
7427
7388
|
rescheduleClearTimeout() {
|
|
7428
7389
|
var _a;
|
|
7429
|
-
(_a =
|
|
7390
|
+
(_a = this.cancelClearTimeout) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
7430
7391
|
if (this.itemMetadataSortedByExpirationTime.length > 0) {
|
|
7431
7392
|
const item = this.itemMetadataSortedByExpirationTime[0];
|
|
7432
7393
|
if (Number.isFinite(item.expirationTime)) {
|
|
@@ -7434,59 +7395,56 @@ class ExpirableMap {
|
|
|
7434
7395
|
this.clearExpiredItems(Date.now());
|
|
7435
7396
|
this.rescheduleClearTimeout();
|
|
7436
7397
|
});
|
|
7437
|
-
|
|
7398
|
+
this.cancelClearTimeout = () => {
|
|
7438
7399
|
cancel();
|
|
7439
|
-
|
|
7440
|
-
}
|
|
7400
|
+
this.cancelClearTimeout = undefined;
|
|
7401
|
+
};
|
|
7441
7402
|
}
|
|
7442
7403
|
}
|
|
7443
7404
|
}
|
|
7444
7405
|
}
|
|
7445
7406
|
|
|
7446
|
-
var _TLRUMap_limit, _TLRUMap_map, _TLRUMap_cancelClearTimeout;
|
|
7447
7407
|
/**
|
|
7448
7408
|
* TLRUMap = LRUMap + ExpirableMap
|
|
7449
7409
|
*/
|
|
7450
7410
|
class TLRUMap {
|
|
7451
7411
|
constructor(limit) {
|
|
7452
|
-
|
|
7453
|
-
_TLRUMap_map.set(this, new Map());
|
|
7454
|
-
_TLRUMap_cancelClearTimeout.set(this, void 0);
|
|
7412
|
+
this.map = new Map();
|
|
7455
7413
|
/**
|
|
7456
7414
|
* 按过期时间升序排列所有项目的元数据
|
|
7457
7415
|
*/
|
|
7458
7416
|
this.itemMetadataSortedByExpirationTime = [];
|
|
7459
7417
|
es2018$d.assert(Number.isInteger(limit), 'The parameter limit must be an integer');
|
|
7460
7418
|
es2018$d.assert(limit > 0, 'The parameter limit must be a positive value');
|
|
7461
|
-
|
|
7419
|
+
this.limit = limit;
|
|
7462
7420
|
}
|
|
7463
|
-
get [
|
|
7421
|
+
get [Symbol.toStringTag]() {
|
|
7464
7422
|
return this.constructor.name;
|
|
7465
7423
|
}
|
|
7466
7424
|
get size() {
|
|
7467
|
-
return
|
|
7425
|
+
return this.map.size;
|
|
7468
7426
|
}
|
|
7469
7427
|
set(key, value, maxAge) {
|
|
7470
|
-
if (
|
|
7428
|
+
if (this.map.has(key)) {
|
|
7471
7429
|
this.updateItem(key, value);
|
|
7472
7430
|
this.removeItemMetadata(key);
|
|
7473
7431
|
this.addItemMetadata(key, Date.now() + maxAge);
|
|
7474
7432
|
}
|
|
7475
7433
|
else {
|
|
7476
|
-
if (
|
|
7477
|
-
|
|
7434
|
+
if (this.map.size === this.limit) {
|
|
7435
|
+
this.map.delete(this.getColdestKey());
|
|
7478
7436
|
}
|
|
7479
|
-
|
|
7437
|
+
this.map.set(key, value);
|
|
7480
7438
|
this.addItemMetadata(key, Date.now() + maxAge);
|
|
7481
7439
|
}
|
|
7482
7440
|
return this;
|
|
7483
7441
|
}
|
|
7484
7442
|
has(key) {
|
|
7485
|
-
return
|
|
7443
|
+
return this.map.has(key);
|
|
7486
7444
|
}
|
|
7487
7445
|
get(key) {
|
|
7488
7446
|
if (this.has(key)) {
|
|
7489
|
-
const value =
|
|
7447
|
+
const value = this.map.get(key);
|
|
7490
7448
|
this.updateItem(key, value);
|
|
7491
7449
|
return value;
|
|
7492
7450
|
}
|
|
@@ -7495,7 +7453,7 @@ class TLRUMap {
|
|
|
7495
7453
|
}
|
|
7496
7454
|
}
|
|
7497
7455
|
delete(key) {
|
|
7498
|
-
const result =
|
|
7456
|
+
const result = this.map.delete(key);
|
|
7499
7457
|
if (result) {
|
|
7500
7458
|
const index = this.itemMetadataSortedByExpirationTime.findIndex(x => x.key === key);
|
|
7501
7459
|
this.itemMetadataSortedByExpirationTime.splice(index, 1);
|
|
@@ -7508,16 +7466,16 @@ class TLRUMap {
|
|
|
7508
7466
|
}
|
|
7509
7467
|
clear() {
|
|
7510
7468
|
var _a;
|
|
7511
|
-
|
|
7512
|
-
(_a =
|
|
7469
|
+
this.map.clear();
|
|
7470
|
+
(_a = this.cancelClearTimeout) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
7513
7471
|
this.itemMetadataSortedByExpirationTime = [];
|
|
7514
7472
|
}
|
|
7515
7473
|
/**
|
|
7516
7474
|
* 重新插入项目, 这会使项目置于#map迭代器的末端.
|
|
7517
7475
|
*/
|
|
7518
7476
|
updateItem(key, value) {
|
|
7519
|
-
|
|
7520
|
-
|
|
7477
|
+
this.map.delete(key);
|
|
7478
|
+
this.map.set(key, value);
|
|
7521
7479
|
}
|
|
7522
7480
|
addItemMetadata(key, expirationTime) {
|
|
7523
7481
|
for (let i = 0; i < this.itemMetadataSortedByExpirationTime.length; i++) {
|
|
@@ -7553,11 +7511,11 @@ class TLRUMap {
|
|
|
7553
7511
|
const expiredItemKeys = indexOfFirstUnexpiredItem >= 0
|
|
7554
7512
|
? this.itemMetadataSortedByExpirationTime.splice(0, indexOfFirstUnexpiredItem)
|
|
7555
7513
|
: this.itemMetadataSortedByExpirationTime.splice(0, this.itemMetadataSortedByExpirationTime.length);
|
|
7556
|
-
expiredItemKeys.forEach(x =>
|
|
7514
|
+
expiredItemKeys.forEach(x => this.map.delete(x.key));
|
|
7557
7515
|
}
|
|
7558
7516
|
rescheduleClearTimeout() {
|
|
7559
7517
|
var _a;
|
|
7560
|
-
(_a =
|
|
7518
|
+
(_a = this.cancelClearTimeout) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
7561
7519
|
if (this.itemMetadataSortedByExpirationTime.length > 0) {
|
|
7562
7520
|
const item = this.itemMetadataSortedByExpirationTime[0];
|
|
7563
7521
|
if (Number.isFinite(item.expirationTime)) {
|
|
@@ -7565,10 +7523,10 @@ class TLRUMap {
|
|
|
7565
7523
|
this.clearExpiredItems(Date.now());
|
|
7566
7524
|
this.rescheduleClearTimeout();
|
|
7567
7525
|
});
|
|
7568
|
-
|
|
7526
|
+
this.cancelClearTimeout = () => {
|
|
7569
7527
|
cancel();
|
|
7570
|
-
|
|
7571
|
-
}
|
|
7528
|
+
this.cancelClearTimeout = undefined;
|
|
7529
|
+
};
|
|
7572
7530
|
}
|
|
7573
7531
|
}
|
|
7574
7532
|
}
|
|
@@ -7576,11 +7534,10 @@ class TLRUMap {
|
|
|
7576
7534
|
* Return the earliest key inserted in the Map
|
|
7577
7535
|
*/
|
|
7578
7536
|
getColdestKey() {
|
|
7579
|
-
return es2018$4.first(
|
|
7537
|
+
return es2018$4.first(this.map.keys());
|
|
7580
7538
|
}
|
|
7581
7539
|
}
|
|
7582
7540
|
|
|
7583
|
-
var _TrieMap_root;
|
|
7584
7541
|
class TrieNode {
|
|
7585
7542
|
constructor(value) {
|
|
7586
7543
|
this.value = value;
|
|
@@ -7589,13 +7546,13 @@ class TrieNode {
|
|
|
7589
7546
|
}
|
|
7590
7547
|
class TrieMap {
|
|
7591
7548
|
constructor() {
|
|
7592
|
-
|
|
7549
|
+
this.root = new TrieNode();
|
|
7593
7550
|
}
|
|
7594
|
-
get [
|
|
7551
|
+
get [Symbol.toStringTag]() {
|
|
7595
7552
|
return this.constructor.name;
|
|
7596
7553
|
}
|
|
7597
7554
|
set(key, value) {
|
|
7598
|
-
let node =
|
|
7555
|
+
let node = this.root;
|
|
7599
7556
|
for (const part of key) {
|
|
7600
7557
|
if (!node.children.has(part)) {
|
|
7601
7558
|
node.children.set(part, new TrieNode());
|
|
@@ -7606,7 +7563,7 @@ class TrieMap {
|
|
|
7606
7563
|
return this;
|
|
7607
7564
|
}
|
|
7608
7565
|
has(key) {
|
|
7609
|
-
let node =
|
|
7566
|
+
let node = this.root;
|
|
7610
7567
|
for (const part of key) {
|
|
7611
7568
|
if (node.children.has(part)) {
|
|
7612
7569
|
node = node.children.get(part);
|
|
@@ -7618,7 +7575,7 @@ class TrieMap {
|
|
|
7618
7575
|
return node.value !== undefined;
|
|
7619
7576
|
}
|
|
7620
7577
|
get(key) {
|
|
7621
|
-
let node =
|
|
7578
|
+
let node = this.root;
|
|
7622
7579
|
for (const part of key) {
|
|
7623
7580
|
if (node.children.has(part)) {
|
|
7624
7581
|
node = node.children.get(part);
|
|
@@ -7631,7 +7588,7 @@ class TrieMap {
|
|
|
7631
7588
|
}
|
|
7632
7589
|
delete(key) {
|
|
7633
7590
|
const parentNodes = [];
|
|
7634
|
-
let node =
|
|
7591
|
+
let node = this.root;
|
|
7635
7592
|
for (const part of key) {
|
|
7636
7593
|
if (node.children.has(part)) {
|
|
7637
7594
|
parentNodes.push(node);
|
|
@@ -7654,18 +7611,16 @@ class TrieMap {
|
|
|
7654
7611
|
}
|
|
7655
7612
|
}
|
|
7656
7613
|
|
|
7657
|
-
var _FiniteStateMachine_state;
|
|
7658
7614
|
class FiniteStateMachine {
|
|
7659
7615
|
constructor(schema, initialState) {
|
|
7660
7616
|
this.schema = schema;
|
|
7661
|
-
|
|
7662
|
-
__classPrivateFieldSet(this, _FiniteStateMachine_state, initialState, "f");
|
|
7617
|
+
this._state = initialState;
|
|
7663
7618
|
}
|
|
7664
7619
|
get state() {
|
|
7665
|
-
return
|
|
7620
|
+
return this._state;
|
|
7666
7621
|
}
|
|
7667
7622
|
matches(state) {
|
|
7668
|
-
return
|
|
7623
|
+
return this._state === state;
|
|
7669
7624
|
}
|
|
7670
7625
|
can(event) {
|
|
7671
7626
|
return event in this.schema[this.state];
|
|
@@ -7675,14 +7630,13 @@ class FiniteStateMachine {
|
|
|
7675
7630
|
*/
|
|
7676
7631
|
send(event) {
|
|
7677
7632
|
if (this.can(event)) {
|
|
7678
|
-
|
|
7633
|
+
this._state = this.schema[this.state][event];
|
|
7679
7634
|
}
|
|
7680
7635
|
else {
|
|
7681
7636
|
throw new BadEventError(this.state, event);
|
|
7682
7637
|
}
|
|
7683
7638
|
}
|
|
7684
7639
|
}
|
|
7685
|
-
_FiniteStateMachine_state = new WeakMap();
|
|
7686
7640
|
class BadEventError extends es2018$d.CustomError {
|
|
7687
7641
|
constructor(state, event) {
|
|
7688
7642
|
super(`State ${state} cannot react to event ${event}`);
|