data-structure-typed 1.51.9 → 1.52.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/CHANGELOG.md +1 -1
- package/README.md +13 -13
- package/benchmark/report.html +37 -1
- package/benchmark/report.json +385 -13
- package/dist/cjs/data-structures/base/index.d.ts +2 -1
- package/dist/cjs/data-structures/base/index.js +2 -1
- package/dist/cjs/data-structures/base/index.js.map +1 -1
- package/dist/cjs/data-structures/base/iterable-element-base.d.ts +171 -0
- package/dist/cjs/data-structures/base/iterable-element-base.js +226 -0
- package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -0
- package/dist/cjs/data-structures/base/{iterable-base.d.ts → iterable-entry-base.d.ts} +4 -147
- package/dist/cjs/data-structures/base/{iterable-base.js → iterable-entry-base.js} +13 -190
- package/dist/cjs/data-structures/base/iterable-entry-base.js.map +1 -0
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +3 -3
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +3 -3
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +4 -4
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +5 -3
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +3 -11
- package/dist/cjs/data-structures/binary-tree/bst.js +2 -10
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +3 -3
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +3 -3
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +2 -2
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +43 -114
- package/dist/cjs/data-structures/heap/heap.js +59 -127
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/max-heap.d.ts +50 -4
- package/dist/cjs/data-structures/heap/max-heap.js +76 -10
- package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/min-heap.d.ts +51 -5
- package/dist/cjs/data-structures/heap/min-heap.js +68 -11
- package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +22 -28
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +26 -28
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +22 -25
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +29 -26
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +50 -4
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +79 -10
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +51 -5
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +71 -11
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +50 -4
- package/dist/cjs/data-structures/priority-queue/priority-queue.js +70 -1
- package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +20 -18
- package/dist/cjs/data-structures/queue/deque.js +27 -20
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +8 -28
- package/dist/cjs/data-structures/queue/queue.js +15 -31
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/stack/stack.d.ts +17 -22
- package/dist/cjs/data-structures/stack/stack.js +25 -24
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +18 -13
- package/dist/cjs/data-structures/trie/trie.js +26 -15
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +2 -2
- package/dist/cjs/types/data-structures/base/base.d.ts +5 -2
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -3
- package/dist/cjs/types/data-structures/binary-tree/avl-tree.d.ts +2 -3
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +2 -3
- package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +2 -3
- package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +2 -3
- package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -3
- package/dist/cjs/types/data-structures/heap/heap.d.ts +3 -2
- package/dist/cjs/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
- package/dist/cjs/types/data-structures/linked-list/singly-linked-list.d.ts +2 -1
- package/dist/cjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/cjs/types/data-structures/queue/deque.d.ts +3 -2
- package/dist/cjs/types/data-structures/queue/queue.d.ts +2 -1
- package/dist/cjs/types/data-structures/stack/stack.d.ts +2 -1
- package/dist/cjs/types/data-structures/trie/trie.d.ts +3 -2
- package/dist/mjs/data-structures/base/index.d.ts +2 -1
- package/dist/mjs/data-structures/base/index.js +2 -1
- package/dist/mjs/data-structures/base/iterable-element-base.d.ts +171 -0
- package/dist/mjs/data-structures/base/iterable-element-base.js +222 -0
- package/dist/mjs/data-structures/base/{iterable-base.d.ts → iterable-entry-base.d.ts} +4 -147
- package/dist/mjs/data-structures/base/{iterable-base.js → iterable-entry-base.js} +10 -186
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +3 -3
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +3 -3
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +4 -4
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +5 -3
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +3 -11
- package/dist/mjs/data-structures/binary-tree/bst.js +2 -10
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +3 -3
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +3 -3
- package/dist/mjs/data-structures/hash/hash-map.d.ts +2 -2
- package/dist/mjs/data-structures/heap/heap.d.ts +43 -114
- package/dist/mjs/data-structures/heap/heap.js +60 -128
- package/dist/mjs/data-structures/heap/max-heap.d.ts +50 -4
- package/dist/mjs/data-structures/heap/max-heap.js +79 -10
- package/dist/mjs/data-structures/heap/min-heap.d.ts +51 -5
- package/dist/mjs/data-structures/heap/min-heap.js +68 -11
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +22 -28
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +26 -28
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +22 -25
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +29 -26
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.d.ts +50 -4
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +82 -10
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.d.ts +51 -5
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +71 -11
- package/dist/mjs/data-structures/priority-queue/priority-queue.d.ts +50 -4
- package/dist/mjs/data-structures/priority-queue/priority-queue.js +70 -1
- package/dist/mjs/data-structures/queue/deque.d.ts +20 -18
- package/dist/mjs/data-structures/queue/deque.js +27 -20
- package/dist/mjs/data-structures/queue/queue.d.ts +8 -28
- package/dist/mjs/data-structures/queue/queue.js +15 -31
- package/dist/mjs/data-structures/stack/stack.d.ts +17 -22
- package/dist/mjs/data-structures/stack/stack.js +25 -24
- package/dist/mjs/data-structures/trie/trie.d.ts +18 -13
- package/dist/mjs/data-structures/trie/trie.js +26 -15
- package/dist/mjs/interfaces/binary-tree.d.ts +2 -2
- package/dist/mjs/types/data-structures/base/base.d.ts +5 -2
- package/dist/mjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -3
- package/dist/mjs/types/data-structures/binary-tree/avl-tree.d.ts +2 -3
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +2 -3
- package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +2 -3
- package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +2 -3
- package/dist/mjs/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -3
- package/dist/mjs/types/data-structures/heap/heap.d.ts +3 -2
- package/dist/mjs/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
- package/dist/mjs/types/data-structures/linked-list/singly-linked-list.d.ts +2 -1
- package/dist/mjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/mjs/types/data-structures/queue/deque.d.ts +3 -2
- package/dist/mjs/types/data-structures/queue/queue.d.ts +2 -1
- package/dist/mjs/types/data-structures/stack/stack.d.ts +2 -1
- package/dist/mjs/types/data-structures/trie/trie.d.ts +3 -2
- package/dist/umd/data-structure-typed.js +628 -319
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +6 -6
- package/src/data-structures/base/index.ts +2 -1
- package/src/data-structures/base/iterable-element-base.ts +250 -0
- package/src/data-structures/base/{iterable-base.ts → iterable-entry-base.ts} +22 -213
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +2 -3
- package/src/data-structures/binary-tree/avl-tree.ts +2 -3
- package/src/data-structures/binary-tree/binary-tree.ts +6 -6
- package/src/data-structures/binary-tree/bst.ts +8 -19
- package/src/data-structures/binary-tree/rb-tree.ts +2 -3
- package/src/data-structures/binary-tree/tree-multi-map.ts +2 -3
- package/src/data-structures/hash/hash-map.ts +4 -4
- package/src/data-structures/heap/heap.ts +71 -152
- package/src/data-structures/heap/max-heap.ts +88 -13
- package/src/data-structures/heap/min-heap.ts +78 -15
- package/src/data-structures/linked-list/doubly-linked-list.ts +32 -32
- package/src/data-structures/linked-list/singly-linked-list.ts +37 -29
- package/src/data-structures/priority-queue/max-priority-queue.ts +94 -13
- package/src/data-structures/priority-queue/min-priority-queue.ts +84 -15
- package/src/data-structures/priority-queue/priority-queue.ts +81 -4
- package/src/data-structures/queue/deque.ts +35 -24
- package/src/data-structures/queue/queue.ts +23 -36
- package/src/data-structures/stack/stack.ts +31 -26
- package/src/data-structures/trie/trie.ts +33 -18
- package/src/interfaces/binary-tree.ts +1 -2
- package/src/types/data-structures/base/base.ts +14 -6
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +2 -3
- package/src/types/data-structures/binary-tree/avl-tree.ts +2 -3
- package/src/types/data-structures/binary-tree/binary-tree.ts +3 -4
- package/src/types/data-structures/binary-tree/bst.ts +2 -3
- package/src/types/data-structures/binary-tree/rb-tree.ts +2 -3
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +2 -3
- package/src/types/data-structures/heap/heap.ts +4 -1
- package/src/types/data-structures/linked-list/doubly-linked-list.ts +3 -1
- package/src/types/data-structures/linked-list/singly-linked-list.ts +3 -1
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -1
- package/src/types/data-structures/queue/deque.ts +3 -1
- package/src/types/data-structures/queue/queue.ts +3 -1
- package/src/types/data-structures/stack/stack.ts +3 -1
- package/src/types/data-structures/trie/trie.ts +3 -1
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +1 -1
- package/test/unit/data-structures/heap/heap.test.ts +80 -0
- package/test/unit/data-structures/heap/max-heap.test.ts +44 -1
- package/test/unit/data-structures/heap/min-heap.test.ts +18 -1
- package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +42 -0
- package/test/unit/data-structures/queue/deque.test.ts +30 -0
- package/test/unit/data-structures/queue/queue.test.ts +56 -0
- package/dist/cjs/data-structures/base/iterable-base.js.map +0 -1
|
@@ -173,8 +173,17 @@ var dataStructureTyped = (() => {
|
|
|
173
173
|
uuidV4: () => uuidV4
|
|
174
174
|
});
|
|
175
175
|
|
|
176
|
-
// src/data-structures/base/iterable-base.ts
|
|
176
|
+
// src/data-structures/base/iterable-entry-base.ts
|
|
177
177
|
var IterableEntryBase = class {
|
|
178
|
+
// protected _toEntryFn?: (rawElement: R) => BTNEntry<K, V>;
|
|
179
|
+
//
|
|
180
|
+
// /**
|
|
181
|
+
// * The function returns the value of the _toEntryFn property.
|
|
182
|
+
// * @returns The function being returned is `this._toEntryFn`.
|
|
183
|
+
// */
|
|
184
|
+
// get toEntryFn() {
|
|
185
|
+
// return this._toEntryFn;
|
|
186
|
+
// }
|
|
178
187
|
/**
|
|
179
188
|
* Time Complexity: O(n)
|
|
180
189
|
* Space Complexity: O(1)
|
|
@@ -439,11 +448,44 @@ var dataStructureTyped = (() => {
|
|
|
439
448
|
* Time Complexity: O(n)
|
|
440
449
|
* Space Complexity: O(n)
|
|
441
450
|
*/
|
|
451
|
+
/**
|
|
452
|
+
* Time Complexity: O(n)
|
|
453
|
+
* Space Complexity: O(n)
|
|
454
|
+
*
|
|
455
|
+
* The print function logs the elements of an array to the console.
|
|
456
|
+
*/
|
|
442
457
|
print() {
|
|
443
458
|
console.log([...this]);
|
|
444
459
|
}
|
|
445
460
|
};
|
|
461
|
+
|
|
462
|
+
// src/data-structures/base/iterable-element-base.ts
|
|
446
463
|
var IterableElementBase = class {
|
|
464
|
+
/**
|
|
465
|
+
* The protected constructor initializes the options for the IterableElementBase class, including the
|
|
466
|
+
* toElementFn function.
|
|
467
|
+
* @param [options] - An optional object that contains the following properties:
|
|
468
|
+
*/
|
|
469
|
+
constructor(options) {
|
|
470
|
+
__publicField(this, "_toElementFn");
|
|
471
|
+
if (options) {
|
|
472
|
+
const { toElementFn } = options;
|
|
473
|
+
if (typeof toElementFn === "function")
|
|
474
|
+
this._toElementFn = toElementFn;
|
|
475
|
+
else if (toElementFn)
|
|
476
|
+
throw new TypeError("toElementFn must be a function type");
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* The function returns the _toElementFn property, which is a function that converts a raw element to
|
|
481
|
+
* a specific type.
|
|
482
|
+
* @returns The function `get toElementFn()` is returning either a function that takes a raw element
|
|
483
|
+
* `rawElement` of type `R` and returns an element `E`, or `undefined` if no function is assigned to
|
|
484
|
+
* `_toElementFn`.
|
|
485
|
+
*/
|
|
486
|
+
get toElementFn() {
|
|
487
|
+
return this._toElementFn;
|
|
488
|
+
}
|
|
447
489
|
/**
|
|
448
490
|
* Time Complexity: O(n)
|
|
449
491
|
* Space Complexity: O(1)
|
|
@@ -630,6 +672,12 @@ var dataStructureTyped = (() => {
|
|
|
630
672
|
* Time Complexity: O(n)
|
|
631
673
|
* Space Complexity: O(n)
|
|
632
674
|
*/
|
|
675
|
+
/**
|
|
676
|
+
* Time Complexity: O(n)
|
|
677
|
+
* Space Complexity: O(n)
|
|
678
|
+
*
|
|
679
|
+
* The print function logs the elements of an array to the console.
|
|
680
|
+
*/
|
|
633
681
|
print() {
|
|
634
682
|
console.log([...this]);
|
|
635
683
|
}
|
|
@@ -1641,20 +1689,19 @@ var dataStructureTyped = (() => {
|
|
|
1641
1689
|
}
|
|
1642
1690
|
};
|
|
1643
1691
|
var SinglyLinkedList = class _SinglyLinkedList extends IterableElementBase {
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
* @param elements - The `elements` parameter is an optional iterable object that contains the
|
|
1647
|
-
* initial elements to be added to the instance of the class. If no `elements` are provided, an empty
|
|
1648
|
-
* array will be used as the default value.
|
|
1649
|
-
*/
|
|
1650
|
-
constructor(elements = []) {
|
|
1651
|
-
super();
|
|
1692
|
+
constructor(elements = [], options) {
|
|
1693
|
+
super(options);
|
|
1652
1694
|
__publicField(this, "_head");
|
|
1653
1695
|
__publicField(this, "_tail");
|
|
1654
1696
|
__publicField(this, "_size", 0);
|
|
1655
1697
|
if (elements) {
|
|
1656
|
-
for (const el of elements)
|
|
1657
|
-
this.
|
|
1698
|
+
for (const el of elements) {
|
|
1699
|
+
if (this.toElementFn) {
|
|
1700
|
+
this.push(this.toElementFn(el));
|
|
1701
|
+
} else {
|
|
1702
|
+
this.push(el);
|
|
1703
|
+
}
|
|
1704
|
+
}
|
|
1658
1705
|
}
|
|
1659
1706
|
}
|
|
1660
1707
|
/**
|
|
@@ -2199,7 +2246,7 @@ var dataStructureTyped = (() => {
|
|
|
2199
2246
|
* is a clone of the original list.
|
|
2200
2247
|
*/
|
|
2201
2248
|
clone() {
|
|
2202
|
-
return new _SinglyLinkedList(this.
|
|
2249
|
+
return new _SinglyLinkedList(this, { toElementFn: this.toElementFn });
|
|
2203
2250
|
}
|
|
2204
2251
|
/**
|
|
2205
2252
|
* Time Complexity: O(n)
|
|
@@ -2223,7 +2270,7 @@ var dataStructureTyped = (() => {
|
|
|
2223
2270
|
* elements that pass the filter condition specified by the `callback` function.
|
|
2224
2271
|
*/
|
|
2225
2272
|
filter(callback, thisArg) {
|
|
2226
|
-
const filteredList = new _SinglyLinkedList();
|
|
2273
|
+
const filteredList = new _SinglyLinkedList([], { toElementFn: this.toElementFn });
|
|
2227
2274
|
let index = 0;
|
|
2228
2275
|
for (const current of this) {
|
|
2229
2276
|
if (callback.call(thisArg, current, index, this)) {
|
|
@@ -2238,21 +2285,24 @@ var dataStructureTyped = (() => {
|
|
|
2238
2285
|
* Space Complexity: O(n)
|
|
2239
2286
|
*/
|
|
2240
2287
|
/**
|
|
2241
|
-
*
|
|
2242
|
-
*
|
|
2243
|
-
*
|
|
2244
|
-
* The `map` function creates a new SinglyLinkedList by applying a callback function to each element
|
|
2245
|
-
* of the original list.
|
|
2288
|
+
* The `map` function takes a callback function and returns a new SinglyLinkedList with the results
|
|
2289
|
+
* of applying the callback to each element in the original list.
|
|
2246
2290
|
* @param callback - The `callback` parameter is a function that will be called for each element in
|
|
2247
|
-
* the
|
|
2248
|
-
*
|
|
2249
|
-
*
|
|
2250
|
-
*
|
|
2251
|
-
*
|
|
2252
|
-
*
|
|
2291
|
+
* the original list. It takes three arguments: `current` (the current element being processed),
|
|
2292
|
+
* `index` (the index of the current element), and `this` (the original list). It should return a
|
|
2293
|
+
* value
|
|
2294
|
+
* @param [toElementFn] - The `toElementFn` parameter is an optional function that can be used to
|
|
2295
|
+
* convert the raw element (`RR`) to the desired element type (`T`). It takes the raw element as
|
|
2296
|
+
* input and returns the converted element. If this parameter is not provided, the raw element will
|
|
2297
|
+
* be used as is.
|
|
2298
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
|
|
2299
|
+
* specify the value of `this` within the callback function. It is used to set the context or scope
|
|
2300
|
+
* in which the callback function will be executed. If `thisArg` is provided, it will be used as the
|
|
2301
|
+
* value of
|
|
2302
|
+
* @returns a new instance of the `SinglyLinkedList` class with the mapped elements.
|
|
2253
2303
|
*/
|
|
2254
|
-
map(callback, thisArg) {
|
|
2255
|
-
const mappedList = new _SinglyLinkedList();
|
|
2304
|
+
map(callback, toElementFn, thisArg) {
|
|
2305
|
+
const mappedList = new _SinglyLinkedList([], { toElementFn });
|
|
2256
2306
|
let index = 0;
|
|
2257
2307
|
for (const current of this) {
|
|
2258
2308
|
mappedList.push(callback.call(thisArg, current, index, this));
|
|
@@ -2337,14 +2387,8 @@ var dataStructureTyped = (() => {
|
|
|
2337
2387
|
}
|
|
2338
2388
|
};
|
|
2339
2389
|
var DoublyLinkedList = class _DoublyLinkedList extends IterableElementBase {
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
* @param elements - The `elements` parameter is an optional iterable object that contains the
|
|
2343
|
-
* initial elements to be added to the data structure. It defaults to an empty array if no elements
|
|
2344
|
-
* are provided.
|
|
2345
|
-
*/
|
|
2346
|
-
constructor(elements = []) {
|
|
2347
|
-
super();
|
|
2390
|
+
constructor(elements = [], options) {
|
|
2391
|
+
super(options);
|
|
2348
2392
|
__publicField(this, "_head");
|
|
2349
2393
|
__publicField(this, "_tail");
|
|
2350
2394
|
__publicField(this, "_size");
|
|
@@ -2353,7 +2397,10 @@ var dataStructureTyped = (() => {
|
|
|
2353
2397
|
this._size = 0;
|
|
2354
2398
|
if (elements) {
|
|
2355
2399
|
for (const el of elements) {
|
|
2356
|
-
this.
|
|
2400
|
+
if (this.toElementFn) {
|
|
2401
|
+
this.push(this.toElementFn(el));
|
|
2402
|
+
} else
|
|
2403
|
+
this.push(el);
|
|
2357
2404
|
}
|
|
2358
2405
|
}
|
|
2359
2406
|
}
|
|
@@ -2924,7 +2971,7 @@ var dataStructureTyped = (() => {
|
|
|
2924
2971
|
* is a copy of the original list.
|
|
2925
2972
|
*/
|
|
2926
2973
|
clone() {
|
|
2927
|
-
return new _DoublyLinkedList(this
|
|
2974
|
+
return new _DoublyLinkedList(this);
|
|
2928
2975
|
}
|
|
2929
2976
|
/**
|
|
2930
2977
|
* Time Complexity: O(n)
|
|
@@ -2948,7 +2995,7 @@ var dataStructureTyped = (() => {
|
|
|
2948
2995
|
* elements that pass the filter condition specified by the `callback` function.
|
|
2949
2996
|
*/
|
|
2950
2997
|
filter(callback, thisArg) {
|
|
2951
|
-
const filteredList = new _DoublyLinkedList();
|
|
2998
|
+
const filteredList = new _DoublyLinkedList([], { toElementFn: this.toElementFn });
|
|
2952
2999
|
let index = 0;
|
|
2953
3000
|
for (const current of this) {
|
|
2954
3001
|
if (callback.call(thisArg, current, index, this)) {
|
|
@@ -2963,24 +3010,24 @@ var dataStructureTyped = (() => {
|
|
|
2963
3010
|
* Space Complexity: O(n)
|
|
2964
3011
|
*/
|
|
2965
3012
|
/**
|
|
2966
|
-
*
|
|
2967
|
-
*
|
|
2968
|
-
*
|
|
2969
|
-
* The `map` function creates a new DoublyLinkedList by applying a callback function to each element
|
|
2970
|
-
* in the original list.
|
|
3013
|
+
* The `map` function takes a callback function and returns a new DoublyLinkedList with the results
|
|
3014
|
+
* of applying the callback to each element in the original list.
|
|
2971
3015
|
* @param callback - The callback parameter is a function that will be called for each element in the
|
|
2972
|
-
* DoublyLinkedList. It takes three arguments:
|
|
2973
|
-
*
|
|
2974
|
-
*
|
|
2975
|
-
* @param
|
|
2976
|
-
*
|
|
2977
|
-
*
|
|
2978
|
-
*
|
|
2979
|
-
*
|
|
2980
|
-
*
|
|
3016
|
+
* original DoublyLinkedList. It takes three arguments: current (the current element being
|
|
3017
|
+
* processed), index (the index of the current element), and this (the original DoublyLinkedList).
|
|
3018
|
+
* The callback function should return a value of type
|
|
3019
|
+
* @param [toElementFn] - The `toElementFn` parameter is an optional function that can be used to
|
|
3020
|
+
* convert the raw element (`RR`) to the desired element type (`T`). It takes the raw element as
|
|
3021
|
+
* input and returns the converted element. If this parameter is not provided, the raw element will
|
|
3022
|
+
* be used as is.
|
|
3023
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
|
|
3024
|
+
* specify the value of `this` within the callback function. It is used to set the context or scope
|
|
3025
|
+
* in which the callback function will be executed. If `thisArg` is provided, it will be used as the
|
|
3026
|
+
* value of
|
|
3027
|
+
* @returns a new instance of the `DoublyLinkedList` class with elements of type `T` and `RR`.
|
|
2981
3028
|
*/
|
|
2982
|
-
map(callback, thisArg) {
|
|
2983
|
-
const mappedList = new _DoublyLinkedList();
|
|
3029
|
+
map(callback, toElementFn, thisArg) {
|
|
3030
|
+
const mappedList = new _DoublyLinkedList([], { toElementFn });
|
|
2984
3031
|
let index = 0;
|
|
2985
3032
|
for (const current of this) {
|
|
2986
3033
|
mappedList.push(callback.call(thisArg, current, index, this));
|
|
@@ -3277,18 +3324,17 @@ var dataStructureTyped = (() => {
|
|
|
3277
3324
|
|
|
3278
3325
|
// src/data-structures/stack/stack.ts
|
|
3279
3326
|
var Stack = class _Stack extends IterableElementBase {
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
* @param {E[]} [elements] - The `elements` parameter is an optional parameter of type `E[]`, which represents an array
|
|
3283
|
-
* of elements of type `E`. It is used to initialize the `_elements` property of the class. If the `elements` parameter
|
|
3284
|
-
* is provided and is an array, it is assigned to the `_elements
|
|
3285
|
-
*/
|
|
3286
|
-
constructor(elements = []) {
|
|
3287
|
-
super();
|
|
3327
|
+
constructor(elements = [], options) {
|
|
3328
|
+
super(options);
|
|
3288
3329
|
__publicField(this, "_elements", []);
|
|
3289
3330
|
if (elements) {
|
|
3290
|
-
for (const el of elements)
|
|
3291
|
-
this.
|
|
3331
|
+
for (const el of elements) {
|
|
3332
|
+
if (this.toElementFn) {
|
|
3333
|
+
this.push(this.toElementFn(el));
|
|
3334
|
+
} else {
|
|
3335
|
+
this.push(el);
|
|
3336
|
+
}
|
|
3337
|
+
}
|
|
3292
3338
|
}
|
|
3293
3339
|
}
|
|
3294
3340
|
/**
|
|
@@ -3434,7 +3480,7 @@ var dataStructureTyped = (() => {
|
|
|
3434
3480
|
* @returns The `clone()` method is returning a new `Stack` object with a copy of the `_elements` array.
|
|
3435
3481
|
*/
|
|
3436
3482
|
clone() {
|
|
3437
|
-
return new _Stack(this.
|
|
3483
|
+
return new _Stack(this, { toElementFn: this.toElementFn });
|
|
3438
3484
|
}
|
|
3439
3485
|
/**
|
|
3440
3486
|
* Time Complexity: O(n)
|
|
@@ -3457,7 +3503,7 @@ var dataStructureTyped = (() => {
|
|
|
3457
3503
|
* satisfy the given predicate function.
|
|
3458
3504
|
*/
|
|
3459
3505
|
filter(predicate, thisArg) {
|
|
3460
|
-
const newStack = new _Stack();
|
|
3506
|
+
const newStack = new _Stack([], { toElementFn: this.toElementFn });
|
|
3461
3507
|
let index = 0;
|
|
3462
3508
|
for (const el of this) {
|
|
3463
3509
|
if (predicate.call(thisArg, el, index, this)) {
|
|
@@ -3472,20 +3518,21 @@ var dataStructureTyped = (() => {
|
|
|
3472
3518
|
* Space Complexity: O(n)
|
|
3473
3519
|
*/
|
|
3474
3520
|
/**
|
|
3475
|
-
* Time Complexity: O(n)
|
|
3476
|
-
* Space Complexity: O(n)
|
|
3477
|
-
*
|
|
3478
3521
|
* The `map` function takes a callback function and applies it to each element in the stack,
|
|
3479
3522
|
* returning a new stack with the results.
|
|
3480
|
-
* @param callback - The
|
|
3481
|
-
*
|
|
3482
|
-
*
|
|
3483
|
-
*
|
|
3484
|
-
*
|
|
3485
|
-
* @
|
|
3523
|
+
* @param callback - The callback parameter is a function that will be called for each element in the
|
|
3524
|
+
* stack. It takes three arguments: the current element, the index of the element, and the stack
|
|
3525
|
+
* itself. It should return a new value that will be added to the new stack.
|
|
3526
|
+
* @param [toElementFn] - The `toElementFn` parameter is an optional function that can be used to
|
|
3527
|
+
* transform the raw element (`RM`) into a new element (`EM`) before pushing it into the new stack.
|
|
3528
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
|
|
3529
|
+
* specify the value of `this` within the callback function. It is used to set the context or scope
|
|
3530
|
+
* in which the callback function will be executed. If `thisArg` is provided, it will be used as the
|
|
3531
|
+
* value of
|
|
3532
|
+
* @returns a new Stack object with elements of type EM and raw elements of type RM.
|
|
3486
3533
|
*/
|
|
3487
|
-
map(callback, thisArg) {
|
|
3488
|
-
const newStack = new _Stack();
|
|
3534
|
+
map(callback, toElementFn, thisArg) {
|
|
3535
|
+
const newStack = new _Stack([], { toElementFn });
|
|
3489
3536
|
let index = 0;
|
|
3490
3537
|
for (const el of this) {
|
|
3491
3538
|
newStack.push(callback.call(thisArg, el, index, this));
|
|
@@ -3513,19 +3560,17 @@ var dataStructureTyped = (() => {
|
|
|
3513
3560
|
|
|
3514
3561
|
// src/data-structures/queue/queue.ts
|
|
3515
3562
|
var Queue = class _Queue extends IterableElementBase {
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
* @param {E[]} [elements] - The `elements` parameter is an optional array of elements of type `E`. If provided, it
|
|
3519
|
-
* will be used to initialize the `_elements` property of the class. If not provided, the `_elements` property will be
|
|
3520
|
-
* initialized as an empty array.
|
|
3521
|
-
*/
|
|
3522
|
-
constructor(elements = []) {
|
|
3523
|
-
super();
|
|
3563
|
+
constructor(elements = [], options) {
|
|
3564
|
+
super(options);
|
|
3524
3565
|
__publicField(this, "_elements", []);
|
|
3525
3566
|
__publicField(this, "_offset", 0);
|
|
3526
3567
|
if (elements) {
|
|
3527
|
-
for (const el of elements)
|
|
3528
|
-
this.
|
|
3568
|
+
for (const el of elements) {
|
|
3569
|
+
if (this.toElementFn)
|
|
3570
|
+
this.push(this.toElementFn(el));
|
|
3571
|
+
else
|
|
3572
|
+
this.push(el);
|
|
3573
|
+
}
|
|
3529
3574
|
}
|
|
3530
3575
|
}
|
|
3531
3576
|
/**
|
|
@@ -3665,7 +3710,7 @@ var dataStructureTyped = (() => {
|
|
|
3665
3710
|
* @param index
|
|
3666
3711
|
*/
|
|
3667
3712
|
at(index) {
|
|
3668
|
-
return this.elements[index];
|
|
3713
|
+
return this.elements[index + this._offset];
|
|
3669
3714
|
}
|
|
3670
3715
|
/**
|
|
3671
3716
|
* Time Complexity: O(1)
|
|
@@ -3722,7 +3767,7 @@ var dataStructureTyped = (() => {
|
|
|
3722
3767
|
* @returns The `clone()` method is returning a new instance of the `Queue` class.
|
|
3723
3768
|
*/
|
|
3724
3769
|
clone() {
|
|
3725
|
-
return new _Queue(this.elements.slice(this.offset));
|
|
3770
|
+
return new _Queue(this.elements.slice(this.offset), { toElementFn: this.toElementFn });
|
|
3726
3771
|
}
|
|
3727
3772
|
/**
|
|
3728
3773
|
* Time Complexity: O(n)
|
|
@@ -3745,7 +3790,7 @@ var dataStructureTyped = (() => {
|
|
|
3745
3790
|
* satisfy the given predicate function.
|
|
3746
3791
|
*/
|
|
3747
3792
|
filter(predicate, thisArg) {
|
|
3748
|
-
const newDeque = new _Queue([]);
|
|
3793
|
+
const newDeque = new _Queue([], { toElementFn: this.toElementFn });
|
|
3749
3794
|
let index = 0;
|
|
3750
3795
|
for (const el of this) {
|
|
3751
3796
|
if (predicate.call(thisArg, el, index, this)) {
|
|
@@ -3759,22 +3804,8 @@ var dataStructureTyped = (() => {
|
|
|
3759
3804
|
* Time Complexity: O(n)
|
|
3760
3805
|
* Space Complexity: O(n)
|
|
3761
3806
|
*/
|
|
3762
|
-
|
|
3763
|
-
|
|
3764
|
-
* Space Complexity: O(n)
|
|
3765
|
-
*
|
|
3766
|
-
* The `map` function takes a callback function and applies it to each element in the queue,
|
|
3767
|
-
* returning a new queue with the results.
|
|
3768
|
-
* @param callback - The callback parameter is a function that will be called for each element in the
|
|
3769
|
-
* queue. It takes three arguments: the current element, the index of the current element, and the
|
|
3770
|
-
* queue itself. The callback function should return a new value that will be added to the new queue.
|
|
3771
|
-
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
3772
|
-
* to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
|
|
3773
|
-
* passed as the `this` value to the `callback` function. If `thisArg` is
|
|
3774
|
-
* @returns The `map` function is returning a new `Queue` object with the transformed elements.
|
|
3775
|
-
*/
|
|
3776
|
-
map(callback, thisArg) {
|
|
3777
|
-
const newDeque = new _Queue([]);
|
|
3807
|
+
map(callback, toElementFn, thisArg) {
|
|
3808
|
+
const newDeque = new _Queue([], { toElementFn });
|
|
3778
3809
|
let index = 0;
|
|
3779
3810
|
for (const el of this) {
|
|
3780
3811
|
newDeque.push(callback.call(thisArg, el, index, this));
|
|
@@ -3793,7 +3824,7 @@ var dataStructureTyped = (() => {
|
|
|
3793
3824
|
* The function `_getIterator` returns an iterable iterator for the elements in the class.
|
|
3794
3825
|
*/
|
|
3795
3826
|
*_getIterator() {
|
|
3796
|
-
for (const item of this.elements) {
|
|
3827
|
+
for (const item of this.elements.slice(this.offset)) {
|
|
3797
3828
|
yield item;
|
|
3798
3829
|
}
|
|
3799
3830
|
}
|
|
@@ -3812,14 +3843,14 @@ var dataStructureTyped = (() => {
|
|
|
3812
3843
|
* values as the original `LinkedListQueue`.
|
|
3813
3844
|
*/
|
|
3814
3845
|
clone() {
|
|
3815
|
-
return new _LinkedListQueue(this.
|
|
3846
|
+
return new _LinkedListQueue(this, { toElementFn: this.toElementFn });
|
|
3816
3847
|
}
|
|
3817
3848
|
};
|
|
3818
3849
|
|
|
3819
3850
|
// src/data-structures/queue/deque.ts
|
|
3820
3851
|
var Deque = class _Deque extends IterableElementBase {
|
|
3821
3852
|
/**
|
|
3822
|
-
* The constructor initializes a Deque object with
|
|
3853
|
+
* The constructor initializes a Deque object with optional iterable of elements and options.
|
|
3823
3854
|
* @param elements - An iterable object (such as an array or a Set) that contains the initial
|
|
3824
3855
|
* elements to be added to the deque. It can also be an object with a `length` or `size` property
|
|
3825
3856
|
* that represents the number of elements in the iterable object. If no elements are provided, an
|
|
@@ -3830,7 +3861,7 @@ var dataStructureTyped = (() => {
|
|
|
3830
3861
|
* or is not a number
|
|
3831
3862
|
*/
|
|
3832
3863
|
constructor(elements = [], options) {
|
|
3833
|
-
super();
|
|
3864
|
+
super(options);
|
|
3834
3865
|
__publicField(this, "_bucketSize", 1 << 12);
|
|
3835
3866
|
__publicField(this, "_bucketFirst", 0);
|
|
3836
3867
|
__publicField(this, "_firstInBucket", 0);
|
|
@@ -3863,8 +3894,12 @@ var dataStructureTyped = (() => {
|
|
|
3863
3894
|
const needBucketNum = calcMinUnitsRequired(_size, this._bucketSize);
|
|
3864
3895
|
this._bucketFirst = this._bucketLast = (this._bucketCount >> 1) - (needBucketNum >> 1);
|
|
3865
3896
|
this._firstInBucket = this._lastInBucket = this._bucketSize - _size % this._bucketSize >> 1;
|
|
3866
|
-
for (const
|
|
3867
|
-
this.
|
|
3897
|
+
for (const el of elements) {
|
|
3898
|
+
if (this.toElementFn) {
|
|
3899
|
+
this.push(this.toElementFn(el));
|
|
3900
|
+
} else {
|
|
3901
|
+
this.push(el);
|
|
3902
|
+
}
|
|
3868
3903
|
}
|
|
3869
3904
|
}
|
|
3870
3905
|
/**
|
|
@@ -4501,7 +4536,7 @@ var dataStructureTyped = (() => {
|
|
|
4501
4536
|
* elements as the original deque (`this`) and the same bucket size.
|
|
4502
4537
|
*/
|
|
4503
4538
|
clone() {
|
|
4504
|
-
return new _Deque(
|
|
4539
|
+
return new _Deque(this, { bucketSize: this.bucketSize, toElementFn: this.toElementFn });
|
|
4505
4540
|
}
|
|
4506
4541
|
/**
|
|
4507
4542
|
* Time Complexity: O(n)
|
|
@@ -4524,7 +4559,7 @@ var dataStructureTyped = (() => {
|
|
|
4524
4559
|
* satisfy the given predicate function.
|
|
4525
4560
|
*/
|
|
4526
4561
|
filter(predicate, thisArg) {
|
|
4527
|
-
const newDeque = new _Deque([], { bucketSize: this._bucketSize });
|
|
4562
|
+
const newDeque = new _Deque([], { bucketSize: this._bucketSize, toElementFn: this.toElementFn });
|
|
4528
4563
|
let index = 0;
|
|
4529
4564
|
for (const el of this) {
|
|
4530
4565
|
if (predicate.call(thisArg, el, index, this)) {
|
|
@@ -4539,20 +4574,22 @@ var dataStructureTyped = (() => {
|
|
|
4539
4574
|
* Space Complexity: O(n)
|
|
4540
4575
|
*/
|
|
4541
4576
|
/**
|
|
4542
|
-
*
|
|
4543
|
-
*
|
|
4544
|
-
*
|
|
4545
|
-
*
|
|
4546
|
-
*
|
|
4547
|
-
* @param
|
|
4548
|
-
* the
|
|
4549
|
-
*
|
|
4550
|
-
*
|
|
4551
|
-
*
|
|
4552
|
-
*
|
|
4577
|
+
* The `map` function takes a callback function and applies it to each element in the deque,
|
|
4578
|
+
* returning a new deque with the results.
|
|
4579
|
+
* @param callback - The callback parameter is a function that will be called for each element in the
|
|
4580
|
+
* deque. It takes three arguments: the current element, the index of the element, and the deque
|
|
4581
|
+
* itself. It should return a value of type EM.
|
|
4582
|
+
* @param [toElementFn] - The `toElementFn` parameter is an optional function that can be used to
|
|
4583
|
+
* transform the raw element (`RM`) into a new element (`EM`) before adding it to the new deque. If
|
|
4584
|
+
* provided, this function will be called for each raw element in the original deque.
|
|
4585
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
|
|
4586
|
+
* specify the value of `this` within the callback function. It is used to set the context or scope
|
|
4587
|
+
* in which the callback function will be executed. If `thisArg` is provided, it will be used as the
|
|
4588
|
+
* value of
|
|
4589
|
+
* @returns a new Deque object with elements of type EM and raw elements of type RM.
|
|
4553
4590
|
*/
|
|
4554
|
-
map(callback, thisArg) {
|
|
4555
|
-
const newDeque = new _Deque([], { bucketSize: this._bucketSize });
|
|
4591
|
+
map(callback, toElementFn, thisArg) {
|
|
4592
|
+
const newDeque = new _Deque([], { bucketSize: this._bucketSize, toElementFn });
|
|
4556
4593
|
let index = 0;
|
|
4557
4594
|
for (const el of this) {
|
|
4558
4595
|
newDeque.push(callback.call(thisArg, el, index, this));
|
|
@@ -4644,23 +4681,32 @@ var dataStructureTyped = (() => {
|
|
|
4644
4681
|
/**
|
|
4645
4682
|
* The constructor initializes a heap data structure with optional elements and options.
|
|
4646
4683
|
* @param elements - The `elements` parameter is an iterable object that contains the initial
|
|
4647
|
-
* elements to be added to the heap.
|
|
4684
|
+
* elements to be added to the heap.
|
|
4685
|
+
* It is an optional parameter, and if not provided, the heap will
|
|
4648
4686
|
* be initialized as empty.
|
|
4649
4687
|
* @param [options] - The `options` parameter is an optional object that can contain additional
|
|
4650
|
-
* configuration options for the heap.
|
|
4651
|
-
*
|
|
4688
|
+
* configuration options for the heap.
|
|
4689
|
+
* In this case, it is used to specify a custom comparator
|
|
4690
|
+
* function for comparing elements in the heap.
|
|
4691
|
+
* The comparator function is used to determine the
|
|
4652
4692
|
* order of elements in the heap.
|
|
4653
4693
|
*/
|
|
4654
4694
|
constructor(elements = [], options) {
|
|
4655
|
-
super();
|
|
4656
|
-
__publicField(this, "
|
|
4657
|
-
|
|
4658
|
-
|
|
4659
|
-
|
|
4660
|
-
|
|
4695
|
+
super(options);
|
|
4696
|
+
__publicField(this, "_elements", []);
|
|
4697
|
+
__publicField(this, "_DEFAULT_COMPARATOR", (a, b) => {
|
|
4698
|
+
if (typeof a === "object" || typeof b === "object") {
|
|
4699
|
+
throw TypeError(
|
|
4700
|
+
`When comparing object types, a custom comparator must be defined in the constructor's options parameter.`
|
|
4701
|
+
);
|
|
4661
4702
|
}
|
|
4703
|
+
if (a > b)
|
|
4704
|
+
return 1;
|
|
4705
|
+
if (a < b)
|
|
4706
|
+
return -1;
|
|
4707
|
+
return 0;
|
|
4662
4708
|
});
|
|
4663
|
-
__publicField(this, "
|
|
4709
|
+
__publicField(this, "_comparator", this._DEFAULT_COMPARATOR);
|
|
4664
4710
|
if (options) {
|
|
4665
4711
|
const { comparator } = options;
|
|
4666
4712
|
if (comparator)
|
|
@@ -4668,20 +4714,16 @@ var dataStructureTyped = (() => {
|
|
|
4668
4714
|
}
|
|
4669
4715
|
if (elements) {
|
|
4670
4716
|
for (const el of elements) {
|
|
4671
|
-
this.
|
|
4717
|
+
if (this.toElementFn)
|
|
4718
|
+
this.add(this.toElementFn(el));
|
|
4719
|
+
else
|
|
4720
|
+
this.add(el);
|
|
4672
4721
|
}
|
|
4673
4722
|
}
|
|
4674
4723
|
}
|
|
4675
|
-
/**
|
|
4676
|
-
* The function returns the value of the _comparator property.
|
|
4677
|
-
* @returns The `_comparator` property is being returned.
|
|
4678
|
-
*/
|
|
4679
|
-
get comparator() {
|
|
4680
|
-
return this._comparator;
|
|
4681
|
-
}
|
|
4682
4724
|
/**
|
|
4683
4725
|
* The function returns an array of elements.
|
|
4684
|
-
* @returns The
|
|
4726
|
+
* @returns The element array is being returned.
|
|
4685
4727
|
*/
|
|
4686
4728
|
get elements() {
|
|
4687
4729
|
return this._elements;
|
|
@@ -4709,11 +4751,6 @@ var dataStructureTyped = (() => {
|
|
|
4709
4751
|
static heapify(elements, options) {
|
|
4710
4752
|
return new _Heap(elements, options);
|
|
4711
4753
|
}
|
|
4712
|
-
/**
|
|
4713
|
-
* Time Complexity: O(log n)
|
|
4714
|
-
* Space Complexity: O(1)
|
|
4715
|
-
* where n is the number of elements in the heap.
|
|
4716
|
-
*/
|
|
4717
4754
|
/**
|
|
4718
4755
|
* Time Complexity: O(log n)
|
|
4719
4756
|
* Space Complexity: O(1)
|
|
@@ -4725,16 +4762,11 @@ var dataStructureTyped = (() => {
|
|
|
4725
4762
|
this._elements.push(element);
|
|
4726
4763
|
return this._bubbleUp(this.elements.length - 1);
|
|
4727
4764
|
}
|
|
4728
|
-
/**
|
|
4729
|
-
* Time Complexity: O(log n)
|
|
4730
|
-
* Space Complexity: O(1)
|
|
4731
|
-
* where n is the number of elements in the heap.
|
|
4732
|
-
*/
|
|
4733
4765
|
/**
|
|
4734
4766
|
* Time Complexity: O(log n)
|
|
4735
4767
|
* Space Complexity: O(1)
|
|
4736
4768
|
*
|
|
4737
|
-
* Remove and return the top element (smallest or largest element) from the heap.
|
|
4769
|
+
* Remove and return the top element (the smallest or largest element) from the heap.
|
|
4738
4770
|
* @returns The top element or undefined if the heap is empty.
|
|
4739
4771
|
*/
|
|
4740
4772
|
poll() {
|
|
@@ -4748,10 +4780,6 @@ var dataStructureTyped = (() => {
|
|
|
4748
4780
|
}
|
|
4749
4781
|
return value;
|
|
4750
4782
|
}
|
|
4751
|
-
/**
|
|
4752
|
-
* Time Complexity: O(1)
|
|
4753
|
-
* Space Complexity: O(1)
|
|
4754
|
-
*/
|
|
4755
4783
|
/**
|
|
4756
4784
|
* Time Complexity: O(1)
|
|
4757
4785
|
* Space Complexity: O(1)
|
|
@@ -4775,10 +4803,6 @@ var dataStructureTyped = (() => {
|
|
|
4775
4803
|
clear() {
|
|
4776
4804
|
this._elements = [];
|
|
4777
4805
|
}
|
|
4778
|
-
/**
|
|
4779
|
-
* Time Complexity: O(n)
|
|
4780
|
-
* Space Complexity: O(n)
|
|
4781
|
-
*/
|
|
4782
4806
|
/**
|
|
4783
4807
|
* Time Complexity: O(n)
|
|
4784
4808
|
* Space Complexity: O(n)
|
|
@@ -4790,10 +4814,6 @@ var dataStructureTyped = (() => {
|
|
|
4790
4814
|
this._elements = elements;
|
|
4791
4815
|
return this.fix();
|
|
4792
4816
|
}
|
|
4793
|
-
/**
|
|
4794
|
-
* Time Complexity: O(n)
|
|
4795
|
-
* Space Complexity: O(1)
|
|
4796
|
-
*/
|
|
4797
4817
|
/**
|
|
4798
4818
|
* Time Complexity: O(n)
|
|
4799
4819
|
* Space Complexity: O(1)
|
|
@@ -4806,12 +4826,7 @@ var dataStructureTyped = (() => {
|
|
|
4806
4826
|
return this.elements.includes(element);
|
|
4807
4827
|
}
|
|
4808
4828
|
/**
|
|
4809
|
-
* Time Complexity:
|
|
4810
|
-
* Space Complexity: O(1)
|
|
4811
|
-
* The worst-case O(n) This is because, in the worst case, the element to be deleted is located at the end of the heap (not the root), and after deletion, we may need to reorganize the elements by performing a sinkDown operation.
|
|
4812
|
-
*/
|
|
4813
|
-
/**
|
|
4814
|
-
* Time Complexity: O(n)
|
|
4829
|
+
* Time Complexity: O(n)
|
|
4815
4830
|
* Space Complexity: O(1)
|
|
4816
4831
|
*
|
|
4817
4832
|
* The `delete` function removes an element from an array-like data structure, maintaining the order
|
|
@@ -4836,11 +4851,6 @@ var dataStructureTyped = (() => {
|
|
|
4836
4851
|
}
|
|
4837
4852
|
return true;
|
|
4838
4853
|
}
|
|
4839
|
-
/**
|
|
4840
|
-
* Time Complexity: O(n)
|
|
4841
|
-
* Space Complexity: O(log n)
|
|
4842
|
-
* where log n is the height of the heap.
|
|
4843
|
-
*/
|
|
4844
4854
|
/**
|
|
4845
4855
|
* Time Complexity: O(n)
|
|
4846
4856
|
* Space Complexity: O(log n)
|
|
@@ -4872,10 +4882,6 @@ var dataStructureTyped = (() => {
|
|
|
4872
4882
|
_dfs(0);
|
|
4873
4883
|
return result;
|
|
4874
4884
|
}
|
|
4875
|
-
/**
|
|
4876
|
-
* Time Complexity: O(n)
|
|
4877
|
-
* Space Complexity: O(n)
|
|
4878
|
-
*/
|
|
4879
4885
|
/**
|
|
4880
4886
|
* Time Complexity: O(n)
|
|
4881
4887
|
* Space Complexity: O(n)
|
|
@@ -4886,10 +4892,6 @@ var dataStructureTyped = (() => {
|
|
|
4886
4892
|
toArray() {
|
|
4887
4893
|
return [...this.elements];
|
|
4888
4894
|
}
|
|
4889
|
-
/**
|
|
4890
|
-
* Time Complexity: O(n)
|
|
4891
|
-
* Space Complexity: O(n)
|
|
4892
|
-
*/
|
|
4893
4895
|
/**
|
|
4894
4896
|
* Time Complexity: O(n)
|
|
4895
4897
|
* Space Complexity: O(n)
|
|
@@ -4898,14 +4900,8 @@ var dataStructureTyped = (() => {
|
|
|
4898
4900
|
* @returns A new Heap instance containing the same elements.
|
|
4899
4901
|
*/
|
|
4900
4902
|
clone() {
|
|
4901
|
-
|
|
4902
|
-
clonedHeap._elements = [...this.elements];
|
|
4903
|
-
return clonedHeap;
|
|
4903
|
+
return new _Heap(this, { comparator: this.comparator, toElementFn: this.toElementFn });
|
|
4904
4904
|
}
|
|
4905
|
-
/**
|
|
4906
|
-
* Time Complexity: O(n log n)
|
|
4907
|
-
* Space Complexity: O(n)
|
|
4908
|
-
*/
|
|
4909
4905
|
/**
|
|
4910
4906
|
* Time Complexity: O(n log n)
|
|
4911
4907
|
* Space Complexity: O(n)
|
|
@@ -4915,18 +4911,14 @@ var dataStructureTyped = (() => {
|
|
|
4915
4911
|
*/
|
|
4916
4912
|
sort() {
|
|
4917
4913
|
const visitedNode = [];
|
|
4918
|
-
const cloned = this.
|
|
4914
|
+
const cloned = new _Heap(this, { comparator: this.comparator });
|
|
4919
4915
|
while (cloned.size !== 0) {
|
|
4920
4916
|
const top = cloned.poll();
|
|
4921
|
-
if (top)
|
|
4917
|
+
if (top !== void 0)
|
|
4922
4918
|
visitedNode.push(top);
|
|
4923
4919
|
}
|
|
4924
4920
|
return visitedNode;
|
|
4925
4921
|
}
|
|
4926
|
-
/**
|
|
4927
|
-
* Time Complexity: O(n log n)
|
|
4928
|
-
* Space Complexity: O(n)
|
|
4929
|
-
*/
|
|
4930
4922
|
/**
|
|
4931
4923
|
* Time Complexity: O(n log n)
|
|
4932
4924
|
* Space Complexity: O(n)
|
|
@@ -4939,10 +4931,6 @@ var dataStructureTyped = (() => {
|
|
|
4939
4931
|
results.push(this._sinkDown(i, this.elements.length >> 1));
|
|
4940
4932
|
return results;
|
|
4941
4933
|
}
|
|
4942
|
-
/**
|
|
4943
|
-
* Time Complexity: O(n)
|
|
4944
|
-
* Space Complexity: O(n)
|
|
4945
|
-
*/
|
|
4946
4934
|
/**
|
|
4947
4935
|
* Time Complexity: O(n)
|
|
4948
4936
|
* Space Complexity: O(n)
|
|
@@ -4960,7 +4948,7 @@ var dataStructureTyped = (() => {
|
|
|
4960
4948
|
* the filter condition specified by the `callback` function.
|
|
4961
4949
|
*/
|
|
4962
4950
|
filter(callback, thisArg) {
|
|
4963
|
-
const filteredList = new _Heap();
|
|
4951
|
+
const filteredList = new _Heap([], { toElementFn: this.toElementFn, comparator: this.comparator });
|
|
4964
4952
|
let index = 0;
|
|
4965
4953
|
for (const current of this) {
|
|
4966
4954
|
if (callback.call(thisArg, current, index, this)) {
|
|
@@ -4971,31 +4959,28 @@ var dataStructureTyped = (() => {
|
|
|
4971
4959
|
return filteredList;
|
|
4972
4960
|
}
|
|
4973
4961
|
/**
|
|
4974
|
-
* Time Complexity: O(n)
|
|
4975
|
-
* Space Complexity: O(n)
|
|
4976
|
-
*/
|
|
4977
|
-
/**
|
|
4978
|
-
* Time Complexity: O(n)
|
|
4962
|
+
* Time Complexity: O(n log n)
|
|
4979
4963
|
* Space Complexity: O(n)
|
|
4980
4964
|
*
|
|
4981
4965
|
* The `map` function creates a new heap by applying a callback function to each element of the
|
|
4982
4966
|
* original heap.
|
|
4983
|
-
* @param callback - The callback parameter is a function that will be called for each element in
|
|
4984
|
-
*
|
|
4985
|
-
* and the
|
|
4986
|
-
*
|
|
4987
|
-
*
|
|
4988
|
-
*
|
|
4989
|
-
*
|
|
4967
|
+
* @param callback - The `callback` parameter is a function that will be called for each element in
|
|
4968
|
+
* the heap. It takes three arguments: `el` (the current element), `index` (the index of the current
|
|
4969
|
+
* element), and `this` (the heap itself). The callback function should return a value of
|
|
4970
|
+
* @param comparator - The `comparator` parameter is a function that defines the order of the
|
|
4971
|
+
* elements in the heap. It takes two elements `a` and `b` as arguments and returns a negative number
|
|
4972
|
+
* if `a` should be placed before `b`, a positive number if `a` should be placed after
|
|
4973
|
+
* @param [toElementFn] - The `toElementFn` parameter is an optional function that converts the raw
|
|
4974
|
+
* element `RR` to the desired type `T`. It takes a single argument `rawElement` of type `RR` and
|
|
4975
|
+
* returns a value of type `T`. This function is used to transform the elements of the original
|
|
4990
4976
|
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
|
|
4991
|
-
* specify the value of `this` within the callback function. It is used
|
|
4992
|
-
*
|
|
4993
|
-
*
|
|
4994
|
-
* @returns a new instance of the Heap class
|
|
4995
|
-
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
const mappedHeap = new _Heap([], { comparator });
|
|
4977
|
+
* specify the value of `this` within the callback function. It is used to set the context or scope
|
|
4978
|
+
* in which the callback function will be executed. If `thisArg` is provided, it will be used as the
|
|
4979
|
+
* value of
|
|
4980
|
+
* @returns a new instance of the `Heap` class with the mapped elements.
|
|
4981
|
+
*/
|
|
4982
|
+
map(callback, comparator, toElementFn, thisArg) {
|
|
4983
|
+
const mappedHeap = new _Heap([], { comparator, toElementFn });
|
|
4999
4984
|
let index = 0;
|
|
5000
4985
|
for (const el of this) {
|
|
5001
4986
|
mappedHeap.add(callback.call(thisArg, el, index, this));
|
|
@@ -5003,6 +4988,13 @@ var dataStructureTyped = (() => {
|
|
|
5003
4988
|
}
|
|
5004
4989
|
return mappedHeap;
|
|
5005
4990
|
}
|
|
4991
|
+
/**
|
|
4992
|
+
* The function returns the value of the _comparator property.
|
|
4993
|
+
* @returns The `_comparator` property is being returned.
|
|
4994
|
+
*/
|
|
4995
|
+
get comparator() {
|
|
4996
|
+
return this._comparator;
|
|
4997
|
+
}
|
|
5006
4998
|
/**
|
|
5007
4999
|
* The function `_getIterator` returns an iterable iterator for the elements in the class.
|
|
5008
5000
|
*/
|
|
@@ -5011,10 +5003,6 @@ var dataStructureTyped = (() => {
|
|
|
5011
5003
|
yield element;
|
|
5012
5004
|
}
|
|
5013
5005
|
}
|
|
5014
|
-
/**
|
|
5015
|
-
* Time Complexity: O(log n)
|
|
5016
|
-
* Space Complexity: O(1)
|
|
5017
|
-
*/
|
|
5018
5006
|
/**
|
|
5019
5007
|
* Time Complexity: O(log n)
|
|
5020
5008
|
* Space Complexity: O(1)
|
|
@@ -5035,10 +5023,6 @@ var dataStructureTyped = (() => {
|
|
|
5035
5023
|
this.elements[index] = element;
|
|
5036
5024
|
return true;
|
|
5037
5025
|
}
|
|
5038
|
-
/**
|
|
5039
|
-
* Time Complexity: O(log n)
|
|
5040
|
-
* Space Complexity: O(1)
|
|
5041
|
-
*/
|
|
5042
5026
|
/**
|
|
5043
5027
|
* Time Complexity: O(log n)
|
|
5044
5028
|
* Space Complexity: O(1)
|
|
@@ -5147,10 +5131,6 @@ var dataStructureTyped = (() => {
|
|
|
5147
5131
|
this._min = void 0;
|
|
5148
5132
|
this._size = 0;
|
|
5149
5133
|
}
|
|
5150
|
-
/**
|
|
5151
|
-
* Time Complexity: O(1)
|
|
5152
|
-
* Space Complexity: O(1)
|
|
5153
|
-
*/
|
|
5154
5134
|
/**
|
|
5155
5135
|
* Time Complexity: O(1)
|
|
5156
5136
|
* Space Complexity: O(1)
|
|
@@ -5162,10 +5142,6 @@ var dataStructureTyped = (() => {
|
|
|
5162
5142
|
add(element) {
|
|
5163
5143
|
return this.push(element);
|
|
5164
5144
|
}
|
|
5165
|
-
/**
|
|
5166
|
-
* Time Complexity: O(1)
|
|
5167
|
-
* Space Complexity: O(1)
|
|
5168
|
-
*/
|
|
5169
5145
|
/**
|
|
5170
5146
|
* Time Complexity: O(1)
|
|
5171
5147
|
* Space Complexity: O(1)
|
|
@@ -5185,10 +5161,6 @@ var dataStructureTyped = (() => {
|
|
|
5185
5161
|
this._size++;
|
|
5186
5162
|
return this;
|
|
5187
5163
|
}
|
|
5188
|
-
/**
|
|
5189
|
-
* Time Complexity: O(1)
|
|
5190
|
-
* Space Complexity: O(1)
|
|
5191
|
-
*/
|
|
5192
5164
|
/**
|
|
5193
5165
|
* Time Complexity: O(1)
|
|
5194
5166
|
* Space Complexity: O(1)
|
|
@@ -5256,7 +5228,7 @@ var dataStructureTyped = (() => {
|
|
|
5256
5228
|
* Time Complexity: O(log n)
|
|
5257
5229
|
* Space Complexity: O(1)
|
|
5258
5230
|
*
|
|
5259
|
-
* Remove and return the top element (smallest or largest element) from the heap.
|
|
5231
|
+
* Remove and return the top element (the smallest or largest element) from the heap.
|
|
5260
5232
|
* @returns The top element or undefined if the heap is empty.
|
|
5261
5233
|
*/
|
|
5262
5234
|
poll() {
|
|
@@ -5270,7 +5242,7 @@ var dataStructureTyped = (() => {
|
|
|
5270
5242
|
* Time Complexity: O(log n)
|
|
5271
5243
|
* Space Complexity: O(1)
|
|
5272
5244
|
*
|
|
5273
|
-
* Remove and return the top element (smallest or largest element) from the heap.
|
|
5245
|
+
* Remove and return the top element (the smallest or largest element) from the heap.
|
|
5274
5246
|
* @returns The top element or undefined if the heap is empty.
|
|
5275
5247
|
*/
|
|
5276
5248
|
pop() {
|
|
@@ -5375,8 +5347,8 @@ var dataStructureTyped = (() => {
|
|
|
5375
5347
|
/**
|
|
5376
5348
|
* Time Complexity: O(1)
|
|
5377
5349
|
* Space Complexity: O(1)
|
|
5378
|
-
|
|
5379
|
-
* Remove and return the top element (smallest or largest element) from the heap.
|
|
5350
|
+
*
|
|
5351
|
+
* Remove and return the top element (the smallest or largest element) from the heap.
|
|
5380
5352
|
* @param node - The node to be removed.
|
|
5381
5353
|
* @protected
|
|
5382
5354
|
*/
|
|
@@ -5396,7 +5368,7 @@ var dataStructureTyped = (() => {
|
|
|
5396
5368
|
* Time Complexity: O(1)
|
|
5397
5369
|
* Space Complexity: O(1)
|
|
5398
5370
|
*
|
|
5399
|
-
* Remove and return the top element (smallest or largest element) from the heap.
|
|
5371
|
+
* Remove and return the top element (the smallest or largest element) from the heap.
|
|
5400
5372
|
* @param y
|
|
5401
5373
|
* @param x
|
|
5402
5374
|
* @protected
|
|
@@ -5417,7 +5389,7 @@ var dataStructureTyped = (() => {
|
|
|
5417
5389
|
* Time Complexity: O(n log n)
|
|
5418
5390
|
* Space Complexity: O(n)
|
|
5419
5391
|
*
|
|
5420
|
-
* Remove and return the top element (smallest or largest element) from the heap.
|
|
5392
|
+
* Remove and return the top element (the smallest or largest element) from the heap.
|
|
5421
5393
|
* @protected
|
|
5422
5394
|
*/
|
|
5423
5395
|
_consolidate() {
|
|
@@ -5449,32 +5421,161 @@ var dataStructureTyped = (() => {
|
|
|
5449
5421
|
};
|
|
5450
5422
|
|
|
5451
5423
|
// src/data-structures/heap/max-heap.ts
|
|
5452
|
-
var MaxHeap = class extends Heap {
|
|
5453
|
-
constructor(elements = [], options
|
|
5454
|
-
|
|
5455
|
-
|
|
5456
|
-
|
|
5457
|
-
|
|
5458
|
-
|
|
5424
|
+
var MaxHeap = class _MaxHeap extends Heap {
|
|
5425
|
+
constructor(elements = [], options) {
|
|
5426
|
+
super(elements, __spreadValues({
|
|
5427
|
+
comparator: (a, b) => {
|
|
5428
|
+
if (typeof a === "object" || typeof b === "object") {
|
|
5429
|
+
throw TypeError(
|
|
5430
|
+
`When comparing object types, a custom comparator must be defined in the constructor's options parameter.`
|
|
5431
|
+
);
|
|
5432
|
+
}
|
|
5433
|
+
if (a < b)
|
|
5434
|
+
return 1;
|
|
5435
|
+
if (a > b)
|
|
5436
|
+
return -1;
|
|
5437
|
+
return 0;
|
|
5438
|
+
}
|
|
5439
|
+
}, options));
|
|
5440
|
+
}
|
|
5441
|
+
/**
|
|
5442
|
+
* The `clone` function returns a new instance of the `MaxHeap` class with the same properties as the
|
|
5443
|
+
* current instance.
|
|
5444
|
+
* @returns The `clone()` method is returning a new instance of the `MaxHeap` class with the same
|
|
5445
|
+
* properties as the current instance.
|
|
5446
|
+
*/
|
|
5447
|
+
clone() {
|
|
5448
|
+
return new _MaxHeap(this, { comparator: this.comparator, toElementFn: this.toElementFn });
|
|
5449
|
+
}
|
|
5450
|
+
/**
|
|
5451
|
+
* Time Complexity: O(n)
|
|
5452
|
+
* Space Complexity: O(n)
|
|
5453
|
+
*
|
|
5454
|
+
* The `filter` function creates a new MaxHeap object containing elements that pass a given callback
|
|
5455
|
+
* function.
|
|
5456
|
+
* @param callback - The `callback` parameter is a function that will be called for each element in
|
|
5457
|
+
* the heap. It takes three arguments: the current element, the index of the current element, and the
|
|
5458
|
+
* heap itself. The callback function should return a boolean value indicating whether the current
|
|
5459
|
+
* element should be included in the filtered list
|
|
5460
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
5461
|
+
* to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
|
|
5462
|
+
* passed as the `this` value to the `callback` function. If `thisArg` is
|
|
5463
|
+
* @returns The `filter` method is returning a new `MaxHeap` object that contains the elements that pass
|
|
5464
|
+
* the filter condition specified by the `callback` function.
|
|
5465
|
+
*/
|
|
5466
|
+
filter(callback, thisArg) {
|
|
5467
|
+
const filteredList = new _MaxHeap([], { toElementFn: this.toElementFn, comparator: this.comparator });
|
|
5468
|
+
let index = 0;
|
|
5469
|
+
for (const current of this) {
|
|
5470
|
+
if (callback.call(thisArg, current, index, this)) {
|
|
5471
|
+
filteredList.add(current);
|
|
5459
5472
|
}
|
|
5473
|
+
index++;
|
|
5460
5474
|
}
|
|
5461
|
-
|
|
5462
|
-
|
|
5475
|
+
return filteredList;
|
|
5476
|
+
}
|
|
5477
|
+
/**
|
|
5478
|
+
* Time Complexity: O(n log n)
|
|
5479
|
+
* Space Complexity: O(n)
|
|
5480
|
+
*
|
|
5481
|
+
* The `map` function creates a new heap by applying a callback function to each element of the
|
|
5482
|
+
* original heap.
|
|
5483
|
+
* @param callback - The `callback` parameter is a function that will be called for each element in
|
|
5484
|
+
* the heap. It takes three arguments: `el` (the current element), `index` (the index of the current
|
|
5485
|
+
* element), and `this` (the heap itself). The callback function should return a value of
|
|
5486
|
+
* @param comparator - The `comparator` parameter is a function that defines the order of the
|
|
5487
|
+
* elements in the heap. It takes two elements `a` and `b` as arguments and returns a negative number
|
|
5488
|
+
* if `a` should be placed before `b`, a positive number if `a` should be placed after
|
|
5489
|
+
* @param [toElementFn] - The `toElementFn` parameter is an optional function that converts the raw
|
|
5490
|
+
* element `RR` to the desired type `T`. It takes a single argument `rawElement` of type `RR` and
|
|
5491
|
+
* returns a value of type `T`. This function is used to transform the elements of the original
|
|
5492
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
|
|
5493
|
+
* specify the value of `this` within the callback function. It is used to set the context or scope
|
|
5494
|
+
* in which the callback function will be executed. If `thisArg` is provided, it will be used as the
|
|
5495
|
+
* value of
|
|
5496
|
+
* @returns a new instance of the `MaxHeap` class with the mapped elements.
|
|
5497
|
+
*/
|
|
5498
|
+
map(callback, comparator, toElementFn, thisArg) {
|
|
5499
|
+
const mappedHeap = new _MaxHeap([], { comparator, toElementFn });
|
|
5500
|
+
let index = 0;
|
|
5501
|
+
for (const el of this) {
|
|
5502
|
+
mappedHeap.add(callback.call(thisArg, el, index, this));
|
|
5503
|
+
index++;
|
|
5504
|
+
}
|
|
5505
|
+
return mappedHeap;
|
|
5463
5506
|
}
|
|
5464
5507
|
};
|
|
5465
5508
|
|
|
5466
5509
|
// src/data-structures/heap/min-heap.ts
|
|
5467
|
-
var MinHeap = class extends Heap {
|
|
5468
|
-
constructor(elements = [], options
|
|
5469
|
-
|
|
5470
|
-
|
|
5471
|
-
|
|
5472
|
-
|
|
5473
|
-
|
|
5510
|
+
var MinHeap = class _MinHeap extends Heap {
|
|
5511
|
+
constructor(elements = [], options) {
|
|
5512
|
+
super(elements, options);
|
|
5513
|
+
}
|
|
5514
|
+
/**
|
|
5515
|
+
* The `clone` function returns a new instance of the `MinHeap` class with the same comparator and
|
|
5516
|
+
* toElementFn as the original instance.
|
|
5517
|
+
* @returns The `clone()` method is returning a new instance of the `MinHeap` class with the same
|
|
5518
|
+
* properties as the current instance.
|
|
5519
|
+
*/
|
|
5520
|
+
clone() {
|
|
5521
|
+
return new _MinHeap(this, { comparator: this.comparator, toElementFn: this.toElementFn });
|
|
5522
|
+
}
|
|
5523
|
+
/**
|
|
5524
|
+
* Time Complexity: O(n)
|
|
5525
|
+
* Space Complexity: O(n)
|
|
5526
|
+
*
|
|
5527
|
+
* The `filter` function creates a new MinHeap object containing elements that pass a given callback
|
|
5528
|
+
* function.
|
|
5529
|
+
* @param callback - The `callback` parameter is a function that will be called for each element in
|
|
5530
|
+
* the heap. It takes three arguments: the current element, the index of the current element, and the
|
|
5531
|
+
* heap itself. The callback function should return a boolean value indicating whether the current
|
|
5532
|
+
* element should be included in the filtered list
|
|
5533
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
5534
|
+
* to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
|
|
5535
|
+
* passed as the `this` value to the `callback` function. If `thisArg` is
|
|
5536
|
+
* @returns The `filter` method is returning a new `MinHeap` object that contains the elements that pass
|
|
5537
|
+
* the filter condition specified by the `callback` function.
|
|
5538
|
+
*/
|
|
5539
|
+
filter(callback, thisArg) {
|
|
5540
|
+
const filteredList = new _MinHeap([], { toElementFn: this.toElementFn, comparator: this.comparator });
|
|
5541
|
+
let index = 0;
|
|
5542
|
+
for (const current of this) {
|
|
5543
|
+
if (callback.call(thisArg, current, index, this)) {
|
|
5544
|
+
filteredList.add(current);
|
|
5474
5545
|
}
|
|
5546
|
+
index++;
|
|
5475
5547
|
}
|
|
5476
|
-
|
|
5477
|
-
|
|
5548
|
+
return filteredList;
|
|
5549
|
+
}
|
|
5550
|
+
/**
|
|
5551
|
+
* Time Complexity: O(n log n)
|
|
5552
|
+
* Space Complexity: O(n)
|
|
5553
|
+
*
|
|
5554
|
+
* The `map` function creates a new heap by applying a callback function to each element of the
|
|
5555
|
+
* original heap.
|
|
5556
|
+
* @param callback - The `callback` parameter is a function that will be called for each element in
|
|
5557
|
+
* the heap. It takes three arguments: `el` (the current element), `index` (the index of the current
|
|
5558
|
+
* element), and `this` (the heap itself). The callback function should return a value of
|
|
5559
|
+
* @param comparator - The `comparator` parameter is a function that defines the order of the
|
|
5560
|
+
* elements in the heap. It takes two elements `a` and `b` as arguments and returns a negative number
|
|
5561
|
+
* if `a` should be placed before `b`, a positive number if `a` should be placed after
|
|
5562
|
+
* @param [toElementFn] - The `toElementFn` parameter is an optional function that converts the raw
|
|
5563
|
+
* element `RR` to the desired type `T`. It takes a single argument `rawElement` of type `RR` and
|
|
5564
|
+
* returns a value of type `T`. This function is used to transform the elements of the original
|
|
5565
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
|
|
5566
|
+
* specify the value of `this` within the callback function. It is used to set the context or scope
|
|
5567
|
+
* in which the callback function will be executed. If `thisArg` is provided, it will be used as the
|
|
5568
|
+
* value of
|
|
5569
|
+
* @returns a new instance of the `MinHeap` class with the mapped elements.
|
|
5570
|
+
*/
|
|
5571
|
+
map(callback, comparator, toElementFn, thisArg) {
|
|
5572
|
+
const mappedHeap = new _MinHeap([], { comparator, toElementFn });
|
|
5573
|
+
let index = 0;
|
|
5574
|
+
for (const el of this) {
|
|
5575
|
+
mappedHeap.add(callback.call(thisArg, el, index, this));
|
|
5576
|
+
index++;
|
|
5577
|
+
}
|
|
5578
|
+
return mappedHeap;
|
|
5478
5579
|
}
|
|
5479
5580
|
};
|
|
5480
5581
|
|
|
@@ -7738,7 +7839,7 @@ var dataStructureTyped = (() => {
|
|
|
7738
7839
|
var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
7739
7840
|
/**
|
|
7740
7841
|
* The constructor function initializes a binary tree object with optional keysOrNodesOrEntriesOrRawElements and options.
|
|
7741
|
-
* @param [keysOrNodesOrEntriesOrRawElements] -
|
|
7842
|
+
* @param [keysOrNodesOrEntriesOrRawElements] - Optional iterable of KeyOrNodeOrEntry objects. These objects represent the
|
|
7742
7843
|
* nodes to be added to the binary tree.
|
|
7743
7844
|
* @param [options] - The `options` parameter is an optional object that can contain additional
|
|
7744
7845
|
* configuration options for the binary tree. In this case, it is of type
|
|
@@ -7759,6 +7860,8 @@ var dataStructureTyped = (() => {
|
|
|
7759
7860
|
this.iterationType = iterationType;
|
|
7760
7861
|
if (typeof toEntryFn === "function")
|
|
7761
7862
|
this._toEntryFn = toEntryFn;
|
|
7863
|
+
else if (toEntryFn)
|
|
7864
|
+
throw TypeError("toEntryFn must be a function type");
|
|
7762
7865
|
}
|
|
7763
7866
|
if (keysOrNodesOrEntriesOrRawElements)
|
|
7764
7867
|
this.addMany(keysOrNodesOrEntriesOrRawElements);
|
|
@@ -9299,7 +9402,7 @@ var dataStructureTyped = (() => {
|
|
|
9299
9402
|
} else if (this.isNIL(node) && !isShowRedBlackNIL) {
|
|
9300
9403
|
return emptyDisplayLayout;
|
|
9301
9404
|
} else if (node !== null && node !== void 0) {
|
|
9302
|
-
const key = node.key, line = this.isNIL(node) ? "S" : key
|
|
9405
|
+
const key = node.key, line = this.isNIL(node) ? "S" : String(key), width = line.length;
|
|
9303
9406
|
return _buildNodeDisplay(
|
|
9304
9407
|
line,
|
|
9305
9408
|
width,
|
|
@@ -9307,7 +9410,7 @@ var dataStructureTyped = (() => {
|
|
|
9307
9410
|
this._displayAux(node.right, options)
|
|
9308
9411
|
);
|
|
9309
9412
|
} else {
|
|
9310
|
-
const line = node === void 0 ? "U" : "
|
|
9413
|
+
const line = node === void 0 ? "U" : "N", width = line.length;
|
|
9311
9414
|
return _buildNodeDisplay(line, width, [[""], 1, 0, 0], [[""], 1, 0, 0]);
|
|
9312
9415
|
}
|
|
9313
9416
|
function _buildNodeDisplay(line, width, left, right) {
|
|
@@ -9499,14 +9602,10 @@ var dataStructureTyped = (() => {
|
|
|
9499
9602
|
constructor(keysOrNodesOrEntriesOrRawElements = [], options) {
|
|
9500
9603
|
super([], options);
|
|
9501
9604
|
__publicField(this, "_root");
|
|
9502
|
-
/**
|
|
9503
|
-
* Time complexity: O(n)
|
|
9504
|
-
* Space complexity: O(n)
|
|
9505
|
-
*/
|
|
9506
9605
|
__publicField(this, "_DEFAULT_COMPARATOR", (a, b) => {
|
|
9507
|
-
if (typeof a === "object"
|
|
9606
|
+
if (typeof a === "object" || typeof b === "object") {
|
|
9508
9607
|
throw TypeError(
|
|
9509
|
-
|
|
9608
|
+
`When comparing object types, a custom comparator must be defined in the constructor's options parameter.`
|
|
9510
9609
|
);
|
|
9511
9610
|
}
|
|
9512
9611
|
if (a > b)
|
|
@@ -9515,10 +9614,6 @@ var dataStructureTyped = (() => {
|
|
|
9515
9614
|
return -1;
|
|
9516
9615
|
return 0;
|
|
9517
9616
|
});
|
|
9518
|
-
/**
|
|
9519
|
-
* Time complexity: O(n)
|
|
9520
|
-
* Space complexity: O(n)
|
|
9521
|
-
*/
|
|
9522
9617
|
__publicField(this, "_comparator", this._DEFAULT_COMPARATOR);
|
|
9523
9618
|
if (options) {
|
|
9524
9619
|
const { comparator } = options;
|
|
@@ -12562,11 +12657,11 @@ var dataStructureTyped = (() => {
|
|
|
12562
12657
|
};
|
|
12563
12658
|
|
|
12564
12659
|
// src/data-structures/priority-queue/priority-queue.ts
|
|
12565
|
-
var PriorityQueue = class extends Heap {
|
|
12660
|
+
var PriorityQueue = class _PriorityQueue extends Heap {
|
|
12566
12661
|
/**
|
|
12567
12662
|
* The constructor initializes a priority queue with optional elements and options.
|
|
12568
12663
|
* @param elements - The `elements` parameter is an iterable object that contains the initial
|
|
12569
|
-
* elements to be added to the priority queue. It is an optional parameter and if not provided, the
|
|
12664
|
+
* elements to be added to the priority queue. It is an optional parameter, and if not provided, the
|
|
12570
12665
|
* priority queue will be initialized as empty.
|
|
12571
12666
|
* @param [options] - The `options` parameter is an optional object that can be used to customize the
|
|
12572
12667
|
* behavior of the priority queue. It can contain the following properties:
|
|
@@ -12574,10 +12669,79 @@ var dataStructureTyped = (() => {
|
|
|
12574
12669
|
constructor(elements = [], options) {
|
|
12575
12670
|
super(elements, options);
|
|
12576
12671
|
}
|
|
12672
|
+
/**
|
|
12673
|
+
* The `clone` function returns a new instance of the `PriorityQueue` class with the same comparator
|
|
12674
|
+
* and toElementFn as the original instance.
|
|
12675
|
+
* @returns The method is returning a new instance of the `PriorityQueue` class with the same
|
|
12676
|
+
* elements and properties as the current instance.
|
|
12677
|
+
*/
|
|
12678
|
+
clone() {
|
|
12679
|
+
return new _PriorityQueue(this, { comparator: this.comparator, toElementFn: this.toElementFn });
|
|
12680
|
+
}
|
|
12681
|
+
/**
|
|
12682
|
+
* Time Complexity: O(n)
|
|
12683
|
+
* Space Complexity: O(n)
|
|
12684
|
+
*
|
|
12685
|
+
* The `filter` function creates a new PriorityQueue object containing elements that pass a given callback
|
|
12686
|
+
* function.
|
|
12687
|
+
* @param callback - The `callback` parameter is a function that will be called for each element in
|
|
12688
|
+
* the heap. It takes three arguments: the current element, the index of the current element, and the
|
|
12689
|
+
* heap itself. The callback function should return a boolean value indicating whether the current
|
|
12690
|
+
* element should be included in the filtered list
|
|
12691
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
12692
|
+
* to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
|
|
12693
|
+
* passed as the `this` value to the `callback` function. If `thisArg` is
|
|
12694
|
+
* @returns The `filter` method is returning a new `PriorityQueue` object that contains the elements that pass
|
|
12695
|
+
* the filter condition specified by the `callback` function.
|
|
12696
|
+
*/
|
|
12697
|
+
filter(callback, thisArg) {
|
|
12698
|
+
const filteredPriorityQueue = new _PriorityQueue([], {
|
|
12699
|
+
toElementFn: this.toElementFn,
|
|
12700
|
+
comparator: this.comparator
|
|
12701
|
+
});
|
|
12702
|
+
let index = 0;
|
|
12703
|
+
for (const current of this) {
|
|
12704
|
+
if (callback.call(thisArg, current, index, this)) {
|
|
12705
|
+
filteredPriorityQueue.add(current);
|
|
12706
|
+
}
|
|
12707
|
+
index++;
|
|
12708
|
+
}
|
|
12709
|
+
return filteredPriorityQueue;
|
|
12710
|
+
}
|
|
12711
|
+
/**
|
|
12712
|
+
* Time Complexity: O(n log n)
|
|
12713
|
+
* Space Complexity: O(n)
|
|
12714
|
+
*
|
|
12715
|
+
* The `map` function creates a new heap by applying a callback function to each element of the
|
|
12716
|
+
* original heap.
|
|
12717
|
+
* @param callback - The `callback` parameter is a function that will be called for each element in
|
|
12718
|
+
* the heap. It takes three arguments: `el` (the current element), `index` (the index of the current
|
|
12719
|
+
* element), and `this` (the heap itself). The callback function should return a value of
|
|
12720
|
+
* @param comparator - The `comparator` parameter is a function that defines the order of the
|
|
12721
|
+
* elements in the heap. It takes two elements `a` and `b` as arguments and returns a negative number
|
|
12722
|
+
* if `a` should be placed before `b`, a positive number if `a` should be placed after
|
|
12723
|
+
* @param [toElementFn] - The `toElementFn` parameter is an optional function that converts the raw
|
|
12724
|
+
* element `RR` to the desired type `T`. It takes a single argument `rawElement` of type `RR` and
|
|
12725
|
+
* returns a value of type `T`. This function is used to transform the elements of the original
|
|
12726
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
|
|
12727
|
+
* specify the value of `this` within the callback function. It is used to set the context or scope
|
|
12728
|
+
* in which the callback function will be executed. If `thisArg` is provided, it will be used as the
|
|
12729
|
+
* value of
|
|
12730
|
+
* @returns a new instance of the `PriorityQueue` class with the mapped elements.
|
|
12731
|
+
*/
|
|
12732
|
+
map(callback, comparator, toElementFn, thisArg) {
|
|
12733
|
+
const mappedPriorityQueue = new _PriorityQueue([], { comparator, toElementFn });
|
|
12734
|
+
let index = 0;
|
|
12735
|
+
for (const el of this) {
|
|
12736
|
+
mappedPriorityQueue.add(callback.call(thisArg, el, index, this));
|
|
12737
|
+
index++;
|
|
12738
|
+
}
|
|
12739
|
+
return mappedPriorityQueue;
|
|
12740
|
+
}
|
|
12577
12741
|
};
|
|
12578
12742
|
|
|
12579
12743
|
// src/data-structures/priority-queue/min-priority-queue.ts
|
|
12580
|
-
var MinPriorityQueue = class extends PriorityQueue {
|
|
12744
|
+
var MinPriorityQueue = class _MinPriorityQueue extends PriorityQueue {
|
|
12581
12745
|
/**
|
|
12582
12746
|
* The constructor initializes a PriorityQueue with optional elements and options, including a
|
|
12583
12747
|
* comparator function.
|
|
@@ -12585,25 +12749,86 @@ var dataStructureTyped = (() => {
|
|
|
12585
12749
|
* elements to be added to the priority queue. It is optional and defaults to an empty array if not
|
|
12586
12750
|
* provided.
|
|
12587
12751
|
* @param options - The `options` parameter is an object that contains additional configuration
|
|
12588
|
-
* options for the priority queue. In this case, it has a property called `comparator
|
|
12752
|
+
* options for the priority queue. In this case, it has a property called `comparator,` which is a
|
|
12589
12753
|
* function used to compare elements in the priority queue. The `comparator` function takes two
|
|
12590
|
-
* parameters `a` and `b
|
|
12754
|
+
* parameters `a` and `b`
|
|
12591
12755
|
*/
|
|
12592
|
-
constructor(elements = [], options
|
|
12593
|
-
|
|
12594
|
-
|
|
12595
|
-
|
|
12596
|
-
|
|
12597
|
-
|
|
12756
|
+
constructor(elements = [], options) {
|
|
12757
|
+
super(elements, options);
|
|
12758
|
+
}
|
|
12759
|
+
/**
|
|
12760
|
+
* The `clone` function returns a new instance of the `MinPriorityQueue` class with the same
|
|
12761
|
+
* comparator and toElementFn as the original instance.
|
|
12762
|
+
* @returns The method is returning a new instance of the `MinPriorityQueue` class with the same
|
|
12763
|
+
* properties as the current instance.
|
|
12764
|
+
*/
|
|
12765
|
+
clone() {
|
|
12766
|
+
return new _MinPriorityQueue(this, { comparator: this.comparator, toElementFn: this.toElementFn });
|
|
12767
|
+
}
|
|
12768
|
+
/**
|
|
12769
|
+
* Time Complexity: O(n)
|
|
12770
|
+
* Space Complexity: O(n)
|
|
12771
|
+
*
|
|
12772
|
+
* The `filter` function creates a new MinPriorityQueue object containing elements that pass a given callback
|
|
12773
|
+
* function.
|
|
12774
|
+
* @param callback - The `callback` parameter is a function that will be called for each element in
|
|
12775
|
+
* the heap. It takes three arguments: the current element, the index of the current element, and the
|
|
12776
|
+
* heap itself. The callback function should return a boolean value indicating whether the current
|
|
12777
|
+
* element should be included in the filtered list
|
|
12778
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
12779
|
+
* to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
|
|
12780
|
+
* passed as the `this` value to the `callback` function. If `thisArg` is
|
|
12781
|
+
* @returns The `filter` method is returning a new `MinPriorityQueue` object that contains the elements that pass
|
|
12782
|
+
* the filter condition specified by the `callback` function.
|
|
12783
|
+
*/
|
|
12784
|
+
filter(callback, thisArg) {
|
|
12785
|
+
const filteredPriorityQueue = new _MinPriorityQueue([], {
|
|
12786
|
+
toElementFn: this.toElementFn,
|
|
12787
|
+
comparator: this.comparator
|
|
12788
|
+
});
|
|
12789
|
+
let index = 0;
|
|
12790
|
+
for (const current of this) {
|
|
12791
|
+
if (callback.call(thisArg, current, index, this)) {
|
|
12792
|
+
filteredPriorityQueue.add(current);
|
|
12598
12793
|
}
|
|
12794
|
+
index++;
|
|
12599
12795
|
}
|
|
12600
|
-
|
|
12601
|
-
|
|
12796
|
+
return filteredPriorityQueue;
|
|
12797
|
+
}
|
|
12798
|
+
/**
|
|
12799
|
+
* Time Complexity: O(n log n)
|
|
12800
|
+
* Space Complexity: O(n)
|
|
12801
|
+
*
|
|
12802
|
+
* The `map` function creates a new heap by applying a callback function to each element of the
|
|
12803
|
+
* original heap.
|
|
12804
|
+
* @param callback - The `callback` parameter is a function that will be called for each element in
|
|
12805
|
+
* the heap. It takes three arguments: `el` (the current element), `index` (the index of the current
|
|
12806
|
+
* element), and `this` (the heap itself). The callback function should return a value of
|
|
12807
|
+
* @param comparator - The `comparator` parameter is a function that defines the order of the
|
|
12808
|
+
* elements in the heap. It takes two elements `a` and `b` as arguments and returns a negative number
|
|
12809
|
+
* if `a` should be placed before `b`, a positive number if `a` should be placed after
|
|
12810
|
+
* @param [toElementFn] - The `toElementFn` parameter is an optional function that converts the raw
|
|
12811
|
+
* element `RR` to the desired type `T`. It takes a single argument `rawElement` of type `RR` and
|
|
12812
|
+
* returns a value of type `T`. This function is used to transform the elements of the original
|
|
12813
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
|
|
12814
|
+
* specify the value of `this` within the callback function. It is used to set the context or scope
|
|
12815
|
+
* in which the callback function will be executed. If `thisArg` is provided, it will be used as the
|
|
12816
|
+
* value of
|
|
12817
|
+
* @returns a new instance of the `MinPriorityQueue` class with the mapped elements.
|
|
12818
|
+
*/
|
|
12819
|
+
map(callback, comparator, toElementFn, thisArg) {
|
|
12820
|
+
const mappedPriorityQueue = new _MinPriorityQueue([], { comparator, toElementFn });
|
|
12821
|
+
let index = 0;
|
|
12822
|
+
for (const el of this) {
|
|
12823
|
+
mappedPriorityQueue.add(callback.call(thisArg, el, index, this));
|
|
12824
|
+
index++;
|
|
12825
|
+
}
|
|
12826
|
+
return mappedPriorityQueue;
|
|
12602
12827
|
}
|
|
12603
12828
|
};
|
|
12604
12829
|
|
|
12605
12830
|
// src/data-structures/priority-queue/max-priority-queue.ts
|
|
12606
|
-
var MaxPriorityQueue = class extends PriorityQueue {
|
|
12831
|
+
var MaxPriorityQueue = class _MaxPriorityQueue extends PriorityQueue {
|
|
12607
12832
|
/**
|
|
12608
12833
|
* The constructor initializes a PriorityQueue with optional elements and options, including a
|
|
12609
12834
|
* comparator function.
|
|
@@ -12611,19 +12836,93 @@ var dataStructureTyped = (() => {
|
|
|
12611
12836
|
* elements to be added to the priority queue. It is optional and defaults to an empty array if not
|
|
12612
12837
|
* provided.
|
|
12613
12838
|
* @param options - The `options` parameter is an object that contains additional configuration
|
|
12614
|
-
* options for the priority queue. In this case, it has a property called `comparator
|
|
12839
|
+
* options for the priority queue. In this case, it has a property called `comparator,` which is a
|
|
12615
12840
|
* function used to compare elements in the priority queue.
|
|
12616
12841
|
*/
|
|
12617
|
-
constructor(elements = [], options
|
|
12618
|
-
|
|
12619
|
-
|
|
12620
|
-
|
|
12621
|
-
|
|
12622
|
-
|
|
12842
|
+
constructor(elements = [], options) {
|
|
12843
|
+
super(elements, __spreadValues({
|
|
12844
|
+
comparator: (a, b) => {
|
|
12845
|
+
if (typeof a === "object" || typeof b === "object") {
|
|
12846
|
+
throw TypeError(
|
|
12847
|
+
`When comparing object types, a custom comparator must be defined in the constructor's options parameter.`
|
|
12848
|
+
);
|
|
12849
|
+
}
|
|
12850
|
+
if (a < b)
|
|
12851
|
+
return 1;
|
|
12852
|
+
if (a > b)
|
|
12853
|
+
return -1;
|
|
12854
|
+
return 0;
|
|
12855
|
+
}
|
|
12856
|
+
}, options));
|
|
12857
|
+
}
|
|
12858
|
+
/**
|
|
12859
|
+
* The `clone` function returns a new instance of the `MaxPriorityQueue` class with the same
|
|
12860
|
+
* comparator and toElementFn as the current instance.
|
|
12861
|
+
* @returns The method is returning a new instance of the MaxPriorityQueue class with the same
|
|
12862
|
+
* comparator and toElementFn as the current instance.
|
|
12863
|
+
*/
|
|
12864
|
+
clone() {
|
|
12865
|
+
return new _MaxPriorityQueue(this, { comparator: this.comparator, toElementFn: this.toElementFn });
|
|
12866
|
+
}
|
|
12867
|
+
/**
|
|
12868
|
+
* Time Complexity: O(n)
|
|
12869
|
+
* Space Complexity: O(n)
|
|
12870
|
+
*
|
|
12871
|
+
* The `filter` function creates a new MaxPriorityQueue object containing elements that pass a given callback
|
|
12872
|
+
* function.
|
|
12873
|
+
* @param callback - The `callback` parameter is a function that will be called for each element in
|
|
12874
|
+
* the heap. It takes three arguments: the current element, the index of the current element, and the
|
|
12875
|
+
* heap itself. The callback function should return a boolean value indicating whether the current
|
|
12876
|
+
* element should be included in the filtered list
|
|
12877
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
12878
|
+
* to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
|
|
12879
|
+
* passed as the `this` value to the `callback` function. If `thisArg` is
|
|
12880
|
+
* @returns The `filter` method is returning a new `MaxPriorityQueue` object that contains the elements that pass
|
|
12881
|
+
* the filter condition specified by the `callback` function.
|
|
12882
|
+
*/
|
|
12883
|
+
filter(callback, thisArg) {
|
|
12884
|
+
const filteredPriorityQueue = new _MaxPriorityQueue([], {
|
|
12885
|
+
toElementFn: this.toElementFn,
|
|
12886
|
+
comparator: this.comparator
|
|
12887
|
+
});
|
|
12888
|
+
let index = 0;
|
|
12889
|
+
for (const current of this) {
|
|
12890
|
+
if (callback.call(thisArg, current, index, this)) {
|
|
12891
|
+
filteredPriorityQueue.add(current);
|
|
12623
12892
|
}
|
|
12893
|
+
index++;
|
|
12624
12894
|
}
|
|
12625
|
-
|
|
12626
|
-
|
|
12895
|
+
return filteredPriorityQueue;
|
|
12896
|
+
}
|
|
12897
|
+
/**
|
|
12898
|
+
* Time Complexity: O(n log n)
|
|
12899
|
+
* Space Complexity: O(n)
|
|
12900
|
+
*
|
|
12901
|
+
* The `map` function creates a new heap by applying a callback function to each element of the
|
|
12902
|
+
* original heap.
|
|
12903
|
+
* @param callback - The `callback` parameter is a function that will be called for each element in
|
|
12904
|
+
* the heap. It takes three arguments: `el` (the current element), `index` (the index of the current
|
|
12905
|
+
* element), and `this` (the heap itself). The callback function should return a value of
|
|
12906
|
+
* @param comparator - The `comparator` parameter is a function that defines the order of the
|
|
12907
|
+
* elements in the heap. It takes two elements `a` and `b` as arguments and returns a negative number
|
|
12908
|
+
* if `a` should be placed before `b`, a positive number if `a` should be placed after
|
|
12909
|
+
* @param [toElementFn] - The `toElementFn` parameter is an optional function that converts the raw
|
|
12910
|
+
* element `RR` to the desired type `T`. It takes a single argument `rawElement` of type `RR` and
|
|
12911
|
+
* returns a value of type `T`. This function is used to transform the elements of the original
|
|
12912
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
|
|
12913
|
+
* specify the value of `this` within the callback function. It is used to set the context or scope
|
|
12914
|
+
* in which the callback function will be executed. If `thisArg` is provided, it will be used as the
|
|
12915
|
+
* value of
|
|
12916
|
+
* @returns a new instance of the `MaxPriorityQueue` class with the mapped elements.
|
|
12917
|
+
*/
|
|
12918
|
+
map(callback, comparator, toElementFn, thisArg) {
|
|
12919
|
+
const mappedPriorityQueue = new _MaxPriorityQueue([], { comparator, toElementFn });
|
|
12920
|
+
let index = 0;
|
|
12921
|
+
for (const el of this) {
|
|
12922
|
+
mappedPriorityQueue.add(callback.call(thisArg, el, index, this));
|
|
12923
|
+
index++;
|
|
12924
|
+
}
|
|
12925
|
+
return mappedPriorityQueue;
|
|
12627
12926
|
}
|
|
12628
12927
|
};
|
|
12629
12928
|
|
|
@@ -13237,7 +13536,7 @@ var dataStructureTyped = (() => {
|
|
|
13237
13536
|
* @return This
|
|
13238
13537
|
*/
|
|
13239
13538
|
constructor(words = [], options) {
|
|
13240
|
-
super();
|
|
13539
|
+
super(options);
|
|
13241
13540
|
__publicField(this, "_size", 0);
|
|
13242
13541
|
__publicField(this, "_caseSensitive", true);
|
|
13243
13542
|
__publicField(this, "_root", new TrieNode(""));
|
|
@@ -13247,8 +13546,13 @@ var dataStructureTyped = (() => {
|
|
|
13247
13546
|
this._caseSensitive = caseSensitive;
|
|
13248
13547
|
}
|
|
13249
13548
|
if (words) {
|
|
13250
|
-
for (const word of words)
|
|
13251
|
-
this.
|
|
13549
|
+
for (const word of words) {
|
|
13550
|
+
if (this.toElementFn) {
|
|
13551
|
+
this.add(this.toElementFn(word));
|
|
13552
|
+
} else {
|
|
13553
|
+
this.add(word);
|
|
13554
|
+
}
|
|
13555
|
+
}
|
|
13252
13556
|
}
|
|
13253
13557
|
}
|
|
13254
13558
|
/**
|
|
@@ -13586,7 +13890,7 @@ var dataStructureTyped = (() => {
|
|
|
13586
13890
|
* @returns A new instance of the Trie class is being returned.
|
|
13587
13891
|
*/
|
|
13588
13892
|
clone() {
|
|
13589
|
-
return new _Trie(this
|
|
13893
|
+
return new _Trie(this, { caseSensitive: this.caseSensitive, toElementFn: this.toElementFn });
|
|
13590
13894
|
}
|
|
13591
13895
|
/**
|
|
13592
13896
|
* Time Complexity: O(n)
|
|
@@ -13607,7 +13911,7 @@ var dataStructureTyped = (() => {
|
|
|
13607
13911
|
* @returns The `filter` method is returning an array of strings (`string[]`).
|
|
13608
13912
|
*/
|
|
13609
13913
|
filter(predicate, thisArg) {
|
|
13610
|
-
const results = new _Trie();
|
|
13914
|
+
const results = new _Trie([], { toElementFn: this.toElementFn, caseSensitive: this.caseSensitive });
|
|
13611
13915
|
let index = 0;
|
|
13612
13916
|
for (const word of this) {
|
|
13613
13917
|
if (predicate.call(thisArg, word, index, this)) {
|
|
@@ -13625,17 +13929,22 @@ var dataStructureTyped = (() => {
|
|
|
13625
13929
|
* Time Complexity: O(n)
|
|
13626
13930
|
* Space Complexity: O(n)
|
|
13627
13931
|
*
|
|
13628
|
-
* The `map` function creates a new Trie by applying a callback function to each element in the
|
|
13932
|
+
* The `map` function creates a new Trie by applying a callback function to each element in the
|
|
13933
|
+
* current Trie.
|
|
13629
13934
|
* @param callback - The callback parameter is a function that will be called for each element in the
|
|
13630
|
-
* Trie. It takes
|
|
13631
|
-
*
|
|
13632
|
-
*
|
|
13633
|
-
*
|
|
13634
|
-
*
|
|
13635
|
-
* @
|
|
13935
|
+
* Trie. It takes four arguments:
|
|
13936
|
+
* @param [toElementFn] - The `toElementFn` parameter is an optional function that can be used to
|
|
13937
|
+
* convert the raw element (`RM`) into a string representation. This can be useful if the raw element
|
|
13938
|
+
* is not already a string or if you want to customize how the element is converted into a string. If
|
|
13939
|
+
* this parameter is
|
|
13940
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
|
|
13941
|
+
* specify the value of `this` within the callback function. It is used to set the context or scope
|
|
13942
|
+
* in which the callback function will be executed. If `thisArg` is provided, it will be used as the
|
|
13943
|
+
* value of
|
|
13944
|
+
* @returns a new Trie object.
|
|
13636
13945
|
*/
|
|
13637
|
-
map(callback, thisArg) {
|
|
13638
|
-
const newTrie = new _Trie();
|
|
13946
|
+
map(callback, toElementFn, thisArg) {
|
|
13947
|
+
const newTrie = new _Trie([], { toElementFn, caseSensitive: this.caseSensitive });
|
|
13639
13948
|
let index = 0;
|
|
13640
13949
|
for (const word of this) {
|
|
13641
13950
|
newTrie.add(callback.call(thisArg, word, index, this));
|