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