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