deque-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/dist/data-structures/base/index.d.ts +2 -1
- package/dist/data-structures/base/index.js +2 -1
- package/dist/data-structures/base/iterable-element-base.d.ts +171 -0
- package/dist/data-structures/base/iterable-element-base.js +225 -0
- package/dist/data-structures/base/{iterable-base.d.ts → iterable-entry-base.d.ts} +4 -147
- package/dist/data-structures/base/{iterable-base.js → iterable-entry-base.js} +12 -189
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +13 -13
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +6 -6
- package/dist/data-structures/binary-tree/avl-tree.d.ts +13 -13
- package/dist/data-structures/binary-tree/avl-tree.js +6 -6
- package/dist/data-structures/binary-tree/binary-tree.d.ts +99 -99
- package/dist/data-structures/binary-tree/binary-tree.js +54 -52
- package/dist/data-structures/binary-tree/bst.d.ts +37 -45
- package/dist/data-structures/binary-tree/bst.js +17 -25
- package/dist/data-structures/binary-tree/rb-tree.d.ts +10 -10
- package/dist/data-structures/binary-tree/rb-tree.js +6 -6
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +12 -12
- package/dist/data-structures/binary-tree/tree-multi-map.js +5 -5
- package/dist/data-structures/graph/directed-graph.js +2 -1
- package/dist/data-structures/hash/hash-map.d.ts +2 -2
- package/dist/data-structures/heap/heap.d.ts +43 -114
- package/dist/data-structures/heap/heap.js +59 -127
- package/dist/data-structures/heap/max-heap.d.ts +50 -4
- package/dist/data-structures/heap/max-heap.js +76 -10
- package/dist/data-structures/heap/min-heap.d.ts +51 -5
- package/dist/data-structures/heap/min-heap.js +68 -11
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +22 -28
- package/dist/data-structures/linked-list/doubly-linked-list.js +26 -28
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +22 -25
- package/dist/data-structures/linked-list/singly-linked-list.js +29 -26
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +50 -4
- package/dist/data-structures/priority-queue/max-priority-queue.js +79 -10
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +51 -5
- package/dist/data-structures/priority-queue/min-priority-queue.js +71 -11
- package/dist/data-structures/priority-queue/priority-queue.d.ts +50 -4
- package/dist/data-structures/priority-queue/priority-queue.js +70 -1
- package/dist/data-structures/queue/deque.d.ts +27 -18
- package/dist/data-structures/queue/deque.js +43 -21
- package/dist/data-structures/queue/queue.d.ts +8 -29
- package/dist/data-structures/queue/queue.js +15 -32
- package/dist/data-structures/stack/stack.d.ts +17 -22
- package/dist/data-structures/stack/stack.js +25 -24
- package/dist/data-structures/trie/trie.d.ts +18 -13
- package/dist/data-structures/trie/trie.js +26 -15
- package/dist/interfaces/binary-tree.d.ts +4 -4
- package/dist/types/common.d.ts +1 -22
- package/dist/types/data-structures/base/base.d.ts +5 -2
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -3
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +2 -3
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +20 -4
- package/dist/types/data-structures/binary-tree/bst.d.ts +5 -3
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +2 -3
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -3
- package/dist/types/data-structures/heap/heap.d.ts +3 -2
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +2 -1
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/types/data-structures/queue/deque.d.ts +4 -2
- package/dist/types/data-structures/queue/queue.d.ts +2 -1
- package/dist/types/data-structures/stack/stack.d.ts +2 -1
- package/dist/types/data-structures/trie/trie.d.ts +3 -2
- package/package.json +2 -2
- 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
|
@@ -19,7 +19,7 @@ class BSTNode extends binary_tree_1.BinaryTreeNode {
|
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* The function sets the left child of a node and updates the parent reference of the child.
|
|
22
|
-
* @param {NODE
|
|
22
|
+
* @param {OptBSTN<NODE>} v - The parameter `v` is of type `OptBSTN<NODE>`. It can either be an
|
|
23
23
|
* instance of the `NODE` class or `undefined`.
|
|
24
24
|
*/
|
|
25
25
|
set left(v) {
|
|
@@ -38,7 +38,7 @@ class BSTNode extends binary_tree_1.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) {
|
|
@@ -70,13 +70,9 @@ class BST extends binary_tree_1.BinaryTree {
|
|
|
70
70
|
constructor(keysOrNodesOrEntriesOrRawElements = [], options) {
|
|
71
71
|
super([], options);
|
|
72
72
|
this._root = undefined;
|
|
73
|
-
/**
|
|
74
|
-
* Time complexity: O(n)
|
|
75
|
-
* Space complexity: O(n)
|
|
76
|
-
*/
|
|
77
73
|
this._DEFAULT_COMPARATOR = (a, b) => {
|
|
78
|
-
if (typeof a === 'object'
|
|
79
|
-
throw TypeError(
|
|
74
|
+
if (typeof a === 'object' || typeof b === 'object') {
|
|
75
|
+
throw TypeError(`When comparing object types, a custom comparator must be defined in the constructor's options parameter.`);
|
|
80
76
|
}
|
|
81
77
|
if (a > b)
|
|
82
78
|
return 1;
|
|
@@ -84,10 +80,6 @@ class BST extends binary_tree_1.BinaryTree {
|
|
|
84
80
|
return -1;
|
|
85
81
|
return 0;
|
|
86
82
|
};
|
|
87
|
-
/**
|
|
88
|
-
* Time complexity: O(n)
|
|
89
|
-
* Space complexity: O(n)
|
|
90
|
-
*/
|
|
91
83
|
this._comparator = this._DEFAULT_COMPARATOR;
|
|
92
84
|
if (options) {
|
|
93
85
|
const { comparator } = options;
|
|
@@ -127,8 +119,8 @@ class BST extends binary_tree_1.BinaryTree {
|
|
|
127
119
|
}
|
|
128
120
|
/**
|
|
129
121
|
* The function overrides a method and converts a key, value pair or entry or raw element to a node.
|
|
130
|
-
* @param {R |
|
|
131
|
-
* type R or
|
|
122
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - A variable that can be of
|
|
123
|
+
* type R or BTNKeyOrNodeOrEntry<K, V, NODE>. It represents either a key, a node, an entry, or a raw
|
|
132
124
|
* element.
|
|
133
125
|
* @param {V} [value] - The `value` parameter is an optional value of type `V`. It represents the
|
|
134
126
|
* value associated with a key in a key-value pair.
|
|
@@ -144,7 +136,7 @@ class BST extends binary_tree_1.BinaryTree {
|
|
|
144
136
|
*
|
|
145
137
|
* The function ensures the existence of a node in a data structure and returns it, or undefined if
|
|
146
138
|
* it doesn't exist.
|
|
147
|
-
* @param {R |
|
|
139
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
148
140
|
* `keyOrNodeOrEntryOrRawElement` can accept a value of type `R`, which represents the key, node,
|
|
149
141
|
* entry, or raw element that needs to be ensured in the tree.
|
|
150
142
|
* @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
|
|
@@ -159,8 +151,8 @@ class BST extends binary_tree_1.BinaryTree {
|
|
|
159
151
|
}
|
|
160
152
|
/**
|
|
161
153
|
* The function checks if the input is an instance of the BSTNode class.
|
|
162
|
-
* @param {R |
|
|
163
|
-
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `
|
|
154
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
155
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
164
156
|
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
|
|
165
157
|
* an instance of the `BSTNode` class.
|
|
166
158
|
*/
|
|
@@ -172,8 +164,8 @@ class BST extends binary_tree_1.BinaryTree {
|
|
|
172
164
|
* Space Complexity: O(1)
|
|
173
165
|
*
|
|
174
166
|
* The `add` function in TypeScript adds a new node to a binary search tree based on the key value.
|
|
175
|
-
* @param {R |
|
|
176
|
-
* `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `
|
|
167
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
168
|
+
* `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
177
169
|
* @param {V} [value] - The `value` parameter is an optional value that can be associated with the
|
|
178
170
|
* key in the binary search tree. If provided, it will be stored in the node along with the key.
|
|
179
171
|
* @returns a boolean value.
|
|
@@ -337,7 +329,7 @@ class BST extends binary_tree_1.BinaryTree {
|
|
|
337
329
|
* @param [onlyOne=false] - A boolean value indicating whether to return only the first matching node
|
|
338
330
|
* or all matching nodes. If set to true, only the first matching node will be returned. If set to
|
|
339
331
|
* false, all matching nodes will be returned. The default value is false.
|
|
340
|
-
* @param {R |
|
|
332
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
341
333
|
* point for the search in the binary tree. It can be either a node object, a key-value pair, or an
|
|
342
334
|
* entry object. If it is not provided, the `root` of the binary tree is used as the starting point.
|
|
343
335
|
* @param {IterationType} iterationType - The `iterationType` parameter determines the type of
|
|
@@ -470,7 +462,7 @@ class BST extends binary_tree_1.BinaryTree {
|
|
|
470
462
|
* @param {DFSOrderPattern} [pattern=IN] - The "pattern" parameter in the code snippet refers to the
|
|
471
463
|
* order in which the Depth-First Search (DFS) algorithm visits the nodes in a tree or graph. It can
|
|
472
464
|
* take one of the following values:
|
|
473
|
-
* @param {R |
|
|
465
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
474
466
|
* point for the depth-first search traversal. It can be either a root node, a key-value pair, or a
|
|
475
467
|
* node entry. If not specified, the default value is the root of the tree.
|
|
476
468
|
* @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter specifies the
|
|
@@ -494,7 +486,7 @@ class BST extends binary_tree_1.BinaryTree {
|
|
|
494
486
|
* @param {C} callback - The `callback` parameter is a function that will be called for each node
|
|
495
487
|
* visited during the breadth-first search. It should take a single argument, which is the current
|
|
496
488
|
* node being visited, and it can return a value of any type.
|
|
497
|
-
* @param {R |
|
|
489
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
498
490
|
* point for the breadth-first search. It can be either a root node, a key-value pair, or an entry
|
|
499
491
|
* object. If no value is provided, the default value is the root of the tree.
|
|
500
492
|
* @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
|
|
@@ -518,7 +510,7 @@ class BST extends binary_tree_1.BinaryTree {
|
|
|
518
510
|
* @param {C} callback - The `callback` parameter is a generic type `C` that extends
|
|
519
511
|
* `BTNCallback<NODE>`. It represents a callback function that will be called for each node in the
|
|
520
512
|
* tree during the iteration process.
|
|
521
|
-
* @param {R |
|
|
513
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
522
514
|
* point for listing the levels of the binary tree. It can be either a root node of the tree, a
|
|
523
515
|
* key-value pair representing a node in the tree, or a key representing a node in the tree. If no
|
|
524
516
|
* value is provided, the root of
|
|
@@ -546,7 +538,7 @@ class BST extends binary_tree_1.BinaryTree {
|
|
|
546
538
|
* @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to
|
|
547
539
|
* traverse nodes that are lesser, greater, or both than the `targetNode`. It accepts the values -1,
|
|
548
540
|
* 0, or 1, where:
|
|
549
|
-
* @param {R |
|
|
541
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} targetNode - The `targetNode` parameter is the node in
|
|
550
542
|
* the binary tree that you want to start traversing from. It can be specified either by providing
|
|
551
543
|
* the key of the node, the node itself, or an entry containing the key and value of the node. If no
|
|
552
544
|
* `targetNode` is provided,
|
|
@@ -721,7 +713,7 @@ class BST extends binary_tree_1.BinaryTree {
|
|
|
721
713
|
/**
|
|
722
714
|
* The function sets the root of a tree-like structure and updates the parent property of the new
|
|
723
715
|
* root.
|
|
724
|
-
* @param {NODE
|
|
716
|
+
* @param {OptBSTN<NODE>} v - v is a parameter of type NODE or undefined.
|
|
725
717
|
*/
|
|
726
718
|
_setRoot(v) {
|
|
727
719
|
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)
|
|
@@ -94,8 +94,8 @@ class RedBlackTree extends bst_1.BST {
|
|
|
94
94
|
* Space Complexity: O(1)
|
|
95
95
|
*
|
|
96
96
|
* The function checks if the input is an instance of the RedBlackTreeNode class.
|
|
97
|
-
* @param {R |
|
|
98
|
-
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `
|
|
97
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
98
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
99
99
|
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
|
|
100
100
|
* an instance of the `RedBlackTreeNode` class.
|
|
101
101
|
*/
|
|
@@ -113,11 +113,11 @@ class RedBlackTree extends bst_1.BST {
|
|
|
113
113
|
// *
|
|
114
114
|
// * The function `keyValueOrEntryOrRawElementToNode` takes a key, value, or entry and returns a node if it is
|
|
115
115
|
// * valid, otherwise it returns undefined.
|
|
116
|
-
// * @param {
|
|
116
|
+
// * @param {BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The key, value, or entry to convert.
|
|
117
117
|
// * @param {V} [value] - The value associated with the key (if `keyOrNodeOrEntryOrRawElement` is a key).
|
|
118
118
|
// * @returns {NODE | undefined} - The corresponding Red-Black Tree node, or `undefined` if conversion fails.
|
|
119
119
|
// */
|
|
120
|
-
// override keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R |
|
|
120
|
+
// override keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V): NODE | undefined {
|
|
121
121
|
//
|
|
122
122
|
// if (keyOrNodeOrEntryOrRawElement === null || keyOrNodeOrEntryOrRawElement === undefined) return;
|
|
123
123
|
// if (this.isNode(keyOrNodeOrEntryOrRawElement)) return keyOrNodeOrEntryOrRawElement;
|
|
@@ -162,8 +162,8 @@ class RedBlackTree extends bst_1.BST {
|
|
|
162
162
|
*
|
|
163
163
|
* The function adds a new node to a binary search tree and returns true if the node was successfully
|
|
164
164
|
* added.
|
|
165
|
-
* @param {R |
|
|
166
|
-
* `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `
|
|
165
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
166
|
+
* `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
167
167
|
* @param {V} [value] - The `value` parameter is an optional value that you want to associate with
|
|
168
168
|
* the key in the data structure. It represents the value that you want to add or update in the data
|
|
169
169
|
* 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)
|
|
@@ -108,8 +108,8 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
|
|
|
108
108
|
/**
|
|
109
109
|
* The function `keyValueOrEntryOrRawElementToNode` takes in a key, value, and count and returns a
|
|
110
110
|
* node based on the input.
|
|
111
|
-
* @param {R |
|
|
112
|
-
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `
|
|
111
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
112
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
113
113
|
* @param {V} [value] - The `value` parameter is an optional value that represents the value
|
|
114
114
|
* associated with the key in the node. It is used when creating a new node or updating the value of
|
|
115
115
|
* an existing node.
|
|
@@ -140,8 +140,8 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
|
|
|
140
140
|
}
|
|
141
141
|
/**
|
|
142
142
|
* The function checks if the input is an instance of the TreeMultiMapNode class.
|
|
143
|
-
* @param {R |
|
|
144
|
-
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `
|
|
143
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
144
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
145
145
|
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
|
|
146
146
|
* an instance of the `TreeMultiMapNode` class.
|
|
147
147
|
*/
|
|
@@ -158,7 +158,7 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
|
|
|
158
158
|
*
|
|
159
159
|
* The function overrides the add method of a class and adds a new node to a data structure, updating
|
|
160
160
|
* the count and returning a boolean indicating success.
|
|
161
|
-
* @param {R |
|
|
161
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
|
|
162
162
|
* `keyOrNodeOrEntryOrRawElement` parameter can accept one of the following types:
|
|
163
163
|
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
164
164
|
* data structure. It is an optional parameter, so it can be omitted if not needed.
|
|
@@ -220,7 +220,8 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
220
220
|
if (vertex) {
|
|
221
221
|
const neighbors = this.getNeighbors(vertex);
|
|
222
222
|
for (const neighbor of neighbors) {
|
|
223
|
-
this._inEdgeMap.delete(neighbor);
|
|
223
|
+
// this._inEdgeMap.delete(neighbor);
|
|
224
|
+
this.deleteEdgeSrcToDest(vertex, neighbor);
|
|
224
225
|
}
|
|
225
226
|
this._outEdgeMap.delete(vertex);
|
|
226
227
|
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)
|