undirected-graph-typed 1.51.9 → 1.52.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/dist/data-structures/base/index.d.ts +2 -1
  2. package/dist/data-structures/base/index.js +2 -1
  3. package/dist/data-structures/base/iterable-element-base.d.ts +171 -0
  4. package/dist/data-structures/base/iterable-element-base.js +225 -0
  5. package/dist/data-structures/base/{iterable-base.d.ts → iterable-entry-base.d.ts} +4 -147
  6. package/dist/data-structures/base/{iterable-base.js → iterable-entry-base.js} +12 -189
  7. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +13 -13
  8. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +6 -6
  9. package/dist/data-structures/binary-tree/avl-tree.d.ts +13 -13
  10. package/dist/data-structures/binary-tree/avl-tree.js +6 -6
  11. package/dist/data-structures/binary-tree/binary-tree.d.ts +99 -99
  12. package/dist/data-structures/binary-tree/binary-tree.js +56 -54
  13. package/dist/data-structures/binary-tree/bst.d.ts +37 -45
  14. package/dist/data-structures/binary-tree/bst.js +19 -27
  15. package/dist/data-structures/binary-tree/rb-tree.d.ts +10 -10
  16. package/dist/data-structures/binary-tree/rb-tree.js +6 -6
  17. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +12 -12
  18. package/dist/data-structures/binary-tree/tree-multi-map.js +5 -5
  19. package/dist/data-structures/graph/directed-graph.js +2 -1
  20. package/dist/data-structures/hash/hash-map.d.ts +2 -2
  21. package/dist/data-structures/heap/heap.d.ts +43 -114
  22. package/dist/data-structures/heap/heap.js +59 -127
  23. package/dist/data-structures/heap/max-heap.d.ts +50 -4
  24. package/dist/data-structures/heap/max-heap.js +76 -10
  25. package/dist/data-structures/heap/min-heap.d.ts +51 -5
  26. package/dist/data-structures/heap/min-heap.js +68 -11
  27. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +22 -28
  28. package/dist/data-structures/linked-list/doubly-linked-list.js +26 -28
  29. package/dist/data-structures/linked-list/singly-linked-list.d.ts +22 -25
  30. package/dist/data-structures/linked-list/singly-linked-list.js +29 -26
  31. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +50 -4
  32. package/dist/data-structures/priority-queue/max-priority-queue.js +79 -10
  33. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +51 -5
  34. package/dist/data-structures/priority-queue/min-priority-queue.js +71 -11
  35. package/dist/data-structures/priority-queue/priority-queue.d.ts +50 -4
  36. package/dist/data-structures/priority-queue/priority-queue.js +70 -1
  37. package/dist/data-structures/queue/deque.d.ts +27 -18
  38. package/dist/data-structures/queue/deque.js +43 -21
  39. package/dist/data-structures/queue/queue.d.ts +26 -29
  40. package/dist/data-structures/queue/queue.js +47 -38
  41. package/dist/data-structures/stack/stack.d.ts +17 -22
  42. package/dist/data-structures/stack/stack.js +25 -24
  43. package/dist/data-structures/trie/trie.d.ts +18 -13
  44. package/dist/data-structures/trie/trie.js +26 -15
  45. package/dist/interfaces/binary-tree.d.ts +4 -4
  46. package/dist/types/common.d.ts +1 -22
  47. package/dist/types/data-structures/base/base.d.ts +5 -2
  48. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -3
  49. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +2 -3
  50. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +20 -4
  51. package/dist/types/data-structures/binary-tree/bst.d.ts +5 -3
  52. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +2 -3
  53. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -3
  54. package/dist/types/data-structures/heap/heap.d.ts +3 -2
  55. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
  56. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +2 -1
  57. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  58. package/dist/types/data-structures/queue/deque.d.ts +4 -2
  59. package/dist/types/data-structures/queue/queue.d.ts +4 -1
  60. package/dist/types/data-structures/stack/stack.d.ts +2 -1
  61. package/dist/types/data-structures/trie/trie.d.ts +3 -2
  62. package/package.json +2 -2
  63. package/src/data-structures/base/index.ts +2 -1
  64. package/src/data-structures/base/iterable-element-base.ts +250 -0
  65. package/src/data-structures/base/{iterable-base.ts → iterable-entry-base.ts} +26 -217
  66. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +26 -26
  67. package/src/data-structures/binary-tree/avl-tree.ts +21 -21
  68. package/src/data-structures/binary-tree/binary-tree.ts +166 -161
  69. package/src/data-structures/binary-tree/bst.ts +61 -68
  70. package/src/data-structures/binary-tree/rb-tree.ts +19 -19
  71. package/src/data-structures/binary-tree/tree-multi-map.ts +19 -19
  72. package/src/data-structures/graph/abstract-graph.ts +15 -14
  73. package/src/data-structures/graph/directed-graph.ts +9 -7
  74. package/src/data-structures/graph/undirected-graph.ts +7 -6
  75. package/src/data-structures/hash/hash-map.ts +8 -8
  76. package/src/data-structures/heap/heap.ts +72 -153
  77. package/src/data-structures/heap/max-heap.ts +88 -13
  78. package/src/data-structures/heap/min-heap.ts +78 -15
  79. package/src/data-structures/linked-list/doubly-linked-list.ts +33 -33
  80. package/src/data-structures/linked-list/singly-linked-list.ts +38 -30
  81. package/src/data-structures/priority-queue/max-priority-queue.ts +94 -13
  82. package/src/data-structures/priority-queue/min-priority-queue.ts +84 -15
  83. package/src/data-structures/priority-queue/priority-queue.ts +81 -4
  84. package/src/data-structures/queue/deque.ts +53 -28
  85. package/src/data-structures/queue/queue.ts +61 -44
  86. package/src/data-structures/stack/stack.ts +32 -27
  87. package/src/data-structures/trie/trie.ts +34 -19
  88. package/src/interfaces/binary-tree.ts +4 -5
  89. package/src/types/common.ts +2 -24
  90. package/src/types/data-structures/base/base.ts +14 -6
  91. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +2 -3
  92. package/src/types/data-structures/binary-tree/avl-tree.ts +2 -3
  93. package/src/types/data-structures/binary-tree/binary-tree.ts +24 -5
  94. package/src/types/data-structures/binary-tree/bst.ts +9 -3
  95. package/src/types/data-structures/binary-tree/rb-tree.ts +2 -3
  96. package/src/types/data-structures/binary-tree/tree-multi-map.ts +2 -3
  97. package/src/types/data-structures/graph/abstract-graph.ts +8 -8
  98. package/src/types/data-structures/heap/heap.ts +4 -1
  99. package/src/types/data-structures/linked-list/doubly-linked-list.ts +3 -1
  100. package/src/types/data-structures/linked-list/singly-linked-list.ts +3 -1
  101. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -1
  102. package/src/types/data-structures/queue/deque.ts +6 -1
  103. package/src/types/data-structures/queue/queue.ts +5 -1
  104. package/src/types/data-structures/stack/stack.ts +3 -1
  105. package/src/types/data-structures/trie/trie.ts +3 -1
  106. package/src/types/utils/utils.ts +4 -4
@@ -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 | undefined} v - The parameter `v` is of type `NODE | undefined`. It can either be an
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 | undefined} v - The parameter `v` is of type `NODE | undefined`. It can either be a
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' && typeof b === 'object' && this.comparator === this._DEFAULT_COMPARATOR) {
79
- throw TypeError('When comparing two object types, it is necessary to customize a [comparator] function of options parameter during the instantiation of the data structure.');
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 | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - A variable that can be of
131
- * type R or KeyOrNodeOrEntry<K, V, NODE>. It represents either a key, a node, an entry, or a raw
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 | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
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 | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
163
- * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
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 | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
176
- * `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
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 | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
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 | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
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 | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
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 | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
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 | KeyOrNodeOrEntry<K, V, NODE>} targetNode - The `targetNode` parameter is the node in
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,
@@ -691,8 +683,8 @@ class BST extends binary_tree_1.BinaryTree {
691
683
  if (!node.right || last === node.right) {
692
684
  node = stack.pop();
693
685
  if (node) {
694
- const left = node.left ? (_a = depths.get(node.left)) !== null && _a !== void 0 ? _a : -1 : -1;
695
- const right = node.right ? (_b = depths.get(node.right)) !== null && _b !== void 0 ? _b : -1 : -1;
686
+ const left = node.left ? ((_a = depths.get(node.left)) !== null && _a !== void 0 ? _a : -1) : -1;
687
+ const right = node.right ? ((_b = depths.get(node.right)) !== null && _b !== void 0 ? _b : -1) : -1;
696
688
  if (Math.abs(left - right) > 1)
697
689
  return false;
698
690
  depths.set(node, 1 + Math.max(left, right));
@@ -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 | undefined} v - v is a parameter of type NODE or undefined.
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, Comparable, CRUD, KeyOrNodeOrEntry, RBTNColor, RBTreeOptions, RedBlackTreeNested, RedBlackTreeNodeNested } from '../../types';
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 extends Comparable, V = any, NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNodeNested<K, V>> extends BSTNode<K, V, NODE> {
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 extends Comparable, 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> {
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 | KeyOrNodeOrEntry<K, V, NODE>>, options?: RBTreeOptions<K, V, 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 | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
80
- * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
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 | KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntryOrRawElement is NODE;
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 | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
108
- * `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
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 | KeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean;
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 | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
98
- * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
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 {KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The key, value, or entry to convert.
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 | KeyOrNodeOrEntry<K, V, NODE>, value?: V): NODE | undefined {
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 | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
166
- * `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
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, Comparable, IterationType, KeyOrNodeOrEntry, RBTNColor, TreeMultiMapNested, TreeMultiMapNodeNested, TreeMultiMapOptions } from '../../types';
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 extends Comparable, V = any, NODE extends TreeMultiMapNode<K, V, NODE> = TreeMultiMapNodeNested<K, V>> extends RedBlackTreeNode<K, V, NODE> {
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 extends Comparable, 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> {
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<KeyOrNodeOrEntry<K, V, NODE>>, options?: TreeMultiMapOptions<K, V, R>);
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 | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
96
- * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
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 | KeyOrNodeOrEntry<K, V, NODE>, value?: V, count?: number): NODE | undefined;
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 | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
108
- * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
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 | KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntryOrRawElement is NODE;
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 | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
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 | KeyOrNodeOrEntry<K, V, NODE>, value?: V, count?: number): boolean;
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 | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
112
- * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
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 | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
144
- * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
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 | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
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<U>(callbackfn: EntryCallback<K, V, U>, thisArg?: any): HashMap<K, U>;
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<NV>(callback: EntryCallback<K, V, NV>, thisArg?: any): LinkedHashMap<K, NV>;
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)