list-toolkit 2.2.5 → 2.3.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.
Files changed (125) hide show
  1. package/README.md +40 -36
  2. package/llms-full.txt +743 -0
  3. package/llms.txt +100 -0
  4. package/package.json +40 -32
  5. package/src/cache/cache-fifo.d.ts +6 -0
  6. package/src/cache/cache-fifo.js +7 -4
  7. package/src/cache/cache-lfu.d.ts +18 -0
  8. package/src/cache/cache-lfu.js +18 -6
  9. package/src/cache/cache-lru.d.ts +74 -0
  10. package/src/cache/cache-lru.js +60 -5
  11. package/src/cache/cache-random.d.ts +20 -0
  12. package/src/cache/cache-random.js +17 -6
  13. package/src/cache/decorator.d.ts +46 -0
  14. package/src/cache/decorator.js +26 -2
  15. package/src/cache.d.ts +13 -0
  16. package/src/cache.js +7 -2
  17. package/src/ext-list.d.ts +3 -0
  18. package/src/ext-list.js +0 -2
  19. package/src/ext-slist.d.ts +3 -0
  20. package/src/ext-slist.js +0 -2
  21. package/src/ext-value-list.d.ts +3 -0
  22. package/src/ext-value-list.js +0 -2
  23. package/src/ext-value-slist.d.ts +3 -0
  24. package/src/ext-value-slist.js +0 -2
  25. package/src/heap/basics.d.ts +89 -0
  26. package/src/heap/basics.js +42 -5
  27. package/src/heap/leftist-heap.d.ts +107 -0
  28. package/src/heap/leftist-heap.js +54 -2
  29. package/src/heap/min-heap.d.ts +270 -0
  30. package/src/heap/min-heap.js +186 -2
  31. package/src/heap/skew-heap.d.ts +105 -0
  32. package/src/heap/skew-heap.js +54 -2
  33. package/src/heap.d.ts +3 -0
  34. package/src/heap.js +0 -2
  35. package/src/list/basics.d.ts +43 -0
  36. package/src/list/basics.js +26 -8
  37. package/src/list/core.d.ts +271 -0
  38. package/src/list/core.js +162 -7
  39. package/src/list/ext-value.d.ts +253 -0
  40. package/src/list/ext-value.js +40 -6
  41. package/src/list/ext.d.ts +242 -0
  42. package/src/list/ext.js +148 -10
  43. package/src/list/nodes.d.ts +336 -0
  44. package/src/list/nodes.js +141 -3
  45. package/src/list/ptr.d.ts +72 -0
  46. package/src/list/ptr.js +44 -2
  47. package/src/list/value.d.ts +292 -0
  48. package/src/list/value.js +47 -6
  49. package/src/list-helpers.d.ts +44 -0
  50. package/src/list-helpers.js +36 -3
  51. package/src/list-utils.d.ts +141 -0
  52. package/src/list-utils.js +89 -3
  53. package/src/list.d.ts +3 -0
  54. package/src/list.js +0 -2
  55. package/src/meta-utils.d.ts +212 -0
  56. package/src/meta-utils.js +152 -1
  57. package/src/nt-utils.d.ts +91 -0
  58. package/src/nt-utils.js +65 -4
  59. package/src/queue.d.ts +74 -0
  60. package/src/queue.js +28 -2
  61. package/src/slist/basics.d.ts +47 -0
  62. package/src/slist/basics.js +23 -8
  63. package/src/slist/core.d.ts +251 -0
  64. package/src/slist/core.js +151 -6
  65. package/src/slist/ext-value.d.ts +188 -0
  66. package/src/slist/ext-value.js +35 -6
  67. package/src/slist/ext.d.ts +182 -0
  68. package/src/slist/ext.js +114 -12
  69. package/src/slist/nodes.d.ts +361 -0
  70. package/src/slist/nodes.js +156 -3
  71. package/src/slist/ptr.d.ts +73 -0
  72. package/src/slist/ptr.js +45 -2
  73. package/src/slist/value.d.ts +246 -0
  74. package/src/slist/value.js +38 -6
  75. package/src/slist.d.ts +3 -0
  76. package/src/slist.js +0 -2
  77. package/src/stack.d.ts +59 -0
  78. package/src/stack.js +29 -3
  79. package/src/tree/splay-tree.d.ts +151 -0
  80. package/src/tree/splay-tree.js +94 -3
  81. package/src/value-list.d.ts +3 -0
  82. package/src/value-list.js +0 -2
  83. package/src/value-slist.d.ts +3 -0
  84. package/src/value-slist.js +0 -2
  85. package/cjs/cache/cache-fifo.js +0 -37
  86. package/cjs/cache/cache-lfu.js +0 -76
  87. package/cjs/cache/cache-lru.js +0 -100
  88. package/cjs/cache/cache-random.js +0 -77
  89. package/cjs/cache/decorator.js +0 -47
  90. package/cjs/cache.js +0 -27
  91. package/cjs/ext-list.js +0 -21
  92. package/cjs/ext-slist.js +0 -21
  93. package/cjs/ext-value-list.js +0 -21
  94. package/cjs/ext-value-slist.js +0 -21
  95. package/cjs/heap/basics.js +0 -63
  96. package/cjs/heap/leftist-heap.js +0 -124
  97. package/cjs/heap/min-heap.js +0 -294
  98. package/cjs/heap/skew-heap.js +0 -114
  99. package/cjs/heap.js +0 -21
  100. package/cjs/list/basics.js +0 -88
  101. package/cjs/list/core.js +0 -305
  102. package/cjs/list/ext-value.js +0 -88
  103. package/cjs/list/ext.js +0 -356
  104. package/cjs/list/nodes.js +0 -240
  105. package/cjs/list/ptr.js +0 -61
  106. package/cjs/list/value.js +0 -99
  107. package/cjs/list-helpers.js +0 -91
  108. package/cjs/list-utils.js +0 -141
  109. package/cjs/list.js +0 -21
  110. package/cjs/meta-utils.js +0 -171
  111. package/cjs/nt-utils.js +0 -132
  112. package/cjs/package.json +0 -1
  113. package/cjs/queue.js +0 -58
  114. package/cjs/slist/basics.js +0 -71
  115. package/cjs/slist/core.js +0 -362
  116. package/cjs/slist/ext-value.js +0 -82
  117. package/cjs/slist/ext.js +0 -336
  118. package/cjs/slist/nodes.js +0 -276
  119. package/cjs/slist/ptr.js +0 -87
  120. package/cjs/slist/value.js +0 -90
  121. package/cjs/slist.js +0 -21
  122. package/cjs/stack.js +0 -55
  123. package/cjs/tree/splay-tree.js +0 -362
  124. package/cjs/value-list.js +0 -21
  125. package/cjs/value-slist.js +0 -21
@@ -1,5 +1,3 @@
1
- 'use strict';
2
-
3
1
  import {copyOptions} from '../meta-utils.js';
4
2
 
5
3
  const defaultLess = (a, b) => a < b;
@@ -55,16 +53,26 @@ const splay = node => {
55
53
 
56
54
  const count = tree => (tree ? count(tree.left) + count(tree.right) + 1 : 0);
57
55
 
56
+ /** Node for a splay tree. */
58
57
  export class SplayTreeNode {
58
+ /** @param {*} value - Value to store. */
59
59
  constructor(value) {
60
60
  this.left = this.right = this.parent = null;
61
61
  this.value = value;
62
62
  }
63
+ /**
64
+ * Find the minimum node in this subtree.
65
+ * @returns {SplayTreeNode} The leftmost node.
66
+ */
63
67
  getMin() {
64
68
  let z = this;
65
69
  while (z.left) z = z.left;
66
70
  return z;
67
71
  }
72
+ /**
73
+ * Find the maximum node in this subtree.
74
+ * @returns {SplayTreeNode} The rightmost node.
75
+ */
68
76
  getMax() {
69
77
  let z = this;
70
78
  while (z.right) z = z.right;
@@ -72,7 +80,9 @@ export class SplayTreeNode {
72
80
  }
73
81
  }
74
82
 
83
+ /** Self-adjusting binary search tree. */
75
84
  export class SplayTree {
85
+ /** @param {object} [options] - Ordering options (`less`, `compare`). */
76
86
  constructor(options) {
77
87
  copyOptions(this, SplayTree.defaults, options);
78
88
  if (typeof this.compare == 'function') {
@@ -84,18 +94,33 @@ export class SplayTree {
84
94
  this.root = null;
85
95
  this.size = 0;
86
96
  }
97
+ /** Whether the tree has no nodes. */
87
98
  get isEmpty() {
88
99
  return !this.root;
89
100
  }
101
+ /** The number of nodes. */
90
102
  get length() {
91
103
  return this.size;
92
104
  }
105
+ /**
106
+ * Get the node with the minimum value.
107
+ * @returns {SplayTreeNode} The minimum node.
108
+ */
93
109
  getMin() {
94
110
  return this.root.getMin();
95
111
  }
112
+ /**
113
+ * Get the node with the maximum value.
114
+ * @returns {SplayTreeNode} The maximum node.
115
+ */
96
116
  getMax() {
97
117
  return this.root.getMax();
98
118
  }
119
+ /**
120
+ * Find a node by value.
121
+ * @param {*} value - Value to search for.
122
+ * @returns {SplayTreeNode|null} The found node, or `null`.
123
+ */
99
124
  find(value) {
100
125
  for (let z = this.root; z; ) {
101
126
  if (this.less(z.value, value)) z = z.right;
@@ -104,6 +129,11 @@ export class SplayTree {
104
129
  }
105
130
  return null;
106
131
  }
132
+ /**
133
+ * Find a node by value using `compare`.
134
+ * @param {*} value - Value to search for.
135
+ * @returns {SplayTreeNode|null} The found node, or `null`.
136
+ */
107
137
  findWithCompare(value) {
108
138
  for (let z = this.root; z; ) {
109
139
  const cmp = this.compare(value, z.value);
@@ -113,6 +143,11 @@ export class SplayTree {
113
143
  }
114
144
  return null;
115
145
  }
146
+ /**
147
+ * Find a value and splay it to the root.
148
+ * @param {*} value - Value to promote.
149
+ * @returns {SplayTreeNode|null} The found node, or `null`.
150
+ */
116
151
  promote(value) {
117
152
  const z = this.find(value);
118
153
  if (z) {
@@ -120,10 +155,20 @@ export class SplayTree {
120
155
  }
121
156
  return z;
122
157
  }
158
+ /**
159
+ * Splay a node to the root.
160
+ * @param {SplayTreeNode} node - Node to splay.
161
+ * @returns {SplayTree} `this` for chaining.
162
+ */
123
163
  splay(node) {
124
164
  this.root = splay(node);
125
165
  return this;
126
166
  }
167
+ /**
168
+ * Insert a value. If it already exists, splay the existing node.
169
+ * @param {*} value - Value to insert.
170
+ * @returns {SplayTree} `this` for chaining.
171
+ */
127
172
  insert(value) {
128
173
  let z = this.root,
129
174
  parent = null;
@@ -145,6 +190,11 @@ export class SplayTree {
145
190
  this.root = splay(z);
146
191
  return this;
147
192
  }
193
+ /**
194
+ * Insert a value using `compare`. If it already exists, splay the existing node.
195
+ * @param {*} value - Value to insert.
196
+ * @returns {SplayTree} `this` for chaining.
197
+ */
148
198
  insertWithCompare(value) {
149
199
  let z = this.root,
150
200
  parent = null;
@@ -167,6 +217,11 @@ export class SplayTree {
167
217
  this.root = splay(z);
168
218
  return this;
169
219
  }
220
+ /**
221
+ * Remove a value from the tree.
222
+ * @param {*} value - Value to remove.
223
+ * @returns {SplayTree} `this` for chaining.
224
+ */
170
225
  remove(value) {
171
226
  const z = this.find(value);
172
227
  if (!z) return this;
@@ -190,11 +245,20 @@ export class SplayTree {
190
245
 
191
246
  return this;
192
247
  }
248
+ /**
249
+ * Remove all nodes.
250
+ * @returns {SplayTree} `this` for chaining.
251
+ */
193
252
  clear() {
194
253
  this.root = null;
195
254
  this.size = 0;
196
255
  return this;
197
256
  }
257
+ /**
258
+ * Split the tree: keep nodes ≤ value, return a new tree with nodes > value.
259
+ * @param {*} value - Split point.
260
+ * @returns {SplayTree} A new SplayTree with the greater nodes.
261
+ */
198
262
  splitMaxTree(value) {
199
263
  if (!this.root) return new SplayTree(this);
200
264
  let z = this.root,
@@ -234,6 +298,11 @@ export class SplayTree {
234
298
  }
235
299
  return newTree;
236
300
  }
301
+ /**
302
+ * Split the tree using `compare`: keep nodes ≤ value, return a new tree with nodes > value.
303
+ * @param {*} value - Split point.
304
+ * @returns {SplayTree} A new SplayTree with the greater nodes.
305
+ */
237
306
  splitMaxTreeWithCompare(value) {
238
307
  if (!this.root) return new SplayTree(this);
239
308
  let z = this.root,
@@ -274,6 +343,11 @@ export class SplayTree {
274
343
  }
275
344
  return newTree;
276
345
  }
346
+ /**
347
+ * Join a tree whose values are all greater than this tree's maximum (unsafe: no validation).
348
+ * @param {SplayTree} tree - Tree to join (consumed).
349
+ * @returns {SplayTree} `this` for chaining.
350
+ */
277
351
  joinMaxTreeUnsafe(tree) {
278
352
  if (this.root.right) {
279
353
  this.splay(this.getMax());
@@ -287,6 +361,11 @@ export class SplayTree {
287
361
 
288
362
  return this;
289
363
  }
364
+ /**
365
+ * Join another tree into this one. Uses fast path if ranges don't overlap.
366
+ * @param {SplayTree} tree - Tree to join (consumed).
367
+ * @returns {SplayTree} `this` for chaining.
368
+ */
290
369
  join(tree) {
291
370
  if (!tree.root) return this;
292
371
  if (!this.root) {
@@ -296,7 +375,8 @@ export class SplayTree {
296
375
  return this;
297
376
  }
298
377
 
299
- const leftMax = this.getMax(), rightMin = tree.getMin();
378
+ const leftMax = this.getMax(),
379
+ rightMin = tree.getMin();
300
380
  if (this.less(leftMax.value, rightMin.value)) {
301
381
  return this.splay(leftMax).joinMaxTreeUnsafe(tree);
302
382
  }
@@ -308,6 +388,7 @@ export class SplayTree {
308
388
  tree.clear();
309
389
  return this;
310
390
  }
391
+ /** Iterate over values in ascending order. */
311
392
  [Symbol.iterator]() {
312
393
  let current = this.root ? this.root.getMin() : null;
313
394
  return {
@@ -334,6 +415,10 @@ export class SplayTree {
334
415
  }
335
416
  };
336
417
  }
418
+ /**
419
+ * Get an iterable over values in descending order.
420
+ * @returns {Iterable} An iterable iterator of values.
421
+ */
337
422
  getReverseIterator() {
338
423
  return {
339
424
  [Symbol.iterator]: () => {
@@ -364,6 +449,12 @@ export class SplayTree {
364
449
  }
365
450
  };
366
451
  }
452
+ /**
453
+ * Build a SplayTree from an iterable.
454
+ * @param {Iterable} values - Values to insert.
455
+ * @param {object} [options] - Ordering options.
456
+ * @returns {SplayTree} A new SplayTree.
457
+ */
367
458
  static from(values, options) {
368
459
  const tree = new SplayTree(options);
369
460
  for (const value of values) {
@@ -0,0 +1,3 @@
1
+ export * from './list/value.js';
2
+ import ValueList from './list/value.js';
3
+ export default ValueList;
package/src/value-list.js CHANGED
@@ -1,5 +1,3 @@
1
- 'use strict';
2
-
3
1
  export * from './list/value.js';
4
2
  import ValueList from './list/value.js';
5
3
 
@@ -0,0 +1,3 @@
1
+ export * from './slist/value.js';
2
+ import ValueSList from './slist/value.js';
3
+ export default ValueSList;
@@ -1,5 +1,3 @@
1
- 'use strict';
2
-
3
1
  export * from './slist/value.js';
4
2
  import ValueSList from './slist/value.js';
5
3
 
@@ -1,37 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = exports.CacheFIFO = void 0;
7
- var _cacheLru = _interopRequireDefault(require("./cache-lru.js"));
8
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
- // Evicts on the first-in-first-out basis.
10
-
11
- class CacheFIFO extends _cacheLru.default {
12
- use(key) {
13
- return this.dict.get(key);
14
- }
15
- addNew(key, value) {
16
- this.list.pushBack({
17
- key,
18
- value
19
- });
20
- const node = this.list.back;
21
- this.dict.set(key, node);
22
- return node;
23
- }
24
- evictAndReplace(key, value) {
25
- const node = this.list.front;
26
- this.list.moveToBack(node);
27
- this.dict.delete(node.value.key);
28
- this.dict.set(key, node);
29
- node.value = {
30
- key,
31
- value
32
- };
33
- return node;
34
- }
35
- }
36
- exports.CacheFIFO = CacheFIFO;
37
- var _default = exports.default = CacheFIFO;
@@ -1,76 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = exports.CacheLFU = void 0;
7
- var _metaUtils = require("../meta-utils.js");
8
- var _minHeap = _interopRequireDefault(require("../heap/min-heap.js"));
9
- var _cacheLru = _interopRequireDefault(require("./cache-lru.js"));
10
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
- // Evicts the least frequently used items.
12
-
13
- class CacheLFU extends _cacheLru.default {
14
- constructor(capacity = 10) {
15
- super(capacity);
16
- this.heap = new _minHeap.default({
17
- less: (a, b) => a.value.counter < b.value.counter
18
- });
19
- }
20
- use(key) {
21
- const node = this.dict.get(key);
22
- if (node) ++node.value.counter;
23
- return node;
24
- }
25
- update(node, value) {
26
- node.value.counter = 1;
27
- node.value.value = value;
28
- return this;
29
- }
30
- addNew(key, value) {
31
- this.list.pushFront({
32
- key,
33
- value,
34
- counter: 1
35
- });
36
- const node = this.list.front;
37
- this.dict.set(key, node);
38
- this.heap.push(node);
39
- return node;
40
- }
41
- evictAndReplace(key, value) {
42
- const node = this.heap.top;
43
- this.dict.delete(node.value.key);
44
- node.value = {
45
- key,
46
- value,
47
- counter: 1
48
- };
49
- this.dict.set(key, node);
50
- this.heap.updateTop();
51
- return node;
52
- }
53
- remove(key) {
54
- const node = this.dict.get(key);
55
- if (node) {
56
- this.dict.delete(key);
57
- this.list.removeNode(node);
58
- this.heap.remove(node);
59
- }
60
- return this;
61
- }
62
- clear() {
63
- super.clear();
64
- this.heap.clear();
65
- return this;
66
- }
67
- resetCounters(initialValue = 1) {
68
- for (const item of this.heap) {
69
- item.counter = initialValue;
70
- }
71
- return this;
72
- }
73
- }
74
- exports.CacheLFU = CacheLFU;
75
- (0, _metaUtils.addAlias)(CacheLFU.prototype, 'remove', 'delete');
76
- var _default = exports.default = CacheLFU;
@@ -1,100 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = exports.CacheLRU = void 0;
7
- var _valueList = _interopRequireDefault(require("../value-list.js"));
8
- var _metaUtils = require("../meta-utils.js");
9
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
- // The base cache class. Evicts the least recently used items.
11
- // Based on doubly linked value lists.
12
-
13
- class CacheLRU {
14
- constructor(capacity = 10) {
15
- this.capacity = capacity;
16
- this.list = new _valueList.default();
17
- this.dict = new Map();
18
- }
19
- get isEmpty() {
20
- return !this.dict.size;
21
- }
22
- get size() {
23
- return this.dict.size;
24
- }
25
- has(key) {
26
- return this.dict.has(key);
27
- }
28
- find(key) {
29
- const node = this.use(key);
30
- return node ? node.value.value : undefined;
31
- }
32
- remove(key) {
33
- const node = this.dict.get(key);
34
- if (node) {
35
- this.dict.delete(key);
36
- this.list.removeNode(node);
37
- }
38
- return this;
39
- }
40
- register(key, value) {
41
- const node = this.use(key);
42
- if (node) {
43
- this.update(node, value);
44
- return this;
45
- }
46
- if (this.dict.size >= this.capacity) {
47
- this.evictAndReplace(key, value);
48
- return this;
49
- }
50
- this.addNew(key, value);
51
- return this;
52
- }
53
- use(key) {
54
- const node = this.dict.get(key);
55
- if (node) this.list.moveToFront(node);
56
- return node;
57
- }
58
- update(node, value) {
59
- node.value.value = value;
60
- return this;
61
- }
62
- addNew(key, value) {
63
- this.list.pushFront({
64
- key,
65
- value
66
- });
67
- const node = this.list.front;
68
- this.dict.set(key, node);
69
- return node;
70
- }
71
- evictAndReplace(key, value) {
72
- const node = this.list.back;
73
- this.list.moveToFront(node);
74
- this.dict.delete(node.value.key);
75
- this.dict.set(key, node);
76
- node.value = {
77
- key,
78
- value
79
- };
80
- return node;
81
- }
82
- clear() {
83
- this.dict.clear();
84
- this.list.clear();
85
- return this;
86
- }
87
- [Symbol.iterator]() {
88
- return this.list[Symbol.iterator]();
89
- }
90
- getReverseIterator() {
91
- return this.list.getReverseIterator();
92
- }
93
- }
94
- exports.CacheLRU = CacheLRU;
95
- (0, _metaUtils.addAliases)(CacheLRU.prototype, {
96
- register: 'add, set',
97
- remove: 'delete',
98
- find: 'get'
99
- });
100
- var _default = exports.default = CacheLRU;
@@ -1,77 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = exports.CacheRandom = void 0;
7
- var _metaUtils = require("../meta-utils.js");
8
- var _minHeap = _interopRequireDefault(require("../heap/min-heap.js"));
9
- var _cacheLru = _interopRequireDefault(require("./cache-lru.js"));
10
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
- // Evicts items randomly.
12
-
13
- class CacheRandom extends _cacheLru.default {
14
- constructor(capacity = 10) {
15
- super(capacity);
16
- this.heap = new _minHeap.default({
17
- less: (a, b) => a.value.id > b.value.id
18
- });
19
- this.nextId = 0;
20
- }
21
- use(key) {
22
- return this.dict.get(key);
23
- }
24
- update(node, value) {
25
- node.value.value = value;
26
- return this;
27
- }
28
- addNew(key, value) {
29
- this.list.pushFront({
30
- key,
31
- value,
32
- id: this.nextId++
33
- });
34
- const node = this.list.front;
35
- this.dict.set(key, node);
36
- this.heap.push(node);
37
- return node;
38
- }
39
- evictAndReplace(key, value) {
40
- const index = Math.floor(this.heap.length * Math.random());
41
- const node = this.heap.array[index],
42
- isDecreased = value > node.value.value;
43
- this.dict.delete(node.value.key);
44
- this.dict.set(key, node);
45
- node.value.key = key;
46
- node.value.value = value;
47
- this.heap.updateByIndex(index, isDecreased);
48
- return node;
49
- }
50
- remove(key) {
51
- const node = this.dict.get(key);
52
- if (node) {
53
- this.dict.delete(key);
54
- this.list.removeNode(node);
55
- this.heap.remove(node);
56
- }
57
- return this;
58
- }
59
- clear() {
60
- super.clear();
61
- this.heap.clear();
62
- this.nextId = 0;
63
- return this;
64
- }
65
- resetIds() {
66
- this.nextId = 0;
67
- for (const item of this.heap) {
68
- item.id = this.nextId++;
69
- }
70
- const array = this.heap.array;
71
- this.heap.clear().merge(array);
72
- return this;
73
- }
74
- }
75
- exports.CacheRandom = CacheRandom;
76
- (0, _metaUtils.addAlias)(CacheRandom.prototype, 'remove', 'delete');
77
- var _default = exports.default = CacheRandom;
@@ -1,47 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getCache = exports.default = exports.decorateMethod = exports.decorateFn = exports.decorate = void 0;
7
- const decorateFn = (fn, cache) => {
8
- if (typeof fn !== 'function') throw new TypeError('Not a function');
9
- const wrapped = function (...args) {
10
- const key = args[0],
11
- cache = wrapped.cache;
12
- if (cache.has(key)) return cache.get(key);
13
- const result = wrapped.fn.apply(this, args);
14
- cache.set(key, result);
15
- return result;
16
- };
17
- wrapped.fn = fn;
18
- wrapped.cache = cache;
19
- return wrapped;
20
- };
21
- exports.decorateFn = decorateFn;
22
- const decorate = (object, key, cache) => {
23
- const descriptor = Object.getOwnPropertyDescriptor(object, key);
24
- if (!descriptor) throw new Error('Missing property: ' + key);
25
- const newDescriptor = {
26
- ...descriptor
27
- },
28
- wrapped = decorateFn(descriptor.value, cache);
29
- newDescriptor.value = wrapped;
30
- Object.defineProperty(object, key, newDescriptor);
31
- return wrapped;
32
- };
33
- exports.decorate = decorate;
34
- const decorateMethod = (object, key, cache) => {
35
- const fn = object[key],
36
- wrapped = decorateFn(fn, cache);
37
- object[key] = wrapped;
38
- return wrapped;
39
- };
40
- exports.decorateMethod = decorateMethod;
41
- const getCache = (object, key) => {
42
- const descriptor = Object.getOwnPropertyDescriptor(object, key);
43
- if (!descriptor) throw new Error('Missing property: ' + key);
44
- return descriptor.value.cache;
45
- };
46
- exports.getCache = getCache;
47
- var _default = exports.default = decorate;
package/cjs/cache.js DELETED
@@ -1,27 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _exportNames = {
7
- cacheDecorator: true
8
- };
9
- exports.default = exports.cacheDecorator = void 0;
10
- var _cacheLru = _interopRequireWildcard(require("./cache/cache-lru.js"));
11
- Object.keys(_cacheLru).forEach(function (key) {
12
- if (key === "default" || key === "__esModule") return;
13
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
14
- if (key in exports && exports[key] === _cacheLru[key]) return;
15
- Object.defineProperty(exports, key, {
16
- enumerable: true,
17
- get: function () {
18
- return _cacheLru[key];
19
- }
20
- });
21
- });
22
- var _decorator = _interopRequireDefault(require("./cache/decorator.js"));
23
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
24
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
25
- const cacheDecorator = (object, key, cache = new _cacheLru.default()) => (0, _decorator.default)(object, key, cache);
26
- exports.cacheDecorator = cacheDecorator;
27
- var _default = exports.default = _cacheLru.default;
package/cjs/ext-list.js DELETED
@@ -1,21 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _exportNames = {};
7
- exports.default = void 0;
8
- var _ext = _interopRequireWildcard(require("./list/ext.js"));
9
- Object.keys(_ext).forEach(function (key) {
10
- if (key === "default" || key === "__esModule") return;
11
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
12
- if (key in exports && exports[key] === _ext[key]) return;
13
- Object.defineProperty(exports, key, {
14
- enumerable: true,
15
- get: function () {
16
- return _ext[key];
17
- }
18
- });
19
- });
20
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
21
- var _default = exports.default = _ext.default;
package/cjs/ext-slist.js DELETED
@@ -1,21 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _exportNames = {};
7
- exports.default = void 0;
8
- var _ext = _interopRequireWildcard(require("./slist/ext.js"));
9
- Object.keys(_ext).forEach(function (key) {
10
- if (key === "default" || key === "__esModule") return;
11
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
12
- if (key in exports && exports[key] === _ext[key]) return;
13
- Object.defineProperty(exports, key, {
14
- enumerable: true,
15
- get: function () {
16
- return _ext[key];
17
- }
18
- });
19
- });
20
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
21
- var _default = exports.default = _ext.default;
@@ -1,21 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _exportNames = {};
7
- exports.default = void 0;
8
- var _extValue = _interopRequireWildcard(require("./list/ext-value.js"));
9
- Object.keys(_extValue).forEach(function (key) {
10
- if (key === "default" || key === "__esModule") return;
11
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
12
- if (key in exports && exports[key] === _extValue[key]) return;
13
- Object.defineProperty(exports, key, {
14
- enumerable: true,
15
- get: function () {
16
- return _extValue[key];
17
- }
18
- });
19
- });
20
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
21
- var _default = exports.default = _extValue.default;