data-structure-typed 1.53.7 → 1.53.8
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/dist/cjs/common/index.js +5 -0
- package/dist/cjs/common/index.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +2 -2
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +2 -2
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +53 -23
- package/dist/cjs/data-structures/binary-tree/bst.js +59 -25
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/index.d.ts +1 -1
- package/dist/cjs/data-structures/binary-tree/index.js +1 -1
- package/dist/cjs/data-structures/binary-tree/index.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/{rb-tree.d.ts → red-black-tree.d.ts} +52 -0
- package/dist/cjs/data-structures/binary-tree/{rb-tree.js → red-black-tree.js} +54 -2
- package/dist/cjs/data-structures/binary-tree/red-black-tree.js.map +1 -0
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +2 -2
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +5 -5
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +30 -0
- package/dist/cjs/data-structures/hash/hash-map.js +30 -0
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +20 -3
- package/dist/cjs/data-structures/heap/heap.js +31 -11
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +36 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +56 -9
- 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 +34 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +54 -10
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +37 -8
- package/dist/cjs/data-structures/queue/deque.js +73 -29
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +41 -1
- package/dist/cjs/data-structures/queue/queue.js +51 -9
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/stack/stack.d.ts +27 -10
- package/dist/cjs/data-structures/stack/stack.js +39 -20
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +12 -13
- package/dist/cjs/data-structures/trie/trie.js +12 -13
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/mjs/common/index.js +5 -0
- package/dist/mjs/common/index.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +2 -2
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +2 -2
- package/dist/mjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +53 -23
- package/dist/mjs/data-structures/binary-tree/bst.js +59 -25
- package/dist/mjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/index.d.ts +1 -1
- package/dist/mjs/data-structures/binary-tree/index.js +1 -1
- package/dist/mjs/data-structures/binary-tree/index.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/{rb-tree.d.ts → red-black-tree.d.ts} +52 -0
- package/dist/mjs/data-structures/binary-tree/{rb-tree.js → red-black-tree.js} +54 -2
- package/dist/mjs/data-structures/binary-tree/red-black-tree.js.map +1 -0
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +2 -2
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +3 -3
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/mjs/data-structures/hash/hash-map.d.ts +30 -0
- package/dist/mjs/data-structures/hash/hash-map.js +30 -0
- package/dist/mjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/mjs/data-structures/heap/heap.d.ts +20 -3
- package/dist/mjs/data-structures/heap/heap.js +31 -11
- package/dist/mjs/data-structures/heap/heap.js.map +1 -1
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +36 -1
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +56 -9
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +34 -1
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +54 -10
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/mjs/data-structures/queue/deque.d.ts +37 -8
- package/dist/mjs/data-structures/queue/deque.js +73 -29
- package/dist/mjs/data-structures/queue/deque.js.map +1 -1
- package/dist/mjs/data-structures/queue/queue.d.ts +41 -1
- package/dist/mjs/data-structures/queue/queue.js +51 -9
- package/dist/mjs/data-structures/queue/queue.js.map +1 -1
- package/dist/mjs/data-structures/stack/stack.d.ts +27 -10
- package/dist/mjs/data-structures/stack/stack.js +39 -20
- package/dist/mjs/data-structures/stack/stack.js.map +1 -1
- package/dist/mjs/data-structures/trie/trie.d.ts +12 -13
- package/dist/mjs/data-structures/trie/trie.js +12 -13
- package/dist/mjs/data-structures/trie/trie.js.map +1 -1
- package/dist/umd/data-structure-typed.js +373 -91
- 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/common/index.ts +7 -1
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +2 -2
- package/src/data-structures/binary-tree/binary-tree.ts +2 -2
- package/src/data-structures/binary-tree/bst.ts +64 -25
- package/src/data-structures/binary-tree/index.ts +1 -1
- package/src/data-structures/binary-tree/{rb-tree.ts → red-black-tree.ts} +50 -1
- package/src/data-structures/binary-tree/tree-multi-map.ts +3 -3
- package/src/data-structures/hash/hash-map.ts +30 -0
- package/src/data-structures/heap/heap.ts +33 -10
- package/src/data-structures/linked-list/doubly-linked-list.ts +62 -8
- package/src/data-structures/linked-list/singly-linked-list.ts +60 -10
- package/src/data-structures/queue/deque.ts +72 -28
- package/src/data-structures/queue/queue.ts +50 -7
- package/src/data-structures/stack/stack.ts +39 -20
- package/src/data-structures/trie/trie.ts +8 -3
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +35 -35
- package/test/unit/data-structures/binary-tree/bst.test.ts +79 -85
- package/test/unit/data-structures/binary-tree/{rb-tree.test.ts → red-black-tree.test.ts} +39 -84
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +0 -1
- package/dist/mjs/data-structures/binary-tree/rb-tree.js.map +0 -1
|
@@ -771,6 +771,9 @@ var dataStructureTyped = (() => {
|
|
|
771
771
|
return this._hashFn;
|
|
772
772
|
}
|
|
773
773
|
/**
|
|
774
|
+
* Time Complexity: O(1)
|
|
775
|
+
* Space Complexity: O(1)
|
|
776
|
+
*
|
|
774
777
|
* The function checks if a given element is an array with exactly two elements.
|
|
775
778
|
* @param {any} rawElement - The `rawElement` parameter is of type `any`, which means it can be any
|
|
776
779
|
* data type.
|
|
@@ -780,6 +783,9 @@ var dataStructureTyped = (() => {
|
|
|
780
783
|
return Array.isArray(rawElement) && rawElement.length === 2;
|
|
781
784
|
}
|
|
782
785
|
/**
|
|
786
|
+
* Time Complexity: O(1)
|
|
787
|
+
* Space Complexity: O(1)
|
|
788
|
+
*
|
|
783
789
|
* The function checks if the size of an object is equal to zero and returns a boolean value.
|
|
784
790
|
* @returns A boolean value indicating whether the size of the object is 0 or not.
|
|
785
791
|
*/
|
|
@@ -787,6 +793,9 @@ var dataStructureTyped = (() => {
|
|
|
787
793
|
return this._size === 0;
|
|
788
794
|
}
|
|
789
795
|
/**
|
|
796
|
+
* Time Complexity: O(1)
|
|
797
|
+
* Space Complexity: O(1)
|
|
798
|
+
*
|
|
790
799
|
* The clear() function resets the state of an object by clearing its internal store, object map, and
|
|
791
800
|
* size.
|
|
792
801
|
*/
|
|
@@ -796,6 +805,9 @@ var dataStructureTyped = (() => {
|
|
|
796
805
|
this._size = 0;
|
|
797
806
|
}
|
|
798
807
|
/**
|
|
808
|
+
* Time Complexity: O(1)
|
|
809
|
+
* Space Complexity: O(1)
|
|
810
|
+
*
|
|
799
811
|
* The `set` function adds a key-value pair to a map-like data structure, incrementing the size if
|
|
800
812
|
* the key is not already present.
|
|
801
813
|
* @param {K} key - The key parameter is the key used to identify the value in the data structure. It
|
|
@@ -820,6 +832,9 @@ var dataStructureTyped = (() => {
|
|
|
820
832
|
return true;
|
|
821
833
|
}
|
|
822
834
|
/**
|
|
835
|
+
* Time Complexity: O(k)
|
|
836
|
+
* Space Complexity: O(k)
|
|
837
|
+
*
|
|
823
838
|
* The function `setMany` takes an iterable collection of objects, maps each object to a key-value
|
|
824
839
|
* pair using a mapping function, and sets each key-value pair in the current object.
|
|
825
840
|
* @param entryOrRawElements - The `entryOrRawElements` parameter is an iterable collection of elements of a type
|
|
@@ -843,6 +858,9 @@ var dataStructureTyped = (() => {
|
|
|
843
858
|
return results;
|
|
844
859
|
}
|
|
845
860
|
/**
|
|
861
|
+
* Time Complexity: O(1)
|
|
862
|
+
* Space Complexity: O(1)
|
|
863
|
+
*
|
|
846
864
|
* The `get` function retrieves a value from a map based on a given key, either from an object map or
|
|
847
865
|
* a string map.
|
|
848
866
|
* @param {K} key - The `key` parameter is the key used to retrieve a value from the map. It can be
|
|
@@ -860,6 +878,9 @@ var dataStructureTyped = (() => {
|
|
|
860
878
|
}
|
|
861
879
|
}
|
|
862
880
|
/**
|
|
881
|
+
* Time Complexity: O(1)
|
|
882
|
+
* Space Complexity: O(1)
|
|
883
|
+
*
|
|
863
884
|
* The `has` function checks if a given key exists in the `_objMap` or `_store` based on whether it
|
|
864
885
|
* is an object key or not.
|
|
865
886
|
* @param {K} key - The parameter "key" is of type K, which means it can be any type.
|
|
@@ -874,6 +895,9 @@ var dataStructureTyped = (() => {
|
|
|
874
895
|
}
|
|
875
896
|
}
|
|
876
897
|
/**
|
|
898
|
+
* Time Complexity: O(1)
|
|
899
|
+
* Space Complexity: O(1)
|
|
900
|
+
*
|
|
877
901
|
* The `delete` function removes an element from a map-like data structure based on the provided key.
|
|
878
902
|
* @param {K} key - The `key` parameter is the key of the element that you want to delete from the
|
|
879
903
|
* data structure.
|
|
@@ -1195,6 +1219,9 @@ var dataStructureTyped = (() => {
|
|
|
1195
1219
|
return true;
|
|
1196
1220
|
}
|
|
1197
1221
|
/**
|
|
1222
|
+
* Time Complexity: O(k)
|
|
1223
|
+
* Space Complexity: O(k)
|
|
1224
|
+
*
|
|
1198
1225
|
* The function `setMany` takes an iterable collection, converts each element into a key-value pair
|
|
1199
1226
|
* using a provided function, and sets each key-value pair in the current object, returning an array
|
|
1200
1227
|
* of booleans indicating the success of each set operation.
|
|
@@ -1219,6 +1246,9 @@ var dataStructureTyped = (() => {
|
|
|
1219
1246
|
return results;
|
|
1220
1247
|
}
|
|
1221
1248
|
/**
|
|
1249
|
+
* Time Complexity: O(1)
|
|
1250
|
+
* Space Complexity: O(1)
|
|
1251
|
+
*
|
|
1222
1252
|
* The function checks if a given key exists in a map, using different logic depending on whether the
|
|
1223
1253
|
* key is a weak key or not.
|
|
1224
1254
|
* @param {K} key - The `key` parameter is the key that is being checked for existence in the map.
|
|
@@ -1514,15 +1544,7 @@ var dataStructureTyped = (() => {
|
|
|
1514
1544
|
__publicField(this, "_head");
|
|
1515
1545
|
__publicField(this, "_tail");
|
|
1516
1546
|
__publicField(this, "_size", 0);
|
|
1517
|
-
|
|
1518
|
-
for (const el of elements) {
|
|
1519
|
-
if (this.toElementFn) {
|
|
1520
|
-
this.push(this.toElementFn(el));
|
|
1521
|
-
} else {
|
|
1522
|
-
this.push(el);
|
|
1523
|
-
}
|
|
1524
|
-
}
|
|
1525
|
-
}
|
|
1547
|
+
this.pushMany(elements);
|
|
1526
1548
|
}
|
|
1527
1549
|
/**
|
|
1528
1550
|
* The `head` function returns the first node of a singly linked list.
|
|
@@ -1648,6 +1670,53 @@ var dataStructureTyped = (() => {
|
|
|
1648
1670
|
this._size++;
|
|
1649
1671
|
return true;
|
|
1650
1672
|
}
|
|
1673
|
+
/**
|
|
1674
|
+
* Time Complexity: O(k)
|
|
1675
|
+
* Space Complexity: O(k)
|
|
1676
|
+
*
|
|
1677
|
+
* The function `pushMany` iterates over elements and pushes them into a data structure, applying a
|
|
1678
|
+
* transformation function if provided.
|
|
1679
|
+
* @param {Iterable<E> | Iterable<R> | Iterable<SinglyLinkedListNode<E>>} elements - The `elements`
|
|
1680
|
+
* parameter in the `pushMany` function can accept an iterable containing elements of type `E`, `R`,
|
|
1681
|
+
* or `SinglyLinkedListNode<E>`.
|
|
1682
|
+
* @returns The `pushMany` function returns an array of boolean values indicating whether each
|
|
1683
|
+
* element was successfully pushed into the data structure.
|
|
1684
|
+
*/
|
|
1685
|
+
pushMany(elements) {
|
|
1686
|
+
const ans = [];
|
|
1687
|
+
for (const el of elements) {
|
|
1688
|
+
if (this.toElementFn) {
|
|
1689
|
+
ans.push(this.push(this.toElementFn(el)));
|
|
1690
|
+
continue;
|
|
1691
|
+
}
|
|
1692
|
+
ans.push(this.push(el));
|
|
1693
|
+
}
|
|
1694
|
+
return ans;
|
|
1695
|
+
}
|
|
1696
|
+
/**
|
|
1697
|
+
* Time Complexity: O(k)
|
|
1698
|
+
* Space Complexity: O(k)
|
|
1699
|
+
*
|
|
1700
|
+
* The function `unshiftMany` iterates over elements and adds them to a data structure, optionally
|
|
1701
|
+
* converting them using a provided function.
|
|
1702
|
+
* @param {Iterable<E> | Iterable<R> | Iterable<SinglyLinkedListNode<E>>} elements - The `elements`
|
|
1703
|
+
* parameter in the `unshiftMany` function can accept an iterable containing elements of type `E`,
|
|
1704
|
+
* `R`, or `SinglyLinkedListNode<E>`. The function iterates over each element in the iterable and
|
|
1705
|
+
* performs an `unshift` operation on the linked list for each
|
|
1706
|
+
* @returns The `unshiftMany` function is returning an array of boolean values, where each value
|
|
1707
|
+
* represents the result of calling the `unshift` method on the current instance of the class.
|
|
1708
|
+
*/
|
|
1709
|
+
unshiftMany(elements) {
|
|
1710
|
+
const ans = [];
|
|
1711
|
+
for (const el of elements) {
|
|
1712
|
+
if (this.toElementFn) {
|
|
1713
|
+
ans.push(this.unshift(this.toElementFn(el)));
|
|
1714
|
+
continue;
|
|
1715
|
+
}
|
|
1716
|
+
ans.push(this.unshift(el));
|
|
1717
|
+
}
|
|
1718
|
+
return ans;
|
|
1719
|
+
}
|
|
1651
1720
|
/**
|
|
1652
1721
|
* Time Complexity: O(n)
|
|
1653
1722
|
* Space Complexity: O(1)
|
|
@@ -1819,6 +1888,9 @@ var dataStructureTyped = (() => {
|
|
|
1819
1888
|
return true;
|
|
1820
1889
|
}
|
|
1821
1890
|
/**
|
|
1891
|
+
* Time Complexity: O(1)
|
|
1892
|
+
* Space Complexity: O(1)
|
|
1893
|
+
*
|
|
1822
1894
|
* The function checks if the length of a data structure is equal to zero and returns a boolean value indicating
|
|
1823
1895
|
* whether it is empty or not.
|
|
1824
1896
|
* @returns A boolean value indicating whether the length of the object is equal to 0.
|
|
@@ -1827,6 +1899,9 @@ var dataStructureTyped = (() => {
|
|
|
1827
1899
|
return this._size === 0;
|
|
1828
1900
|
}
|
|
1829
1901
|
/**
|
|
1902
|
+
* Time Complexity: O(1)
|
|
1903
|
+
* Space Complexity: O(1)
|
|
1904
|
+
*
|
|
1830
1905
|
* The `clear` function resets the linked list by setting the head, tail, and length to undefined and 0 respectively.
|
|
1831
1906
|
*/
|
|
1832
1907
|
clear() {
|
|
@@ -2235,13 +2310,7 @@ var dataStructureTyped = (() => {
|
|
|
2235
2310
|
this._head = void 0;
|
|
2236
2311
|
this._tail = void 0;
|
|
2237
2312
|
this._size = 0;
|
|
2238
|
-
|
|
2239
|
-
for (const el of elements) {
|
|
2240
|
-
if (this.toElementFn) {
|
|
2241
|
-
this.push(this.toElementFn(el));
|
|
2242
|
-
} else this.push(el);
|
|
2243
|
-
}
|
|
2244
|
-
}
|
|
2313
|
+
this.pushMany(elements);
|
|
2245
2314
|
}
|
|
2246
2315
|
/**
|
|
2247
2316
|
* The `head` function returns the first node of a doubly linked list.
|
|
@@ -2389,6 +2458,55 @@ var dataStructureTyped = (() => {
|
|
|
2389
2458
|
this._size++;
|
|
2390
2459
|
return true;
|
|
2391
2460
|
}
|
|
2461
|
+
/**
|
|
2462
|
+
* Time Complexity: O(k)
|
|
2463
|
+
* Space Complexity: O(k)
|
|
2464
|
+
*
|
|
2465
|
+
* The function `pushMany` iterates over elements and pushes them into a data structure, applying a
|
|
2466
|
+
* transformation function if provided.
|
|
2467
|
+
* @param {Iterable<E> | Iterable<R> | Iterable<DoublyLinkedListNode<E>>} elements - The `elements`
|
|
2468
|
+
* parameter in the `pushMany` function can accept an iterable containing elements of type `E`, `R`,
|
|
2469
|
+
* or `DoublyLinkedListNode<E>`. The function iterates over each element in the iterable and pushes
|
|
2470
|
+
* it onto the linked list. If a transformation function `to
|
|
2471
|
+
* @returns The `pushMany` function is returning an array of boolean values (`ans`) which indicate
|
|
2472
|
+
* the success or failure of pushing each element into the data structure.
|
|
2473
|
+
*/
|
|
2474
|
+
pushMany(elements) {
|
|
2475
|
+
const ans = [];
|
|
2476
|
+
for (const el of elements) {
|
|
2477
|
+
if (this.toElementFn) {
|
|
2478
|
+
ans.push(this.push(this.toElementFn(el)));
|
|
2479
|
+
continue;
|
|
2480
|
+
}
|
|
2481
|
+
ans.push(this.push(el));
|
|
2482
|
+
}
|
|
2483
|
+
return ans;
|
|
2484
|
+
}
|
|
2485
|
+
/**
|
|
2486
|
+
* Time Complexity: O(k)
|
|
2487
|
+
* Space Complexity: O(k)
|
|
2488
|
+
*
|
|
2489
|
+
* The function `unshiftMany` iterates through a collection of elements and adds them to the
|
|
2490
|
+
* beginning of a Doubly Linked List, returning an array of boolean values indicating the success of
|
|
2491
|
+
* each insertion.
|
|
2492
|
+
* @param {Iterable<E> | Iterable<R> | Iterable<DoublyLinkedListNode<E>>} elements - The `elements`
|
|
2493
|
+
* parameter in the `unshiftMany` function can accept an iterable containing elements of type `E`,
|
|
2494
|
+
* `R`, or `DoublyLinkedListNode<E>`. The function iterates over each element in the iterable and
|
|
2495
|
+
* performs an `unshift` operation on the doubly linked list
|
|
2496
|
+
* @returns The `unshiftMany` function returns an array of boolean values indicating the success of
|
|
2497
|
+
* each unshift operation performed on the elements passed as input.
|
|
2498
|
+
*/
|
|
2499
|
+
unshiftMany(elements) {
|
|
2500
|
+
const ans = [];
|
|
2501
|
+
for (const el of elements) {
|
|
2502
|
+
if (this.toElementFn) {
|
|
2503
|
+
ans.push(this.unshift(this.toElementFn(el)));
|
|
2504
|
+
continue;
|
|
2505
|
+
}
|
|
2506
|
+
ans.push(this.unshift(el));
|
|
2507
|
+
}
|
|
2508
|
+
return ans;
|
|
2509
|
+
}
|
|
2392
2510
|
/**
|
|
2393
2511
|
* Time Complexity: O(n)
|
|
2394
2512
|
* Space Complexity: O(1)
|
|
@@ -2825,6 +2943,12 @@ var dataStructureTyped = (() => {
|
|
|
2825
2943
|
* Time Complexity: O(n)
|
|
2826
2944
|
* Space Complexity: O(1)
|
|
2827
2945
|
*
|
|
2946
|
+
* The function `countOccurrences` iterates through a doubly linked list and counts the occurrences
|
|
2947
|
+
* of a specified element or nodes that satisfy a given predicate.
|
|
2948
|
+
* @param {E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)} elementOrNode
|
|
2949
|
+
* - The `elementOrNode` parameter in the `countOccurrences` method can accept three types of values:
|
|
2950
|
+
* @returns The `countOccurrences` method returns the number of occurrences of the specified element,
|
|
2951
|
+
* node, or predicate function in the doubly linked list.
|
|
2828
2952
|
*/
|
|
2829
2953
|
countOccurrences(elementOrNode) {
|
|
2830
2954
|
const predicate = this._ensurePredicate(elementOrNode);
|
|
@@ -3144,15 +3268,7 @@ var dataStructureTyped = (() => {
|
|
|
3144
3268
|
constructor(elements = [], options) {
|
|
3145
3269
|
super(options);
|
|
3146
3270
|
__publicField(this, "_elements", []);
|
|
3147
|
-
|
|
3148
|
-
for (const el of elements) {
|
|
3149
|
-
if (this.toElementFn) {
|
|
3150
|
-
this.push(this.toElementFn(el));
|
|
3151
|
-
} else {
|
|
3152
|
-
this.push(el);
|
|
3153
|
-
}
|
|
3154
|
-
}
|
|
3155
|
-
}
|
|
3271
|
+
this.pushMany(elements);
|
|
3156
3272
|
}
|
|
3157
3273
|
/**
|
|
3158
3274
|
* The elements function returns the elements of this set.
|
|
@@ -3168,10 +3284,6 @@ var dataStructureTyped = (() => {
|
|
|
3168
3284
|
get size() {
|
|
3169
3285
|
return this.elements.length;
|
|
3170
3286
|
}
|
|
3171
|
-
/**
|
|
3172
|
-
* Time Complexity: O(n)
|
|
3173
|
-
* Space Complexity: O(n)
|
|
3174
|
-
*/
|
|
3175
3287
|
/**
|
|
3176
3288
|
* Time Complexity: O(n)
|
|
3177
3289
|
* Space Complexity: O(n)
|
|
@@ -3185,6 +3297,9 @@ var dataStructureTyped = (() => {
|
|
|
3185
3297
|
return new _Stack(elements);
|
|
3186
3298
|
}
|
|
3187
3299
|
/**
|
|
3300
|
+
* Time Complexity: O(1)
|
|
3301
|
+
* Space Complexity: O(1)
|
|
3302
|
+
*
|
|
3188
3303
|
* The function checks if an array is empty and returns a boolean value.
|
|
3189
3304
|
* @returns A boolean value indicating whether the `_elements` array is empty or not.
|
|
3190
3305
|
*/
|
|
@@ -3227,18 +3342,46 @@ var dataStructureTyped = (() => {
|
|
|
3227
3342
|
return this.elements.pop();
|
|
3228
3343
|
}
|
|
3229
3344
|
/**
|
|
3230
|
-
*
|
|
3231
|
-
*
|
|
3232
|
-
*
|
|
3345
|
+
* Time Complexity: O(k)
|
|
3346
|
+
* Space Complexity: O(1)
|
|
3347
|
+
*
|
|
3348
|
+
* The function `pushMany` iterates over elements and pushes them into an array after applying a
|
|
3349
|
+
* transformation function if provided.
|
|
3350
|
+
* @param {Iterable<E> | Iterable<R>} elements - The `elements` parameter in the `pushMany` function
|
|
3351
|
+
* is an iterable containing elements of type `E` or `R`. The function iterates over each element in
|
|
3352
|
+
* the iterable and pushes it into the data structure. If a transformation function `toElementFn` is
|
|
3353
|
+
* provided, it is used to
|
|
3354
|
+
* @returns The `pushMany` function is returning an array of boolean values indicating whether each
|
|
3355
|
+
* element was successfully pushed into the data structure.
|
|
3356
|
+
*/
|
|
3357
|
+
pushMany(elements) {
|
|
3358
|
+
const ans = [];
|
|
3359
|
+
for (const el of elements) {
|
|
3360
|
+
if (this.toElementFn) {
|
|
3361
|
+
ans.push(this.push(this.toElementFn(el)));
|
|
3362
|
+
} else {
|
|
3363
|
+
ans.push(this.push(el));
|
|
3364
|
+
}
|
|
3365
|
+
}
|
|
3366
|
+
return ans;
|
|
3367
|
+
}
|
|
3368
|
+
/**
|
|
3369
|
+
* Time Complexity: O(n)
|
|
3370
|
+
* Space Complexity: O(1)
|
|
3371
|
+
*
|
|
3372
|
+
* The toArray function returns a copy of the elements in an array.
|
|
3373
|
+
* @returns An array of type E.
|
|
3233
3374
|
*/
|
|
3234
3375
|
delete(element) {
|
|
3235
3376
|
const index = this.elements.indexOf(element);
|
|
3236
3377
|
return this.deleteAt(index);
|
|
3237
3378
|
}
|
|
3238
3379
|
/**
|
|
3239
|
-
*
|
|
3240
|
-
*
|
|
3241
|
-
*
|
|
3380
|
+
* Time Complexity: O(n)
|
|
3381
|
+
* Space Complexity: O(1)
|
|
3382
|
+
*
|
|
3383
|
+
* The toArray function returns a copy of the elements in an array.
|
|
3384
|
+
* @returns An array of type E.
|
|
3242
3385
|
*/
|
|
3243
3386
|
deleteAt(index) {
|
|
3244
3387
|
const spliced = this.elements.splice(index, 1);
|
|
@@ -3351,12 +3494,7 @@ var dataStructureTyped = (() => {
|
|
|
3351
3494
|
const { autoCompactRatio = 0.5 } = options;
|
|
3352
3495
|
this._autoCompactRatio = autoCompactRatio;
|
|
3353
3496
|
}
|
|
3354
|
-
|
|
3355
|
-
for (const el of elements) {
|
|
3356
|
-
if (this.toElementFn) this.push(this.toElementFn(el));
|
|
3357
|
-
else this.push(el);
|
|
3358
|
-
}
|
|
3359
|
-
}
|
|
3497
|
+
this.pushMany(elements);
|
|
3360
3498
|
}
|
|
3361
3499
|
/**
|
|
3362
3500
|
* The elements function returns the elements of this set.
|
|
@@ -3441,6 +3579,25 @@ var dataStructureTyped = (() => {
|
|
|
3441
3579
|
this.elements.push(element);
|
|
3442
3580
|
return true;
|
|
3443
3581
|
}
|
|
3582
|
+
/**
|
|
3583
|
+
* Time Complexity: O(k)
|
|
3584
|
+
* Space Complexity: O(k)
|
|
3585
|
+
*
|
|
3586
|
+
* The `pushMany` function iterates over elements and pushes them into an array after applying a
|
|
3587
|
+
* transformation function if provided.
|
|
3588
|
+
* @param {Iterable<E> | Iterable<R>} elements - The `elements` parameter in the `pushMany` function
|
|
3589
|
+
* is an iterable containing elements of type `E` or `R`.
|
|
3590
|
+
* @returns The `pushMany` function is returning an array of boolean values indicating whether each
|
|
3591
|
+
* element was successfully pushed into the data structure.
|
|
3592
|
+
*/
|
|
3593
|
+
pushMany(elements) {
|
|
3594
|
+
const ans = [];
|
|
3595
|
+
for (const el of elements) {
|
|
3596
|
+
if (this.toElementFn) ans.push(this.push(this.toElementFn(el)));
|
|
3597
|
+
else ans.push(this.push(el));
|
|
3598
|
+
}
|
|
3599
|
+
return ans;
|
|
3600
|
+
}
|
|
3444
3601
|
/**
|
|
3445
3602
|
* Time Complexity: O(1)
|
|
3446
3603
|
* Space Complexity: O(1)
|
|
@@ -3457,6 +3614,9 @@ var dataStructureTyped = (() => {
|
|
|
3457
3614
|
return first;
|
|
3458
3615
|
}
|
|
3459
3616
|
/**
|
|
3617
|
+
* Time Complexity: O(n)
|
|
3618
|
+
* Space Complexity: O(1)
|
|
3619
|
+
*
|
|
3460
3620
|
* The delete function removes an element from the list.
|
|
3461
3621
|
* @param {E} element - Specify the element to be deleted
|
|
3462
3622
|
* @return A boolean value indicating whether the element was successfully deleted or not
|
|
@@ -3466,6 +3626,9 @@ var dataStructureTyped = (() => {
|
|
|
3466
3626
|
return this.deleteAt(index);
|
|
3467
3627
|
}
|
|
3468
3628
|
/**
|
|
3629
|
+
* Time Complexity: O(n)
|
|
3630
|
+
* Space Complexity: O(1)
|
|
3631
|
+
*
|
|
3469
3632
|
* The deleteAt function deletes the element at a given index.
|
|
3470
3633
|
* @param {number} index - Determine the index of the element to be deleted
|
|
3471
3634
|
* @return A boolean value
|
|
@@ -3478,7 +3641,12 @@ var dataStructureTyped = (() => {
|
|
|
3478
3641
|
* Time Complexity: O(1)
|
|
3479
3642
|
* Space Complexity: O(1)
|
|
3480
3643
|
*
|
|
3481
|
-
*
|
|
3644
|
+
* The `at` function returns the element at a specified index adjusted by an offset, or `undefined`
|
|
3645
|
+
* if the index is out of bounds.
|
|
3646
|
+
* @param {number} index - The `index` parameter represents the position of the element you want to
|
|
3647
|
+
* retrieve from the data structure.
|
|
3648
|
+
* @returns The `at` method is returning the element at the specified index adjusted by the offset
|
|
3649
|
+
* `_offset`.
|
|
3482
3650
|
*/
|
|
3483
3651
|
at(index) {
|
|
3484
3652
|
return this.elements[index + this._offset];
|
|
@@ -3514,6 +3682,9 @@ var dataStructureTyped = (() => {
|
|
|
3514
3682
|
this._offset = 0;
|
|
3515
3683
|
}
|
|
3516
3684
|
/**
|
|
3685
|
+
* Time Complexity: O(n)
|
|
3686
|
+
* Space Complexity: O(1)
|
|
3687
|
+
*
|
|
3517
3688
|
* The `compact` function in TypeScript slices the elements array based on the offset and resets the
|
|
3518
3689
|
* offset to zero.
|
|
3519
3690
|
* @returns The `compact()` method is returning a boolean value of `true`.
|
|
@@ -3563,6 +3734,20 @@ var dataStructureTyped = (() => {
|
|
|
3563
3734
|
/**
|
|
3564
3735
|
* Time Complexity: O(n)
|
|
3565
3736
|
* Space Complexity: O(n)
|
|
3737
|
+
*
|
|
3738
|
+
* The `map` function in TypeScript creates a new Queue by applying a callback function to each
|
|
3739
|
+
* element in the original Queue.
|
|
3740
|
+
* @param callback - The `callback` parameter is a function that will be applied to each element in
|
|
3741
|
+
* the queue. It takes the current element, its index, and the queue itself as arguments, and returns
|
|
3742
|
+
* a new element.
|
|
3743
|
+
* @param [toElementFn] - The `toElementFn` parameter is an optional function that can be provided to
|
|
3744
|
+
* convert a raw element of type `RM` to a new element of type `EM`. This function is used within the
|
|
3745
|
+
* `map` method to transform each raw element before passing it to the `callback` function. If
|
|
3746
|
+
* @param {any} [thisArg] - The `thisArg` parameter in the `map` function is used to specify the
|
|
3747
|
+
* value of `this` when executing the `callback` function. It allows you to set the context (the
|
|
3748
|
+
* value of `this`) within the callback function. If `thisArg` is provided, it will be
|
|
3749
|
+
* @returns A new Queue object containing elements of type EM, which are the result of applying the
|
|
3750
|
+
* callback function to each element in the original Queue object.
|
|
3566
3751
|
*/
|
|
3567
3752
|
map(callback, toElementFn, thisArg) {
|
|
3568
3753
|
const newDeque = new _Queue([], { toElementFn });
|
|
@@ -3643,13 +3828,7 @@ var dataStructureTyped = (() => {
|
|
|
3643
3828
|
const needBucketNum = calcMinUnitsRequired(_size, this._bucketSize);
|
|
3644
3829
|
this._bucketFirst = this._bucketLast = (this._bucketCount >> 1) - (needBucketNum >> 1);
|
|
3645
3830
|
this._firstInBucket = this._lastInBucket = this._bucketSize - _size % this._bucketSize >> 1;
|
|
3646
|
-
|
|
3647
|
-
if (this.toElementFn) {
|
|
3648
|
-
this.push(this.toElementFn(el));
|
|
3649
|
-
} else {
|
|
3650
|
-
this.push(el);
|
|
3651
|
-
}
|
|
3652
|
-
}
|
|
3831
|
+
this.pushMany(elements);
|
|
3653
3832
|
}
|
|
3654
3833
|
/**
|
|
3655
3834
|
* The bucketSize function returns the size of the bucket.
|
|
@@ -3787,6 +3966,32 @@ var dataStructureTyped = (() => {
|
|
|
3787
3966
|
this._size -= 1;
|
|
3788
3967
|
return element;
|
|
3789
3968
|
}
|
|
3969
|
+
/**
|
|
3970
|
+
* Time Complexity: O(1)
|
|
3971
|
+
* Space Complexity: O(1)
|
|
3972
|
+
*
|
|
3973
|
+
* The `shift()` function removes and returns the first element from a data structure, updating the
|
|
3974
|
+
* internal state variables accordingly.
|
|
3975
|
+
* @returns The element that is being removed from the beginning of the data structure is being
|
|
3976
|
+
* returned.
|
|
3977
|
+
*/
|
|
3978
|
+
shift() {
|
|
3979
|
+
if (this._size === 0) return;
|
|
3980
|
+
const element = this._buckets[this._bucketFirst][this._firstInBucket];
|
|
3981
|
+
if (this._size !== 1) {
|
|
3982
|
+
if (this._firstInBucket < this._bucketSize - 1) {
|
|
3983
|
+
this._firstInBucket += 1;
|
|
3984
|
+
} else if (this._bucketFirst < this._bucketCount - 1) {
|
|
3985
|
+
this._bucketFirst += 1;
|
|
3986
|
+
this._firstInBucket = 0;
|
|
3987
|
+
} else {
|
|
3988
|
+
this._bucketFirst = 0;
|
|
3989
|
+
this._firstInBucket = 0;
|
|
3990
|
+
}
|
|
3991
|
+
}
|
|
3992
|
+
this._size -= 1;
|
|
3993
|
+
return element;
|
|
3994
|
+
}
|
|
3790
3995
|
/**
|
|
3791
3996
|
* Time Complexity: Amortized O(1)
|
|
3792
3997
|
* Space Complexity: O(n)
|
|
@@ -3816,30 +4021,53 @@ var dataStructureTyped = (() => {
|
|
|
3816
4021
|
return true;
|
|
3817
4022
|
}
|
|
3818
4023
|
/**
|
|
3819
|
-
* Time Complexity: O(
|
|
3820
|
-
* Space Complexity: O(
|
|
4024
|
+
* Time Complexity: O(k)
|
|
4025
|
+
* Space Complexity: O(k)
|
|
3821
4026
|
*
|
|
3822
|
-
* The `
|
|
3823
|
-
*
|
|
3824
|
-
* @
|
|
3825
|
-
*
|
|
4027
|
+
* The function `pushMany` iterates over elements and pushes them into an array after applying a
|
|
4028
|
+
* transformation function if provided.
|
|
4029
|
+
* @param {IterableWithSizeOrLength<E> | IterableWithSizeOrLength<R>} elements - The `elements`
|
|
4030
|
+
* parameter in the `pushMany` function is expected to be an iterable containing elements of type `E`
|
|
4031
|
+
* or `R`. It can be either an `IterableWithSizeOrLength<E>` or an `IterableWithSizeOrLength<R>`. The
|
|
4032
|
+
* function iterates over each element
|
|
4033
|
+
* @returns The `pushMany` function is returning an array of boolean values, where each value
|
|
4034
|
+
* represents the result of calling the `push` method on the current object instance with the
|
|
4035
|
+
* corresponding element from the input `elements` iterable.
|
|
3826
4036
|
*/
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
const
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
this._firstInBucket += 1;
|
|
3833
|
-
} else if (this._bucketFirst < this._bucketCount - 1) {
|
|
3834
|
-
this._bucketFirst += 1;
|
|
3835
|
-
this._firstInBucket = 0;
|
|
4037
|
+
pushMany(elements) {
|
|
4038
|
+
const ans = [];
|
|
4039
|
+
for (const el of elements) {
|
|
4040
|
+
if (this.toElementFn) {
|
|
4041
|
+
ans.push(this.push(this.toElementFn(el)));
|
|
3836
4042
|
} else {
|
|
3837
|
-
this.
|
|
3838
|
-
this._firstInBucket = 0;
|
|
4043
|
+
ans.push(this.push(el));
|
|
3839
4044
|
}
|
|
3840
4045
|
}
|
|
3841
|
-
|
|
3842
|
-
|
|
4046
|
+
return ans;
|
|
4047
|
+
}
|
|
4048
|
+
/**
|
|
4049
|
+
* Time Complexity: O(k)
|
|
4050
|
+
* Space Complexity: O(k)
|
|
4051
|
+
*
|
|
4052
|
+
* The `unshiftMany` function in TypeScript iterates over elements and adds them to the beginning of
|
|
4053
|
+
* an array, optionally converting them using a provided function.
|
|
4054
|
+
* @param {IterableWithSizeOrLength<E> | IterableWithSizeOrLength<R>} elements - The `elements`
|
|
4055
|
+
* parameter in the `unshiftMany` function is an iterable containing elements of type `E` or `R`. It
|
|
4056
|
+
* can be an array or any other iterable data structure that has a known size or length. The function
|
|
4057
|
+
* iterates over each element in the `elements` iterable and
|
|
4058
|
+
* @returns The `unshiftMany` function returns an array of boolean values indicating whether each
|
|
4059
|
+
* element was successfully added to the beginning of the array.
|
|
4060
|
+
*/
|
|
4061
|
+
unshiftMany(elements = []) {
|
|
4062
|
+
const ans = [];
|
|
4063
|
+
for (const el of elements) {
|
|
4064
|
+
if (this.toElementFn) {
|
|
4065
|
+
ans.push(this.unshift(this.toElementFn(el)));
|
|
4066
|
+
} else {
|
|
4067
|
+
ans.push(this.unshift(el));
|
|
4068
|
+
}
|
|
4069
|
+
}
|
|
4070
|
+
return ans;
|
|
3843
4071
|
}
|
|
3844
4072
|
/**
|
|
3845
4073
|
* Time Complexity: O(1)
|
|
@@ -4356,12 +4584,7 @@ var dataStructureTyped = (() => {
|
|
|
4356
4584
|
const { comparator } = options;
|
|
4357
4585
|
if (comparator) this._comparator = comparator;
|
|
4358
4586
|
}
|
|
4359
|
-
|
|
4360
|
-
for (const el of elements) {
|
|
4361
|
-
if (this.toElementFn) this.add(this.toElementFn(el));
|
|
4362
|
-
else this.add(el);
|
|
4363
|
-
}
|
|
4364
|
-
}
|
|
4587
|
+
this.addMany(elements);
|
|
4365
4588
|
}
|
|
4366
4589
|
/**
|
|
4367
4590
|
* The function returns an array of elements.
|
|
@@ -4397,13 +4620,40 @@ var dataStructureTyped = (() => {
|
|
|
4397
4620
|
* Time Complexity: O(log n)
|
|
4398
4621
|
* Space Complexity: O(1)
|
|
4399
4622
|
*
|
|
4400
|
-
*
|
|
4401
|
-
* @param element - The element to
|
|
4623
|
+
* The add function pushes an element into an array and then triggers a bubble-up operation.
|
|
4624
|
+
* @param {E} element - The `element` parameter represents the element that you want to add to the
|
|
4625
|
+
* data structure.
|
|
4626
|
+
* @returns The `add` method is returning a boolean value, which is the result of calling the
|
|
4627
|
+
* `_bubbleUp` method with the index `this.elements.length - 1` as an argument.
|
|
4402
4628
|
*/
|
|
4403
4629
|
add(element) {
|
|
4404
4630
|
this._elements.push(element);
|
|
4405
4631
|
return this._bubbleUp(this.elements.length - 1);
|
|
4406
4632
|
}
|
|
4633
|
+
/**
|
|
4634
|
+
* Time Complexity: O(k log n)
|
|
4635
|
+
* Space Complexity: O(1)
|
|
4636
|
+
*
|
|
4637
|
+
* The `addMany` function iterates over elements and adds them to a collection, returning an array of
|
|
4638
|
+
* boolean values indicating success or failure.
|
|
4639
|
+
* @param {Iterable<E> | Iterable<R>} elements - The `elements` parameter in the `addMany` method is
|
|
4640
|
+
* an iterable containing elements of type `E` or `R`. The method iterates over each element in the
|
|
4641
|
+
* iterable and adds them to the data structure. If a transformation function `_toElementFn` is
|
|
4642
|
+
* provided, it transforms the element
|
|
4643
|
+
* @returns The `addMany` method returns an array of boolean values indicating whether each element
|
|
4644
|
+
* in the input iterable was successfully added to the data structure.
|
|
4645
|
+
*/
|
|
4646
|
+
addMany(elements) {
|
|
4647
|
+
const ans = [];
|
|
4648
|
+
for (const el of elements) {
|
|
4649
|
+
if (this._toElementFn) {
|
|
4650
|
+
ans.push(this.add(this._toElementFn(el)));
|
|
4651
|
+
continue;
|
|
4652
|
+
}
|
|
4653
|
+
ans.push(this.add(el));
|
|
4654
|
+
}
|
|
4655
|
+
return ans;
|
|
4656
|
+
}
|
|
4407
4657
|
/**
|
|
4408
4658
|
* Time Complexity: O(log n)
|
|
4409
4659
|
* Space Complexity: O(1)
|
|
@@ -4597,7 +4847,7 @@ var dataStructureTyped = (() => {
|
|
|
4597
4847
|
return filteredList;
|
|
4598
4848
|
}
|
|
4599
4849
|
/**
|
|
4600
|
-
* Time Complexity: O(n
|
|
4850
|
+
* Time Complexity: O(n)
|
|
4601
4851
|
* Space Complexity: O(n)
|
|
4602
4852
|
*
|
|
4603
4853
|
* The `map` function creates a new heap by applying a callback function to each element of the
|
|
@@ -7120,6 +7370,8 @@ var dataStructureTyped = (() => {
|
|
|
7120
7370
|
this.high = high;
|
|
7121
7371
|
this.includeLow = includeLow;
|
|
7122
7372
|
this.includeHigh = includeHigh;
|
|
7373
|
+
if (!(isComparable(low) && isComparable(high))) throw new RangeError("low or high is not comparable");
|
|
7374
|
+
if (low > high) throw new RangeError("low must be less than or equal to high");
|
|
7123
7375
|
}
|
|
7124
7376
|
// Determine whether a key is within the range
|
|
7125
7377
|
isInRange(key, comparator) {
|
|
@@ -7260,7 +7512,7 @@ var dataStructureTyped = (() => {
|
|
|
7260
7512
|
* input parameter (`keyNodeEntryOrRaw`) and processes it accordingly to return a node or null
|
|
7261
7513
|
* value.
|
|
7262
7514
|
*/
|
|
7263
|
-
|
|
7515
|
+
_keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value) {
|
|
7264
7516
|
if (keyNodeEntryOrRaw === void 0) return [void 0, void 0];
|
|
7265
7517
|
if (keyNodeEntryOrRaw === null) return [null, void 0];
|
|
7266
7518
|
if (this.isNode(keyNodeEntryOrRaw)) return [keyNodeEntryOrRaw, value];
|
|
@@ -7437,7 +7689,7 @@ var dataStructureTyped = (() => {
|
|
|
7437
7689
|
* key was found and the node was replaced instead of inserted.
|
|
7438
7690
|
*/
|
|
7439
7691
|
add(keyNodeEntryOrRaw, value) {
|
|
7440
|
-
const [newNode, newValue] = this.
|
|
7692
|
+
const [newNode, newValue] = this._keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value);
|
|
7441
7693
|
if (newNode === void 0) return false;
|
|
7442
7694
|
if (!this._root) {
|
|
7443
7695
|
this._setRoot(newNode);
|
|
@@ -9120,8 +9372,8 @@ var dataStructureTyped = (() => {
|
|
|
9120
9372
|
* value associated with a key in a key-value pair.
|
|
9121
9373
|
* @returns either a NODE object or undefined.
|
|
9122
9374
|
*/
|
|
9123
|
-
|
|
9124
|
-
const [node, entryValue] = super.
|
|
9375
|
+
_keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value) {
|
|
9376
|
+
const [node, entryValue] = super._keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value);
|
|
9125
9377
|
if (node === null) return [void 0, void 0];
|
|
9126
9378
|
return [node, value != null ? value : entryValue];
|
|
9127
9379
|
}
|
|
@@ -9177,7 +9429,7 @@ var dataStructureTyped = (() => {
|
|
|
9177
9429
|
* @returns a boolean value.
|
|
9178
9430
|
*/
|
|
9179
9431
|
add(keyNodeEntryOrRaw, value) {
|
|
9180
|
-
const [newNode, newValue] = this.
|
|
9432
|
+
const [newNode, newValue] = this._keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value);
|
|
9181
9433
|
if (newNode === void 0) return false;
|
|
9182
9434
|
if (this._root === void 0) {
|
|
9183
9435
|
this._setRoot(newNode);
|
|
@@ -9423,6 +9675,31 @@ var dataStructureTyped = (() => {
|
|
|
9423
9675
|
}
|
|
9424
9676
|
return ans;
|
|
9425
9677
|
}
|
|
9678
|
+
/**
|
|
9679
|
+
* Time Complexity: O(log n)
|
|
9680
|
+
* Space Complexity: O(n)
|
|
9681
|
+
*
|
|
9682
|
+
* The `rangeSearch` function searches for nodes within a specified range in a binary search tree.
|
|
9683
|
+
* @param {Range<K> | [K, K]} range - The `range` parameter in the `rangeSearch` function can be
|
|
9684
|
+
* either a `Range` object or an array of two elements representing the range boundaries.
|
|
9685
|
+
* @param {C} callback - The `callback` parameter in the `rangeSearch` function is a callback
|
|
9686
|
+
* function that is used to process each node that is found within the specified range during the
|
|
9687
|
+
* search operation. It is of type `NodeCallback<NODE>`, where `NODE` is the type of nodes in the
|
|
9688
|
+
* data structure.
|
|
9689
|
+
* @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the `rangeSearch`
|
|
9690
|
+
* function represents the node from which the search for nodes within the specified range will
|
|
9691
|
+
* begin. It is the starting point for the range search operation.
|
|
9692
|
+
* @param {IterationType} iterationType - The `iterationType` parameter in the `rangeSearch` function
|
|
9693
|
+
* is used to specify the type of iteration to be performed during the search operation. It has a
|
|
9694
|
+
* default value of `this.iterationType`, which suggests that it is likely a property of the class or
|
|
9695
|
+
* object that the `rangeSearch`
|
|
9696
|
+
* @returns The `rangeSearch` function is returning the result of calling the `search` method with
|
|
9697
|
+
* the specified parameters.
|
|
9698
|
+
*/
|
|
9699
|
+
rangeSearch(range, callback = this._DEFAULT_NODE_CALLBACK, startNode = this._root, iterationType = this.iterationType) {
|
|
9700
|
+
const searchRange = range instanceof Range ? range : new Range(range[0], range[1]);
|
|
9701
|
+
return this.search(searchRange, false, callback, startNode, iterationType);
|
|
9702
|
+
}
|
|
9426
9703
|
/**
|
|
9427
9704
|
* Time Complexity: O(log n)
|
|
9428
9705
|
* Space Complexity: O(1)
|
|
@@ -10655,7 +10932,7 @@ var dataStructureTyped = (() => {
|
|
|
10655
10932
|
}
|
|
10656
10933
|
};
|
|
10657
10934
|
|
|
10658
|
-
// src/data-structures/binary-tree/
|
|
10935
|
+
// src/data-structures/binary-tree/red-black-tree.ts
|
|
10659
10936
|
var RedBlackTreeNode = class extends BSTNode {
|
|
10660
10937
|
/**
|
|
10661
10938
|
* The constructor function initializes a Red-Black Tree Node with a key, an optional value, and a
|
|
@@ -10820,7 +11097,7 @@ var dataStructureTyped = (() => {
|
|
|
10820
11097
|
* returns true. If the node cannot be added or updated, the method returns false.
|
|
10821
11098
|
*/
|
|
10822
11099
|
add(keyNodeEntryOrRaw, value) {
|
|
10823
|
-
const [newNode, newValue] = this.
|
|
11100
|
+
const [newNode, newValue] = this._keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value);
|
|
10824
11101
|
if (!this.isRealNode(newNode)) return false;
|
|
10825
11102
|
const insertStatus = this._insert(newNode);
|
|
10826
11103
|
if (insertStatus === "CREATED") {
|
|
@@ -11292,7 +11569,7 @@ var dataStructureTyped = (() => {
|
|
|
11292
11569
|
* times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
|
|
11293
11570
|
* @returns either a NODE object or undefined.
|
|
11294
11571
|
*/
|
|
11295
|
-
|
|
11572
|
+
_keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count = 1) {
|
|
11296
11573
|
if (keyNodeEntryOrRaw === void 0 || keyNodeEntryOrRaw === null) return [void 0, void 0];
|
|
11297
11574
|
if (this.isNode(keyNodeEntryOrRaw)) return [keyNodeEntryOrRaw, value];
|
|
11298
11575
|
if (this.isEntry(keyNodeEntryOrRaw)) {
|
|
@@ -11327,7 +11604,7 @@ var dataStructureTyped = (() => {
|
|
|
11327
11604
|
* @returns a boolean value.
|
|
11328
11605
|
*/
|
|
11329
11606
|
add(keyNodeEntryOrRaw, value, count = 1) {
|
|
11330
|
-
const [newNode, newValue] = this.
|
|
11607
|
+
const [newNode, newValue] = this._keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count);
|
|
11331
11608
|
if (newNode === void 0) return false;
|
|
11332
11609
|
const orgNodeCount = (newNode == null ? void 0 : newNode.count) || 0;
|
|
11333
11610
|
const inserted = super.add(newNode, newValue);
|
|
@@ -11641,7 +11918,7 @@ var dataStructureTyped = (() => {
|
|
|
11641
11918
|
* times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
|
|
11642
11919
|
* @returns either a NODE object or undefined.
|
|
11643
11920
|
*/
|
|
11644
|
-
|
|
11921
|
+
_keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count = 1) {
|
|
11645
11922
|
if (keyNodeEntryOrRaw === void 0 || keyNodeEntryOrRaw === null) return [void 0, void 0];
|
|
11646
11923
|
if (this.isNode(keyNodeEntryOrRaw)) return [keyNodeEntryOrRaw, value];
|
|
11647
11924
|
if (this.isEntry(keyNodeEntryOrRaw)) {
|
|
@@ -11685,7 +11962,7 @@ var dataStructureTyped = (() => {
|
|
|
11685
11962
|
* was successful, and false otherwise.
|
|
11686
11963
|
*/
|
|
11687
11964
|
add(keyNodeEntryOrRaw, value, count = 1) {
|
|
11688
|
-
const [newNode, newValue] = this.
|
|
11965
|
+
const [newNode, newValue] = this._keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count);
|
|
11689
11966
|
const orgCount = (newNode == null ? void 0 : newNode.count) || 0;
|
|
11690
11967
|
const isSuccessAdded = super.add(newNode, newValue);
|
|
11691
11968
|
if (isSuccessAdded) {
|
|
@@ -12853,7 +13130,7 @@ var dataStructureTyped = (() => {
|
|
|
12853
13130
|
* @returns The `addMany` method returns an array of boolean values indicating whether each word in
|
|
12854
13131
|
* the input iterable was successfully added to the data structure.
|
|
12855
13132
|
*/
|
|
12856
|
-
addMany(words
|
|
13133
|
+
addMany(words) {
|
|
12857
13134
|
const ans = [];
|
|
12858
13135
|
for (const word of words) {
|
|
12859
13136
|
if (this.toElementFn) {
|
|
@@ -12945,9 +13222,14 @@ var dataStructureTyped = (() => {
|
|
|
12945
13222
|
return isDeleted;
|
|
12946
13223
|
}
|
|
12947
13224
|
/**
|
|
12948
|
-
* Time Complexity: O(n)
|
|
12949
|
-
* Space Complexity: O(1)
|
|
13225
|
+
* Time Complexity: O(n)
|
|
13226
|
+
* Space Complexity: O(1)
|
|
12950
13227
|
*
|
|
13228
|
+
* The function `getHeight` calculates the height of a trie data structure starting from the root
|
|
13229
|
+
* node.
|
|
13230
|
+
* @returns The `getHeight` method returns the maximum depth or height of the trie tree starting from
|
|
13231
|
+
* the root node. It calculates the depth using a breadth-first search (BFS) traversal of the trie
|
|
13232
|
+
* tree and returns the maximum depth found.
|
|
12951
13233
|
*/
|
|
12952
13234
|
getHeight() {
|
|
12953
13235
|
const startNode = this.root;
|