data-structure-typed 1.51.9 → 1.52.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/README.md +141 -54
- 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 +13 -13
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +6 -6
- 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 +13 -13
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +6 -6
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +99 -99
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +54 -52
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +37 -45
- package/dist/cjs/data-structures/binary-tree/bst.js +17 -25
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +10 -10
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +6 -6
- 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 +12 -12
- 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/graph/directed-graph.js +2 -1
- package/dist/cjs/data-structures/graph/directed-graph.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 +27 -18
- package/dist/cjs/data-structures/queue/deque.js +43 -21
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +8 -29
- package/dist/cjs/data-structures/queue/queue.js +15 -32
- 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 +4 -4
- package/dist/cjs/types/common.d.ts +1 -22
- 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 +20 -4
- package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +5 -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 +4 -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/cjs/utils/number.js +1 -2
- package/dist/cjs/utils/number.js.map +1 -1
- package/dist/cjs/utils/utils.js +2 -2
- package/dist/cjs/utils/utils.js.map +1 -1
- 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 +13 -13
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +6 -6
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +13 -13
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +6 -6
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +99 -99
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +54 -52
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +37 -45
- package/dist/mjs/data-structures/binary-tree/bst.js +17 -25
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +10 -10
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +6 -6
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +12 -12
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +5 -5
- package/dist/mjs/data-structures/graph/directed-graph.js +2 -1
- 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 +27 -18
- package/dist/mjs/data-structures/queue/deque.js +43 -21
- package/dist/mjs/data-structures/queue/queue.d.ts +8 -29
- package/dist/mjs/data-structures/queue/queue.js +15 -32
- 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 +4 -4
- package/dist/mjs/types/common.d.ts +1 -22
- 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 +20 -4
- package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +5 -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 +4 -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 +732 -409
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +7 -7
- 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 +14 -15
- package/src/data-structures/binary-tree/avl-tree.ts +13 -14
- package/src/data-structures/binary-tree/binary-tree.ts +156 -152
- package/src/data-structures/binary-tree/bst.ts +52 -60
- package/src/data-structures/binary-tree/rb-tree.ts +12 -13
- package/src/data-structures/binary-tree/tree-multi-map.ts +12 -13
- package/src/data-structures/graph/directed-graph.ts +2 -1
- 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 +50 -25
- package/src/data-structures/queue/queue.ts +23 -37
- package/src/data-structures/stack/stack.ts +31 -26
- package/src/data-structures/trie/trie.ts +33 -18
- package/src/interfaces/binary-tree.ts +4 -5
- package/src/types/common.ts +2 -24
- 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 +24 -5
- package/src/types/data-structures/binary-tree/bst.ts +9 -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 +6 -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/graph/directed-graph.test.ts +28 -0
- package/test/unit/data-structures/heap/heap.test.ts +100 -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 +49 -0
- package/test/unit/data-structures/queue/queue.test.ts +56 -0
- package/dist/cjs/data-structures/base/iterable-base.js.map +0 -1
|
@@ -18,7 +18,7 @@ export class BSTNode extends BinaryTreeNode {
|
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* The function sets the left child of a node and updates the parent reference of the child.
|
|
21
|
-
* @param {NODE
|
|
21
|
+
* @param {OptBSTN<NODE>} v - The parameter `v` is of type `OptBSTN<NODE>`. It can either be an
|
|
22
22
|
* instance of the `NODE` class or `undefined`.
|
|
23
23
|
*/
|
|
24
24
|
set left(v) {
|
|
@@ -38,7 +38,7 @@ export class BSTNode extends BinaryTreeNode {
|
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
40
|
* The function sets the right child of a node and updates the parent reference of the child.
|
|
41
|
-
* @param {NODE
|
|
41
|
+
* @param {OptBSTN<NODE>} v - The parameter `v` is of type `OptBSTN<NODE>`. It can either be a
|
|
42
42
|
* `NODE` object or `undefined`.
|
|
43
43
|
*/
|
|
44
44
|
set right(v) {
|
|
@@ -111,8 +111,8 @@ export class BST extends BinaryTree {
|
|
|
111
111
|
}
|
|
112
112
|
/**
|
|
113
113
|
* The function overrides a method and converts a key, value pair or entry or raw element to a node.
|
|
114
|
-
* @param {R |
|
|
115
|
-
* type R or
|
|
114
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - A variable that can be of
|
|
115
|
+
* type R or BTNKeyOrNodeOrEntry<K, V, NODE>. It represents either a key, a node, an entry, or a raw
|
|
116
116
|
* element.
|
|
117
117
|
* @param {V} [value] - The `value` parameter is an optional value of type `V`. It represents the
|
|
118
118
|
* value associated with a key in a key-value pair.
|
|
@@ -127,7 +127,7 @@ export class BST extends BinaryTree {
|
|
|
127
127
|
*
|
|
128
128
|
* The function ensures the existence of a node in a data structure and returns it, or undefined if
|
|
129
129
|
* it doesn't exist.
|
|
130
|
-
* @param {R |
|
|
130
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
131
131
|
* `keyOrNodeOrEntryOrRawElement` can accept a value of type `R`, which represents the key, node,
|
|
132
132
|
* entry, or raw element that needs to be ensured in the tree.
|
|
133
133
|
* @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
|
|
@@ -141,8 +141,8 @@ export class BST extends BinaryTree {
|
|
|
141
141
|
}
|
|
142
142
|
/**
|
|
143
143
|
* The function checks if the input is an instance of the BSTNode class.
|
|
144
|
-
* @param {R |
|
|
145
|
-
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `
|
|
144
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
145
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
146
146
|
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
|
|
147
147
|
* an instance of the `BSTNode` class.
|
|
148
148
|
*/
|
|
@@ -154,8 +154,8 @@ export class BST extends BinaryTree {
|
|
|
154
154
|
* Space Complexity: O(1)
|
|
155
155
|
*
|
|
156
156
|
* The `add` function in TypeScript adds a new node to a binary search tree based on the key value.
|
|
157
|
-
* @param {R |
|
|
158
|
-
* `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `
|
|
157
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
158
|
+
* `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
159
159
|
* @param {V} [value] - The `value` parameter is an optional value that can be associated with the
|
|
160
160
|
* key in the binary search tree. If provided, it will be stored in the node along with the key.
|
|
161
161
|
* @returns a boolean value.
|
|
@@ -319,7 +319,7 @@ export class BST extends BinaryTree {
|
|
|
319
319
|
* @param [onlyOne=false] - A boolean value indicating whether to return only the first matching node
|
|
320
320
|
* or all matching nodes. If set to true, only the first matching node will be returned. If set to
|
|
321
321
|
* false, all matching nodes will be returned. The default value is false.
|
|
322
|
-
* @param {R |
|
|
322
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
323
323
|
* point for the search in the binary tree. It can be either a node object, a key-value pair, or an
|
|
324
324
|
* entry object. If it is not provided, the `root` of the binary tree is used as the starting point.
|
|
325
325
|
* @param {IterationType} iterationType - The `iterationType` parameter determines the type of
|
|
@@ -451,7 +451,7 @@ export class BST extends BinaryTree {
|
|
|
451
451
|
* @param {DFSOrderPattern} [pattern=IN] - The "pattern" parameter in the code snippet refers to the
|
|
452
452
|
* order in which the Depth-First Search (DFS) algorithm visits the nodes in a tree or graph. It can
|
|
453
453
|
* take one of the following values:
|
|
454
|
-
* @param {R |
|
|
454
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
455
455
|
* point for the depth-first search traversal. It can be either a root node, a key-value pair, or a
|
|
456
456
|
* node entry. If not specified, the default value is the root of the tree.
|
|
457
457
|
* @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter specifies the
|
|
@@ -475,7 +475,7 @@ export class BST extends BinaryTree {
|
|
|
475
475
|
* @param {C} callback - The `callback` parameter is a function that will be called for each node
|
|
476
476
|
* visited during the breadth-first search. It should take a single argument, which is the current
|
|
477
477
|
* node being visited, and it can return a value of any type.
|
|
478
|
-
* @param {R |
|
|
478
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
479
479
|
* point for the breadth-first search. It can be either a root node, a key-value pair, or an entry
|
|
480
480
|
* object. If no value is provided, the default value is the root of the tree.
|
|
481
481
|
* @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
|
|
@@ -499,7 +499,7 @@ export class BST extends BinaryTree {
|
|
|
499
499
|
* @param {C} callback - The `callback` parameter is a generic type `C` that extends
|
|
500
500
|
* `BTNCallback<NODE>`. It represents a callback function that will be called for each node in the
|
|
501
501
|
* tree during the iteration process.
|
|
502
|
-
* @param {R |
|
|
502
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
503
503
|
* point for listing the levels of the binary tree. It can be either a root node of the tree, a
|
|
504
504
|
* key-value pair representing a node in the tree, or a key representing a node in the tree. If no
|
|
505
505
|
* value is provided, the root of
|
|
@@ -527,7 +527,7 @@ export class BST extends BinaryTree {
|
|
|
527
527
|
* @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to
|
|
528
528
|
* traverse nodes that are lesser, greater, or both than the `targetNode`. It accepts the values -1,
|
|
529
529
|
* 0, or 1, where:
|
|
530
|
-
* @param {R |
|
|
530
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} targetNode - The `targetNode` parameter is the node in
|
|
531
531
|
* the binary tree that you want to start traversing from. It can be specified either by providing
|
|
532
532
|
* the key of the node, the node itself, or an entry containing the key and value of the node. If no
|
|
533
533
|
* `targetNode` is provided,
|
|
@@ -687,13 +687,9 @@ export class BST extends BinaryTree {
|
|
|
687
687
|
}
|
|
688
688
|
return balanced;
|
|
689
689
|
}
|
|
690
|
-
/**
|
|
691
|
-
* Time complexity: O(n)
|
|
692
|
-
* Space complexity: O(n)
|
|
693
|
-
*/
|
|
694
690
|
_DEFAULT_COMPARATOR = (a, b) => {
|
|
695
|
-
if (typeof a === 'object'
|
|
696
|
-
throw TypeError(
|
|
691
|
+
if (typeof a === 'object' || typeof b === 'object') {
|
|
692
|
+
throw TypeError(`When comparing object types, a custom comparator must be defined in the constructor's options parameter.`);
|
|
697
693
|
}
|
|
698
694
|
if (a > b)
|
|
699
695
|
return 1;
|
|
@@ -701,10 +697,6 @@ export class BST extends BinaryTree {
|
|
|
701
697
|
return -1;
|
|
702
698
|
return 0;
|
|
703
699
|
};
|
|
704
|
-
/**
|
|
705
|
-
* Time complexity: O(n)
|
|
706
|
-
* Space complexity: O(n)
|
|
707
|
-
*/
|
|
708
700
|
_comparator = this._DEFAULT_COMPARATOR;
|
|
709
701
|
/**
|
|
710
702
|
* Time Complexity: O(n)
|
|
@@ -720,7 +712,7 @@ export class BST extends BinaryTree {
|
|
|
720
712
|
/**
|
|
721
713
|
* The function sets the root of a tree-like structure and updates the parent property of the new
|
|
722
714
|
* root.
|
|
723
|
-
* @param {NODE
|
|
715
|
+
* @param {OptBSTN<NODE>} v - v is a parameter of type NODE or undefined.
|
|
724
716
|
*/
|
|
725
717
|
_setRoot(v) {
|
|
726
718
|
if (v) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { BinaryTreeDeleteResult, BTNCallback,
|
|
1
|
+
import type { BinaryTreeDeleteResult, BTNCallback, BTNKeyOrNodeOrEntry, CRUD, RBTNColor, RBTreeOptions, RedBlackTreeNested, RedBlackTreeNodeNested } from '../../types';
|
|
2
2
|
import { BTNEntry } from '../../types';
|
|
3
3
|
import { BST, BSTNode } from './bst';
|
|
4
4
|
import { IBinaryTree } from '../../interfaces';
|
|
5
|
-
export declare class RedBlackTreeNode<K
|
|
5
|
+
export declare class RedBlackTreeNode<K = any, V = any, NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNodeNested<K, V>> extends BSTNode<K, V, NODE> {
|
|
6
6
|
/**
|
|
7
7
|
* The constructor function initializes a Red-Black Tree Node with a key, an optional value, and a
|
|
8
8
|
* color.
|
|
@@ -27,7 +27,7 @@ export declare class RedBlackTreeNode<K extends Comparable, V = any, NODE extend
|
|
|
27
27
|
*/
|
|
28
28
|
set color(value: RBTNColor);
|
|
29
29
|
}
|
|
30
|
-
export declare class RedBlackTree<K
|
|
30
|
+
export declare class RedBlackTree<K = any, V = any, R = BTNEntry<K, V>, NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNode<K, V, RedBlackTreeNodeNested<K, V>>, TREE extends RedBlackTree<K, V, R, NODE, TREE> = RedBlackTree<K, V, R, NODE, RedBlackTreeNested<K, V, R, NODE>>> extends BST<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
|
|
31
31
|
/**
|
|
32
32
|
* This is the constructor function for a Red-Black Tree data structure in TypeScript.
|
|
33
33
|
* @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
|
|
@@ -38,7 +38,7 @@ export declare class RedBlackTree<K extends Comparable, V = any, R = BTNEntry<K,
|
|
|
38
38
|
* configuring the behavior of the Red-Black Tree. The specific properties and their meanings would
|
|
39
39
|
* depend on the implementation
|
|
40
40
|
*/
|
|
41
|
-
constructor(keysOrNodesOrEntriesOrRawElements?: Iterable<R |
|
|
41
|
+
constructor(keysOrNodesOrEntriesOrRawElements?: Iterable<R | BTNKeyOrNodeOrEntry<K, V, NODE>>, options?: RBTreeOptions<K, V, R>);
|
|
42
42
|
protected _root: NODE | undefined;
|
|
43
43
|
/**
|
|
44
44
|
* The function returns the root node of a tree or undefined if there is no root.
|
|
@@ -76,12 +76,12 @@ export declare class RedBlackTree<K extends Comparable, V = any, R = BTNEntry<K,
|
|
|
76
76
|
* Space Complexity: O(1)
|
|
77
77
|
*
|
|
78
78
|
* The function checks if the input is an instance of the RedBlackTreeNode class.
|
|
79
|
-
* @param {R |
|
|
80
|
-
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `
|
|
79
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
80
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
81
81
|
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
|
|
82
82
|
* an instance of the `RedBlackTreeNode` class.
|
|
83
83
|
*/
|
|
84
|
-
isNode(keyOrNodeOrEntryOrRawElement: R |
|
|
84
|
+
isNode(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntryOrRawElement is NODE;
|
|
85
85
|
/**
|
|
86
86
|
* Time Complexity: O(1)
|
|
87
87
|
* Space Complexity: O(1)
|
|
@@ -104,8 +104,8 @@ export declare class RedBlackTree<K extends Comparable, V = any, R = BTNEntry<K,
|
|
|
104
104
|
*
|
|
105
105
|
* The function adds a new node to a binary search tree and returns true if the node was successfully
|
|
106
106
|
* added.
|
|
107
|
-
* @param {R |
|
|
108
|
-
* `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `
|
|
107
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
108
|
+
* `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
109
109
|
* @param {V} [value] - The `value` parameter is an optional value that you want to associate with
|
|
110
110
|
* the key in the data structure. It represents the value that you want to add or update in the data
|
|
111
111
|
* structure.
|
|
@@ -113,7 +113,7 @@ export declare class RedBlackTree<K extends Comparable, V = any, R = BTNEntry<K,
|
|
|
113
113
|
* the method returns true. If the node already exists and its value is updated, the method also
|
|
114
114
|
* returns true. If the node cannot be added or updated, the method returns false.
|
|
115
115
|
*/
|
|
116
|
-
add(keyOrNodeOrEntryOrRawElement: R |
|
|
116
|
+
add(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean;
|
|
117
117
|
/**
|
|
118
118
|
* Time Complexity: O(log n)
|
|
119
119
|
* Space Complexity: O(1)
|
|
@@ -95,8 +95,8 @@ export class RedBlackTree extends BST {
|
|
|
95
95
|
* Space Complexity: O(1)
|
|
96
96
|
*
|
|
97
97
|
* The function checks if the input is an instance of the RedBlackTreeNode class.
|
|
98
|
-
* @param {R |
|
|
99
|
-
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `
|
|
98
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
99
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
100
100
|
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
|
|
101
101
|
* an instance of the `RedBlackTreeNode` class.
|
|
102
102
|
*/
|
|
@@ -114,11 +114,11 @@ export class RedBlackTree extends BST {
|
|
|
114
114
|
// *
|
|
115
115
|
// * The function `keyValueOrEntryOrRawElementToNode` takes a key, value, or entry and returns a node if it is
|
|
116
116
|
// * valid, otherwise it returns undefined.
|
|
117
|
-
// * @param {
|
|
117
|
+
// * @param {BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The key, value, or entry to convert.
|
|
118
118
|
// * @param {V} [value] - The value associated with the key (if `keyOrNodeOrEntryOrRawElement` is a key).
|
|
119
119
|
// * @returns {NODE | undefined} - The corresponding Red-Black Tree node, or `undefined` if conversion fails.
|
|
120
120
|
// */
|
|
121
|
-
// override keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R |
|
|
121
|
+
// override keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V): NODE | undefined {
|
|
122
122
|
//
|
|
123
123
|
// if (keyOrNodeOrEntryOrRawElement === null || keyOrNodeOrEntryOrRawElement === undefined) return;
|
|
124
124
|
// if (this.isNode(keyOrNodeOrEntryOrRawElement)) return keyOrNodeOrEntryOrRawElement;
|
|
@@ -163,8 +163,8 @@ export class RedBlackTree extends BST {
|
|
|
163
163
|
*
|
|
164
164
|
* The function adds a new node to a binary search tree and returns true if the node was successfully
|
|
165
165
|
* added.
|
|
166
|
-
* @param {R |
|
|
167
|
-
* `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `
|
|
166
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
167
|
+
* `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
168
168
|
* @param {V} [value] - The `value` parameter is an optional value that you want to associate with
|
|
169
169
|
* the key in the data structure. It represents the value that you want to add or update in the data
|
|
170
170
|
* structure.
|
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback,
|
|
8
|
+
import type { BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, BTNKeyOrNodeOrEntry, IterationType, RBTNColor, TreeMultiMapNested, TreeMultiMapNodeNested, TreeMultiMapOptions } from '../../types';
|
|
9
9
|
import { BTNEntry } from '../../types';
|
|
10
10
|
import { IBinaryTree } from '../../interfaces';
|
|
11
11
|
import { RedBlackTree, RedBlackTreeNode } from './rb-tree';
|
|
12
|
-
export declare class TreeMultiMapNode<K
|
|
12
|
+
export declare class TreeMultiMapNode<K = any, V = any, NODE extends TreeMultiMapNode<K, V, NODE> = TreeMultiMapNodeNested<K, V>> extends RedBlackTreeNode<K, V, NODE> {
|
|
13
13
|
/**
|
|
14
14
|
* The constructor function initializes a Red-Black Tree node with a key, value, count, and color.
|
|
15
15
|
* @param {K} key - The key parameter represents the key of the node in the Red-Black Tree. It is
|
|
@@ -36,7 +36,7 @@ export declare class TreeMultiMapNode<K extends Comparable, V = any, NODE extend
|
|
|
36
36
|
*/
|
|
37
37
|
set count(value: number);
|
|
38
38
|
}
|
|
39
|
-
export declare class TreeMultiMap<K
|
|
39
|
+
export declare class TreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE extends TreeMultiMapNode<K, V, NODE> = TreeMultiMapNode<K, V, TreeMultiMapNodeNested<K, V>>, TREE extends TreeMultiMap<K, V, R, NODE, TREE> = TreeMultiMap<K, V, R, NODE, TreeMultiMapNested<K, V, R, NODE>>> extends RedBlackTree<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
|
|
40
40
|
/**
|
|
41
41
|
* The constructor function initializes a TreeMultiMap object with optional initial data.
|
|
42
42
|
* @param keysOrNodesOrEntriesOrRawElements - The parameter `keysOrNodesOrEntriesOrRawElements` is an
|
|
@@ -46,7 +46,7 @@ export declare class TreeMultiMap<K extends Comparable, V = any, R = BTNEntry<K,
|
|
|
46
46
|
* behavior of the `TreeMultiMap` constructor. It can include properties such as `compareKeys` and
|
|
47
47
|
* `compareValues`, which are functions used to compare keys and values respectively.
|
|
48
48
|
*/
|
|
49
|
-
constructor(keysOrNodesOrEntriesOrRawElements?: Iterable<
|
|
49
|
+
constructor(keysOrNodesOrEntriesOrRawElements?: Iterable<BTNKeyOrNodeOrEntry<K, V, NODE>>, options?: TreeMultiMapOptions<K, V, R>);
|
|
50
50
|
protected _count: number;
|
|
51
51
|
/**
|
|
52
52
|
* The function calculates the sum of the count property of all nodes in a tree structure.
|
|
@@ -92,8 +92,8 @@ export declare class TreeMultiMap<K extends Comparable, V = any, R = BTNEntry<K,
|
|
|
92
92
|
/**
|
|
93
93
|
* The function `keyValueOrEntryOrRawElementToNode` takes in a key, value, and count and returns a
|
|
94
94
|
* node based on the input.
|
|
95
|
-
* @param {R |
|
|
96
|
-
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `
|
|
95
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
96
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
97
97
|
* @param {V} [value] - The `value` parameter is an optional value that represents the value
|
|
98
98
|
* associated with the key in the node. It is used when creating a new node or updating the value of
|
|
99
99
|
* an existing node.
|
|
@@ -101,15 +101,15 @@ export declare class TreeMultiMap<K extends Comparable, V = any, R = BTNEntry<K,
|
|
|
101
101
|
* times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
|
|
102
102
|
* @returns either a NODE object or undefined.
|
|
103
103
|
*/
|
|
104
|
-
keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R |
|
|
104
|
+
keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V, count?: number): NODE | undefined;
|
|
105
105
|
/**
|
|
106
106
|
* The function checks if the input is an instance of the TreeMultiMapNode class.
|
|
107
|
-
* @param {R |
|
|
108
|
-
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `
|
|
107
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
108
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
109
109
|
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
|
|
110
110
|
* an instance of the `TreeMultiMapNode` class.
|
|
111
111
|
*/
|
|
112
|
-
isNode(keyOrNodeOrEntryOrRawElement: R |
|
|
112
|
+
isNode(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntryOrRawElement is NODE;
|
|
113
113
|
/**
|
|
114
114
|
* Time Complexity: O(log n)
|
|
115
115
|
* Space Complexity: O(1)
|
|
@@ -120,7 +120,7 @@ export declare class TreeMultiMap<K extends Comparable, V = any, R = BTNEntry<K,
|
|
|
120
120
|
*
|
|
121
121
|
* The function overrides the add method of a class and adds a new node to a data structure, updating
|
|
122
122
|
* the count and returning a boolean indicating success.
|
|
123
|
-
* @param {R |
|
|
123
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
|
|
124
124
|
* `keyOrNodeOrEntryOrRawElement` parameter can accept one of the following types:
|
|
125
125
|
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
126
126
|
* data structure. It is an optional parameter, so it can be omitted if not needed.
|
|
@@ -130,7 +130,7 @@ export declare class TreeMultiMap<K extends Comparable, V = any, R = BTNEntry<K,
|
|
|
130
130
|
* @returns The method is returning a boolean value. It returns true if the addition of the new node
|
|
131
131
|
* was successful, and false otherwise.
|
|
132
132
|
*/
|
|
133
|
-
add(keyOrNodeOrEntryOrRawElement: R |
|
|
133
|
+
add(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V, count?: number): boolean;
|
|
134
134
|
/**
|
|
135
135
|
* Time Complexity: O(log n)
|
|
136
136
|
* Space Complexity: O(1)
|
|
@@ -107,8 +107,8 @@ export class TreeMultiMap extends RedBlackTree {
|
|
|
107
107
|
/**
|
|
108
108
|
* The function `keyValueOrEntryOrRawElementToNode` takes in a key, value, and count and returns a
|
|
109
109
|
* node based on the input.
|
|
110
|
-
* @param {R |
|
|
111
|
-
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `
|
|
110
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
111
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
112
112
|
* @param {V} [value] - The `value` parameter is an optional value that represents the value
|
|
113
113
|
* associated with the key in the node. It is used when creating a new node or updating the value of
|
|
114
114
|
* an existing node.
|
|
@@ -139,8 +139,8 @@ export class TreeMultiMap extends RedBlackTree {
|
|
|
139
139
|
}
|
|
140
140
|
/**
|
|
141
141
|
* The function checks if the input is an instance of the TreeMultiMapNode class.
|
|
142
|
-
* @param {R |
|
|
143
|
-
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `
|
|
142
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
143
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
144
144
|
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
|
|
145
145
|
* an instance of the `TreeMultiMapNode` class.
|
|
146
146
|
*/
|
|
@@ -157,7 +157,7 @@ export class TreeMultiMap extends RedBlackTree {
|
|
|
157
157
|
*
|
|
158
158
|
* The function overrides the add method of a class and adds a new node to a data structure, updating
|
|
159
159
|
* the count and returning a boolean indicating success.
|
|
160
|
-
* @param {R |
|
|
160
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
|
|
161
161
|
* `keyOrNodeOrEntryOrRawElement` parameter can accept one of the following types:
|
|
162
162
|
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
163
163
|
* data structure. It is an optional parameter, so it can be omitted if not needed.
|
|
@@ -217,7 +217,8 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
217
217
|
if (vertex) {
|
|
218
218
|
const neighbors = this.getNeighbors(vertex);
|
|
219
219
|
for (const neighbor of neighbors) {
|
|
220
|
-
this._inEdgeMap.delete(neighbor);
|
|
220
|
+
// this._inEdgeMap.delete(neighbor);
|
|
221
|
+
this.deleteEdgeSrcToDest(vertex, neighbor);
|
|
221
222
|
}
|
|
222
223
|
this._outEdgeMap.delete(vertex);
|
|
223
224
|
this._inEdgeMap.delete(vertex);
|
|
@@ -150,7 +150,7 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
150
150
|
* @returns The `map` method is returning a new `HashMap` object with the transformed values based on
|
|
151
151
|
* the provided callback function.
|
|
152
152
|
*/
|
|
153
|
-
map<
|
|
153
|
+
map<VM>(callbackfn: EntryCallback<K, V, VM>, thisArg?: any): HashMap<K, VM>;
|
|
154
154
|
/**
|
|
155
155
|
* Time Complexity: O(n)
|
|
156
156
|
* Space Complexity: O(n)
|
|
@@ -482,7 +482,7 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
482
482
|
* @returns a new `LinkedHashMap` object with the values mapped according to the provided callback
|
|
483
483
|
* function.
|
|
484
484
|
*/
|
|
485
|
-
map<
|
|
485
|
+
map<VM>(callback: EntryCallback<K, V, VM>, thisArg?: any): LinkedHashMap<K, VM>;
|
|
486
486
|
/**
|
|
487
487
|
* Time Complexity: O(1)
|
|
488
488
|
* Space Complexity: O(1)
|