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