linked-list-typed 1.48.3 → 1.48.5

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 (38) hide show
  1. package/dist/data-structures/base/iterable-base.d.ts +6 -6
  2. package/dist/data-structures/base/iterable-base.js +3 -3
  3. package/dist/data-structures/binary-tree/avl-tree.d.ts +5 -3
  4. package/dist/data-structures/binary-tree/avl-tree.js +6 -4
  5. package/dist/data-structures/binary-tree/binary-tree.d.ts +18 -15
  6. package/dist/data-structures/binary-tree/binary-tree.js +16 -13
  7. package/dist/data-structures/binary-tree/bst.d.ts +15 -11
  8. package/dist/data-structures/binary-tree/bst.js +17 -13
  9. package/dist/data-structures/binary-tree/rb-tree.d.ts +19 -13
  10. package/dist/data-structures/binary-tree/rb-tree.js +20 -14
  11. package/dist/data-structures/binary-tree/tree-multimap.d.ts +21 -14
  12. package/dist/data-structures/binary-tree/tree-multimap.js +25 -18
  13. package/dist/data-structures/graph/abstract-graph.d.ts +53 -52
  14. package/dist/data-structures/graph/abstract-graph.js +82 -78
  15. package/dist/data-structures/graph/directed-graph.d.ts +70 -52
  16. package/dist/data-structures/graph/directed-graph.js +111 -65
  17. package/dist/data-structures/graph/map-graph.d.ts +5 -5
  18. package/dist/data-structures/graph/map-graph.js +8 -8
  19. package/dist/data-structures/graph/undirected-graph.d.ts +51 -32
  20. package/dist/data-structures/graph/undirected-graph.js +117 -54
  21. package/dist/data-structures/hash/hash-map.d.ts +8 -8
  22. package/dist/data-structures/hash/hash-map.js +2 -2
  23. package/dist/interfaces/binary-tree.d.ts +1 -1
  24. package/dist/types/data-structures/base/base.d.ts +3 -3
  25. package/package.json +2 -2
  26. package/src/data-structures/base/iterable-base.ts +6 -6
  27. package/src/data-structures/binary-tree/avl-tree.ts +8 -5
  28. package/src/data-structures/binary-tree/binary-tree.ts +23 -19
  29. package/src/data-structures/binary-tree/bst.ts +19 -14
  30. package/src/data-structures/binary-tree/rb-tree.ts +20 -14
  31. package/src/data-structures/binary-tree/tree-multimap.ts +27 -19
  32. package/src/data-structures/graph/abstract-graph.ts +87 -82
  33. package/src/data-structures/graph/directed-graph.ts +114 -65
  34. package/src/data-structures/graph/map-graph.ts +8 -8
  35. package/src/data-structures/graph/undirected-graph.ts +124 -56
  36. package/src/data-structures/hash/hash-map.ts +8 -8
  37. package/src/interfaces/binary-tree.ts +1 -1
  38. package/src/types/data-structures/base/base.ts +3 -3
@@ -1,5 +1,5 @@
1
- import { ElementCallback, PairCallback, ReduceElementCallback, ReducePairCallback } from "../../types";
2
- export declare abstract class IterablePairBase<K = any, V = any> {
1
+ import { ElementCallback, EntryCallback, ReduceElementCallback, ReduceEntryCallback } from "../../types";
2
+ export declare abstract class IterableEntryBase<K = any, V = any> {
3
3
  /**
4
4
  * Time Complexity: O(n)
5
5
  * Space Complexity: O(1)
@@ -66,7 +66,7 @@ export declare abstract class IterablePairBase<K = any, V = any> {
66
66
  * @returns The `every` method is returning a boolean value. It returns `true` if every element in
67
67
  * the collection satisfies the provided predicate function, and `false` otherwise.
68
68
  */
69
- every(predicate: PairCallback<K, V, boolean>, thisArg?: any): boolean;
69
+ every(predicate: EntryCallback<K, V, boolean>, thisArg?: any): boolean;
70
70
  /**
71
71
  * Time Complexity: O(n)
72
72
  * Space Complexity: O(1)
@@ -86,7 +86,7 @@ export declare abstract class IterablePairBase<K = any, V = any> {
86
86
  * @returns a boolean value. It returns true if the predicate function returns true for any pair in
87
87
  * the collection, and false otherwise.
88
88
  */
89
- some(predicate: PairCallback<K, V, boolean>, thisArg?: any): boolean;
89
+ some(predicate: EntryCallback<K, V, boolean>, thisArg?: any): boolean;
90
90
  /**
91
91
  * Time Complexity: O(n)
92
92
  * Space Complexity: O(1)
@@ -104,7 +104,7 @@ export declare abstract class IterablePairBase<K = any, V = any> {
104
104
  * specify the value of `this` within the callback function. If `thisArg` is provided, it will be
105
105
  * used as the `this` value when calling the callback function. If `thisArg` is not provided, `
106
106
  */
107
- forEach(callbackfn: PairCallback<K, V, void>, thisArg?: any): void;
107
+ forEach(callbackfn: EntryCallback<K, V, void>, thisArg?: any): void;
108
108
  /**
109
109
  * Time Complexity: O(n)
110
110
  * Space Complexity: O(1)
@@ -125,7 +125,7 @@ export declare abstract class IterablePairBase<K = any, V = any> {
125
125
  * @returns The `reduce` method is returning the final value of the accumulator after iterating over
126
126
  * all the elements in the collection.
127
127
  */
128
- reduce<U>(callbackfn: ReducePairCallback<K, V, U>, initialValue: U): U;
128
+ reduce<U>(callbackfn: ReduceEntryCallback<K, V, U>, initialValue: U): U;
129
129
  protected abstract _getIterator(...args: any[]): IterableIterator<[K, V]>;
130
130
  }
131
131
  export declare abstract class IterableElementBase<V> {
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IterableElementBase = exports.IterablePairBase = void 0;
4
- class IterablePairBase {
3
+ exports.IterableElementBase = exports.IterableEntryBase = void 0;
4
+ class IterableEntryBase {
5
5
  /**
6
6
  * Time Complexity: O(n)
7
7
  * Space Complexity: O(1)
@@ -173,7 +173,7 @@ class IterablePairBase {
173
173
  return accumulator;
174
174
  }
175
175
  }
176
- exports.IterablePairBase = IterablePairBase;
176
+ exports.IterableEntryBase = IterableEntryBase;
177
177
  class IterableElementBase {
178
178
  /**
179
179
  * Time Complexity: O(n)
@@ -68,11 +68,13 @@ export declare class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> =
68
68
  *
69
69
  * The function overrides the add method of a binary tree node and balances the tree after inserting
70
70
  * a new node.
71
- * @param keyOrNodeOrEntry - The parameter `keyOrNodeOrEntry` can be either a key, a node, or an
71
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be either a key, a node, or an
72
72
  * entry.
73
- * @returns The method is returning either the inserted node or `undefined`.
73
+ * @param {V} [value] - The `value` parameter represents the value associated with the key that is
74
+ * being added to the binary tree.
75
+ * @returns The method is returning either the inserted node or undefined.
74
76
  */
75
- add(keyOrNodeOrEntry: BTNodeExemplar<K, V, N>): N | undefined;
77
+ add(keyOrNodeOrEntry: BTNodeExemplar<K, V, N>, value?: V): N | undefined;
76
78
  /**
77
79
  * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
78
80
  * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
@@ -81,14 +81,16 @@ class AVLTree extends bst_1.BST {
81
81
  *
82
82
  * The function overrides the add method of a binary tree node and balances the tree after inserting
83
83
  * a new node.
84
- * @param keyOrNodeOrEntry - The parameter `keyOrNodeOrEntry` can be either a key, a node, or an
84
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be either a key, a node, or an
85
85
  * entry.
86
- * @returns The method is returning either the inserted node or `undefined`.
86
+ * @param {V} [value] - The `value` parameter represents the value associated with the key that is
87
+ * being added to the binary tree.
88
+ * @returns The method is returning either the inserted node or undefined.
87
89
  */
88
- add(keyOrNodeOrEntry) {
90
+ add(keyOrNodeOrEntry, value) {
89
91
  if (keyOrNodeOrEntry === null)
90
92
  return undefined;
91
- const inserted = super.add(keyOrNodeOrEntry);
93
+ const inserted = super.add(keyOrNodeOrEntry, value);
92
94
  if (inserted)
93
95
  this._balancePath(inserted);
94
96
  return inserted;
@@ -6,9 +6,9 @@
6
6
  * @license MIT License
7
7
  */
8
8
  import type { BinaryTreeNodeNested, BinaryTreeOptions, BTNCallback, BTNodeEntry, BTNodeExemplar, BTNodeKeyOrNode } from '../../types';
9
- import { BinaryTreeNested, BinaryTreePrintOptions, BiTreeDeleteResult, DFSOrderPattern, FamilyPosition, IterationType, NodeDisplayLayout, PairCallback } from '../../types';
9
+ import { BinaryTreeNested, BinaryTreePrintOptions, BiTreeDeleteResult, DFSOrderPattern, EntryCallback, FamilyPosition, IterationType, NodeDisplayLayout } from '../../types';
10
10
  import { IBinaryTree } from '../../interfaces';
11
- import { IterablePairBase } from "../base";
11
+ import { IterableEntryBase } from "../base";
12
12
  /**
13
13
  * Represents a node in a binary tree.
14
14
  * @template V - The type of data stored in the node.
@@ -42,7 +42,7 @@ export declare class BinaryTreeNode<K = any, V = any, N extends BinaryTreeNode<K
42
42
  * 8. Full Trees: Every node has either 0 or 2 children.
43
43
  * 9. Complete Trees: All levels are fully filled except possibly the last, filled from left to right.
44
44
  */
45
- export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V, N> = BinaryTreeNode<K, V, BinaryTreeNodeNested<K, V>>, TREE extends BinaryTree<K, V, N, TREE> = BinaryTree<K, V, N, BinaryTreeNested<K, V, N>>> extends IterablePairBase<K, V | undefined> implements IBinaryTree<K, V, N, TREE> {
45
+ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V, N> = BinaryTreeNode<K, V, BinaryTreeNodeNested<K, V>>, TREE extends BinaryTree<K, V, N, TREE> = BinaryTree<K, V, N, BinaryTreeNested<K, V, N>>> extends IterableEntryBase<K, V | undefined> implements IBinaryTree<K, V, N, TREE> {
46
46
  iterationType: IterationType;
47
47
  /**
48
48
  * The constructor function initializes a binary tree object with optional elements and options.
@@ -82,13 +82,14 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
82
82
  */
83
83
  isNode(exemplar: BTNodeExemplar<K, V, N>): exemplar is N;
84
84
  /**
85
- * The function `exemplarToNode` converts an exemplar of a binary tree node into an actual node
86
- * object.
87
- * @param exemplar - BTNodeExemplar<K, V,N> - A generic type representing the exemplar parameter of the
88
- * function. It can be any type.
89
- * @returns a value of type `N` (which represents a node), or `null`, or `undefined`.
85
+ * The function `exemplarToNode` converts an exemplar object into a node object.
86
+ * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`.
87
+ * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
88
+ * `exemplarToNode` function. It represents the value associated with the exemplar node. If no value
89
+ * is provided, it will be `undefined`.
90
+ * @returns a value of type N (node), or null, or undefined.
90
91
  */
91
- exemplarToNode(exemplar: BTNodeExemplar<K, V, N>): N | null | undefined;
92
+ exemplarToNode(exemplar: BTNodeExemplar<K, V, N>, value?: V): N | null | undefined;
92
93
  /**
93
94
  * The function checks if a given value is an entry in a binary tree node.
94
95
  * @param kne - BTNodeExemplar<K, V,N> - A generic type representing a node in a binary tree. It has
@@ -104,11 +105,13 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
104
105
  * Time Complexity O(log n) - O(n)
105
106
  * Space Complexity O(1)
106
107
  *
107
- * The `add` function adds a new node to a binary tree, either by key or by providing a node object.
108
- * @param keyOrNodeOrEntry - The parameter `keyOrNodeOrEntry` can be one of the following:
109
- * @returns The function `add` returns the inserted node (`N`), `null`, or `undefined`.
108
+ * The `add` function adds a new node to a binary tree, either by creating a new node or replacing an
109
+ * existing node with the same key.
110
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be one of the following:
111
+ * @param {V} [value] - The value to be inserted into the binary tree.
112
+ * @returns The function `add` returns either a node (`N`), `null`, or `undefined`.
110
113
  */
111
- add(keyOrNodeOrEntry: BTNodeExemplar<K, V, N>): N | null | undefined;
114
+ add(keyOrNodeOrEntry: BTNodeExemplar<K, V, N>, value?: V): N | null | undefined;
112
115
  /**
113
116
  * Time Complexity: O(k log n) - O(k * n)
114
117
  * Space Complexity: O(1)
@@ -495,7 +498,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
495
498
  * @returns The `filter` method is returning a new tree object that contains the key-value pairs that
496
499
  * pass the given predicate function.
497
500
  */
498
- filter(predicate: PairCallback<K, V | undefined, boolean>, thisArg?: any): TREE;
501
+ filter(predicate: EntryCallback<K, V | undefined, boolean>, thisArg?: any): TREE;
499
502
  /**
500
503
  * Time Complexity: O(n)
501
504
  * Space Complexity: O(n)
@@ -515,7 +518,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
515
518
  * will be used as the `this` value when the callback function is called. If you don't pass a value
516
519
  * @returns The `map` method is returning a new tree object.
517
520
  */
518
- map(callback: PairCallback<K, V | undefined, V>, thisArg?: any): TREE;
521
+ map(callback: EntryCallback<K, V | undefined, V>, thisArg?: any): TREE;
519
522
  /**
520
523
  * The `print` function is used to display a binary tree structure in a visually appealing way.
521
524
  * @param {K | N | null | undefined} [beginRoot=this.root] - The `root` parameter is of type `K | N | null |
@@ -70,7 +70,7 @@ exports.BinaryTreeNode = BinaryTreeNode;
70
70
  * 8. Full Trees: Every node has either 0 or 2 children.
71
71
  * 9. Complete Trees: All levels are fully filled except possibly the last, filled from left to right.
72
72
  */
73
- class BinaryTree extends base_1.IterablePairBase {
73
+ class BinaryTree extends base_1.IterableEntryBase {
74
74
  /**
75
75
  * The constructor function initializes a binary tree object with optional elements and options.
76
76
  * @param [elements] - An optional iterable of BTNodeExemplar objects. These objects represent the
@@ -135,13 +135,14 @@ class BinaryTree extends base_1.IterablePairBase {
135
135
  return exemplar instanceof BinaryTreeNode;
136
136
  }
137
137
  /**
138
- * The function `exemplarToNode` converts an exemplar of a binary tree node into an actual node
139
- * object.
140
- * @param exemplar - BTNodeExemplar<K, V,N> - A generic type representing the exemplar parameter of the
141
- * function. It can be any type.
142
- * @returns a value of type `N` (which represents a node), or `null`, or `undefined`.
138
+ * The function `exemplarToNode` converts an exemplar object into a node object.
139
+ * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`.
140
+ * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
141
+ * `exemplarToNode` function. It represents the value associated with the exemplar node. If no value
142
+ * is provided, it will be `undefined`.
143
+ * @returns a value of type N (node), or null, or undefined.
143
144
  */
144
- exemplarToNode(exemplar) {
145
+ exemplarToNode(exemplar, value) {
145
146
  if (exemplar === undefined)
146
147
  return;
147
148
  let node;
@@ -164,7 +165,7 @@ class BinaryTree extends base_1.IterablePairBase {
164
165
  node = exemplar;
165
166
  }
166
167
  else if (this.isNotNodeInstance(exemplar)) {
167
- node = this.createNode(exemplar);
168
+ node = this.createNode(exemplar, value);
168
169
  }
169
170
  else {
170
171
  return;
@@ -188,13 +189,15 @@ class BinaryTree extends base_1.IterablePairBase {
188
189
  * Time Complexity O(log n) - O(n)
189
190
  * Space Complexity O(1)
190
191
  *
191
- * The `add` function adds a new node to a binary tree, either by key or by providing a node object.
192
- * @param keyOrNodeOrEntry - The parameter `keyOrNodeOrEntry` can be one of the following:
193
- * @returns The function `add` returns the inserted node (`N`), `null`, or `undefined`.
192
+ * The `add` function adds a new node to a binary tree, either by creating a new node or replacing an
193
+ * existing node with the same key.
194
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be one of the following:
195
+ * @param {V} [value] - The value to be inserted into the binary tree.
196
+ * @returns The function `add` returns either a node (`N`), `null`, or `undefined`.
194
197
  */
195
- add(keyOrNodeOrEntry) {
198
+ add(keyOrNodeOrEntry, value) {
196
199
  let inserted;
197
- const newNode = this.exemplarToNode(keyOrNodeOrEntry);
200
+ const newNode = this.exemplarToNode(keyOrNodeOrEntry, value);
198
201
  if (newNode === undefined)
199
202
  return;
200
203
  const _bfs = (root, newNode) => {
@@ -80,12 +80,14 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
80
80
  */
81
81
  isNode(exemplar: BTNodeExemplar<K, V, N>): exemplar is N;
82
82
  /**
83
- * The function `exemplarToNode` takes an exemplar and returns a corresponding node if the exemplar
84
- * is valid, otherwise it returns undefined.
85
- * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`.
86
- * @returns a variable `node` which is of type `N` or `undefined`.
83
+ * The function `exemplarToNode` takes an exemplar and returns a node if the exemplar is valid,
84
+ * otherwise it returns undefined.
85
+ * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`, where:
86
+ * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
87
+ * `exemplarToNode` function. It represents the value associated with the exemplar node.
88
+ * @returns a node of type N or undefined.
87
89
  */
88
- exemplarToNode(exemplar: BTNodeExemplar<K, V, N>): N | undefined;
90
+ exemplarToNode(exemplar: BTNodeExemplar<K, V, N>, value?: V): N | undefined;
89
91
  /**
90
92
  * Time Complexity: O(log n) - Average case for a balanced tree. In the worst case (unbalanced tree), it can be O(n).
91
93
  * Space Complexity: O(1) - Constant space is used.
@@ -94,13 +96,15 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
94
96
  * Time Complexity: O(log n) - Average case for a balanced tree. In the worst case (unbalanced tree), it can be O(n).
95
97
  * Space Complexity: O(1) - Constant space is used.
96
98
  *
97
- * The `add` function adds a new node to a binary search tree, either by key or by providing a node
98
- * object.
99
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be one of the following:
100
- * @returns The method returns either the newly added node (`newNode`) or `undefined` if the input
101
- * (`keyOrNodeOrEntry`) is null, undefined, or does not match any of the expected types.
99
+ * The `add` function adds a new node to a binary tree, updating the value if the key already exists
100
+ * or inserting a new node if the key is unique.
101
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can accept three types of values:
102
+ * @param {V} [value] - The `value` parameter represents the value associated with the key that is
103
+ * being added to the binary tree.
104
+ * @returns The method `add` returns either the newly added node (`newNode`) or `undefined` if the
105
+ * node was not added.
102
106
  */
103
- add(keyOrNodeOrEntry: BTNodeExemplar<K, V, N>): N | undefined;
107
+ add(keyOrNodeOrEntry: BTNodeExemplar<K, V, N>, value?: V): N | undefined;
104
108
  /**
105
109
  * Time Complexity: O(k log n) - Adding each element individually in a balanced tree.
106
110
  * Space Complexity: O(k) - Additional space is required for the sorted array.
@@ -112,12 +112,14 @@ class BST extends binary_tree_1.BinaryTree {
112
112
  return exemplar instanceof BSTNode;
113
113
  }
114
114
  /**
115
- * The function `exemplarToNode` takes an exemplar and returns a corresponding node if the exemplar
116
- * is valid, otherwise it returns undefined.
117
- * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`.
118
- * @returns a variable `node` which is of type `N` or `undefined`.
115
+ * The function `exemplarToNode` takes an exemplar and returns a node if the exemplar is valid,
116
+ * otherwise it returns undefined.
117
+ * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`, where:
118
+ * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
119
+ * `exemplarToNode` function. It represents the value associated with the exemplar node.
120
+ * @returns a node of type N or undefined.
119
121
  */
120
- exemplarToNode(exemplar) {
122
+ exemplarToNode(exemplar, value) {
121
123
  let node;
122
124
  if (exemplar === null || exemplar === undefined) {
123
125
  return;
@@ -135,7 +137,7 @@ class BST extends binary_tree_1.BinaryTree {
135
137
  }
136
138
  }
137
139
  else if (this.isNotNodeInstance(exemplar)) {
138
- node = this.createNode(exemplar);
140
+ node = this.createNode(exemplar, value);
139
141
  }
140
142
  else {
141
143
  return;
@@ -150,14 +152,16 @@ class BST extends binary_tree_1.BinaryTree {
150
152
  * Time Complexity: O(log n) - Average case for a balanced tree. In the worst case (unbalanced tree), it can be O(n).
151
153
  * Space Complexity: O(1) - Constant space is used.
152
154
  *
153
- * The `add` function adds a new node to a binary search tree, either by key or by providing a node
154
- * object.
155
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be one of the following:
156
- * @returns The method returns either the newly added node (`newNode`) or `undefined` if the input
157
- * (`keyOrNodeOrEntry`) is null, undefined, or does not match any of the expected types.
155
+ * The `add` function adds a new node to a binary tree, updating the value if the key already exists
156
+ * or inserting a new node if the key is unique.
157
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can accept three types of values:
158
+ * @param {V} [value] - The `value` parameter represents the value associated with the key that is
159
+ * being added to the binary tree.
160
+ * @returns The method `add` returns either the newly added node (`newNode`) or `undefined` if the
161
+ * node was not added.
158
162
  */
159
- add(keyOrNodeOrEntry) {
160
- const newNode = this.exemplarToNode(keyOrNodeOrEntry);
163
+ add(keyOrNodeOrEntry, value) {
164
+ const newNode = this.exemplarToNode(keyOrNodeOrEntry, value);
161
165
  if (newNode === undefined)
162
166
  return;
163
167
  if (this.root === undefined) {
@@ -66,25 +66,31 @@ export declare class RedBlackTree<K = any, V = any, N extends RedBlackTreeNode<K
66
66
  */
67
67
  isNode(exemplar: BTNodeExemplar<K, V, N>): exemplar is N;
68
68
  /**
69
- * The function `exemplarToNode` takes an exemplar and returns a node if the exemplar is valid,
70
- * otherwise it returns undefined.
71
- * @param exemplar - BTNodeExemplar<K, V, N> - A generic type representing an exemplar of a binary tree
72
- * node. It can be either a node itself, an entry (key-value pair), a node key, or any other value
73
- * that is not a valid exemplar.
74
- * @returns a variable `node` which is of type `N | undefined`.
69
+ * The function `exemplarToNode` takes an exemplar and converts it into a node object if possible.
70
+ * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`, where:
71
+ * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
72
+ * `exemplarToNode` function. It represents the value associated with the exemplar node. If a value
73
+ * is provided, it will be used when creating the new node. If no value is provided, the new node
74
+ * @returns a node of type N or undefined.
75
75
  */
76
- exemplarToNode(exemplar: BTNodeExemplar<K, V, N>): N | undefined;
76
+ exemplarToNode(exemplar: BTNodeExemplar<K, V, N>, value?: V): N | undefined;
77
77
  /**
78
78
  * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
79
79
  * Space Complexity: O(1)
80
80
  */
81
81
  /**
82
- * The function adds a node to a Red-Black Tree data structure.
83
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be one of the following:
84
- * @returns The method `add` returns either an instance of `N` (the node that was added) or
85
- * `undefined`.
86
- */
87
- add(keyOrNodeOrEntry: BTNodeExemplar<K, V, N>): N | undefined;
82
+ * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
83
+ * Space Complexity: O(1)
84
+ *
85
+ * The `add` function adds a new node to a binary search tree and performs necessary rotations and
86
+ * color changes to maintain the red-black tree properties.
87
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be either a key, a node, or an
88
+ * entry.
89
+ * @param {V} [value] - The `value` parameter represents the value associated with the key that is
90
+ * being added to the binary search tree.
91
+ * @returns The method `add` returns either the newly added node (`N`) or `undefined`.
92
+ */
93
+ add(keyOrNodeOrEntry: BTNodeExemplar<K, V, N>, value?: V): N | undefined;
88
94
  /**
89
95
  * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
90
96
  * Space Complexity: O(1)
@@ -86,14 +86,14 @@ class RedBlackTree extends bst_1.BST {
86
86
  return exemplar instanceof RedBlackTreeNode;
87
87
  }
88
88
  /**
89
- * The function `exemplarToNode` takes an exemplar and returns a node if the exemplar is valid,
90
- * otherwise it returns undefined.
91
- * @param exemplar - BTNodeExemplar<K, V, N> - A generic type representing an exemplar of a binary tree
92
- * node. It can be either a node itself, an entry (key-value pair), a node key, or any other value
93
- * that is not a valid exemplar.
94
- * @returns a variable `node` which is of type `N | undefined`.
89
+ * The function `exemplarToNode` takes an exemplar and converts it into a node object if possible.
90
+ * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`, where:
91
+ * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
92
+ * `exemplarToNode` function. It represents the value associated with the exemplar node. If a value
93
+ * is provided, it will be used when creating the new node. If no value is provided, the new node
94
+ * @returns a node of type N or undefined.
95
95
  */
96
- exemplarToNode(exemplar) {
96
+ exemplarToNode(exemplar, value) {
97
97
  let node;
98
98
  if (exemplar === null || exemplar === undefined) {
99
99
  return;
@@ -111,7 +111,7 @@ class RedBlackTree extends bst_1.BST {
111
111
  }
112
112
  }
113
113
  else if (this.isNotNodeInstance(exemplar)) {
114
- node = this.createNode(exemplar, undefined, types_1.RBTNColor.RED);
114
+ node = this.createNode(exemplar, value, types_1.RBTNColor.RED);
115
115
  }
116
116
  else {
117
117
  return;
@@ -123,13 +123,19 @@ class RedBlackTree extends bst_1.BST {
123
123
  * Space Complexity: O(1)
124
124
  */
125
125
  /**
126
- * The function adds a node to a Red-Black Tree data structure.
127
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be one of the following:
128
- * @returns The method `add` returns either an instance of `N` (the node that was added) or
129
- * `undefined`.
126
+ * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
127
+ * Space Complexity: O(1)
128
+ *
129
+ * The `add` function adds a new node to a binary search tree and performs necessary rotations and
130
+ * color changes to maintain the red-black tree properties.
131
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be either a key, a node, or an
132
+ * entry.
133
+ * @param {V} [value] - The `value` parameter represents the value associated with the key that is
134
+ * being added to the binary search tree.
135
+ * @returns The method `add` returns either the newly added node (`N`) or `undefined`.
130
136
  */
131
- add(keyOrNodeOrEntry) {
132
- const newNode = this.exemplarToNode(keyOrNodeOrEntry);
137
+ add(keyOrNodeOrEntry, value) {
138
+ const newNode = this.exemplarToNode(keyOrNodeOrEntry, value);
133
139
  if (newNode === undefined)
134
140
  return;
135
141
  newNode.left = this.Sentinel;
@@ -50,13 +50,16 @@ export declare class TreeMultimap<K = any, V = any, N extends TreeMultimapNode<K
50
50
  isNode(exemplar: BTNodeExemplar<K, V, N>): exemplar is N;
51
51
  /**
52
52
  * The function `exemplarToNode` converts an exemplar object into a node object.
53
- * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`, where `V` represents
54
- * the value type and `N` represents the node type.
53
+ * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`, which means it
54
+ * can be one of the following:
55
+ * @param {V} [value] - The `value` parameter is an optional argument that represents the value
56
+ * associated with the node. It is of type `V`, which can be any data type. If no value is provided,
57
+ * it defaults to `undefined`.
55
58
  * @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
56
- * times the node should be created. If not provided, it defaults to 1.
57
- * @returns a value of type `N` (the generic type parameter) or `undefined`.
59
+ * times the value should be added to the node. If not provided, it defaults to 1.
60
+ * @returns a node of type `N` or `undefined`.
58
61
  */
59
- exemplarToNode(exemplar: BTNodeExemplar<K, V, N>, count?: number): N | undefined;
62
+ exemplarToNode(exemplar: BTNodeExemplar<K, V, N>, value?: V, count?: number): N | undefined;
60
63
  /**
61
64
  * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (AVLTree) has logarithmic time complexity.
62
65
  * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
@@ -65,15 +68,19 @@ export declare class TreeMultimap<K = any, V = any, N extends TreeMultimapNode<K
65
68
  * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (AVLTree) has logarithmic time complexity.
66
69
  * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
67
70
  *
68
- * The `add` function overrides the base class `add` function to add a new node to the tree multimap
69
- * and update the count.
70
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be one of the following:
71
- * @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
72
- * times the key or node or entry should be added to the multimap. If not provided, the default value
73
- * is 1.
74
- * @returns either a node (`N`) or `undefined`.
75
- */
76
- add(keyOrNodeOrEntry: BTNodeExemplar<K, V, N>, count?: number): N | undefined;
71
+ * The function overrides the add method of a binary tree node and adds a new node to the tree.
72
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be either a key, a node, or an
73
+ * entry. It represents the key, node, or entry that you want to add to the binary tree.
74
+ * @param {V} [value] - The `value` parameter represents the value associated with the key in the
75
+ * binary tree node. It is an optional parameter, meaning it can be omitted when calling the `add`
76
+ * method.
77
+ * @param [count=1] - The `count` parameter represents the number of times the key-value pair should
78
+ * be added to the binary tree. By default, it is set to 1, meaning that the key-value pair will be
79
+ * added once. However, you can specify a different value for `count` if you want to add
80
+ * @returns The method is returning either the newly inserted node or `undefined` if the insertion
81
+ * was not successful.
82
+ */
83
+ add(keyOrNodeOrEntry: BTNodeExemplar<K, V, N>, value?: V, count?: number): N | undefined;
77
84
  /**
78
85
  * Time Complexity: O(k log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (AVLTree) has logarithmic time complexity.
79
86
  * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
@@ -62,13 +62,16 @@ class TreeMultimap extends avl_tree_1.AVLTree {
62
62
  }
63
63
  /**
64
64
  * The function `exemplarToNode` converts an exemplar object into a node object.
65
- * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`, where `V` represents
66
- * the value type and `N` represents the node type.
65
+ * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`, which means it
66
+ * can be one of the following:
67
+ * @param {V} [value] - The `value` parameter is an optional argument that represents the value
68
+ * associated with the node. It is of type `V`, which can be any data type. If no value is provided,
69
+ * it defaults to `undefined`.
67
70
  * @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
68
- * times the node should be created. If not provided, it defaults to 1.
69
- * @returns a value of type `N` (the generic type parameter) or `undefined`.
71
+ * times the value should be added to the node. If not provided, it defaults to 1.
72
+ * @returns a node of type `N` or `undefined`.
70
73
  */
71
- exemplarToNode(exemplar, count = 1) {
74
+ exemplarToNode(exemplar, value, count = 1) {
72
75
  let node;
73
76
  if (exemplar === undefined || exemplar === null) {
74
77
  return;
@@ -86,7 +89,7 @@ class TreeMultimap extends avl_tree_1.AVLTree {
86
89
  }
87
90
  }
88
91
  else if (this.isNotNodeInstance(exemplar)) {
89
- node = this.createNode(exemplar, undefined, count);
92
+ node = this.createNode(exemplar, value, count);
90
93
  }
91
94
  else {
92
95
  return;
@@ -101,16 +104,20 @@ class TreeMultimap extends avl_tree_1.AVLTree {
101
104
  * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (AVLTree) has logarithmic time complexity.
102
105
  * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
103
106
  *
104
- * The `add` function overrides the base class `add` function to add a new node to the tree multimap
105
- * and update the count.
106
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be one of the following:
107
- * @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
108
- * times the key or node or entry should be added to the multimap. If not provided, the default value
109
- * is 1.
110
- * @returns either a node (`N`) or `undefined`.
107
+ * The function overrides the add method of a binary tree node and adds a new node to the tree.
108
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be either a key, a node, or an
109
+ * entry. It represents the key, node, or entry that you want to add to the binary tree.
110
+ * @param {V} [value] - The `value` parameter represents the value associated with the key in the
111
+ * binary tree node. It is an optional parameter, meaning it can be omitted when calling the `add`
112
+ * method.
113
+ * @param [count=1] - The `count` parameter represents the number of times the key-value pair should
114
+ * be added to the binary tree. By default, it is set to 1, meaning that the key-value pair will be
115
+ * added once. However, you can specify a different value for `count` if you want to add
116
+ * @returns The method is returning either the newly inserted node or `undefined` if the insertion
117
+ * was not successful.
111
118
  */
112
- add(keyOrNodeOrEntry, count = 1) {
113
- const newNode = this.exemplarToNode(keyOrNodeOrEntry, count);
119
+ add(keyOrNodeOrEntry, value, count = 1) {
120
+ const newNode = this.exemplarToNode(keyOrNodeOrEntry, value, count);
114
121
  if (newNode === undefined)
115
122
  return;
116
123
  const orgNodeCount = (newNode === null || newNode === void 0 ? void 0 : newNode.count) || 0;
@@ -163,7 +170,7 @@ class TreeMultimap extends avl_tree_1.AVLTree {
163
170
  return;
164
171
  const m = l + Math.floor((r - l) / 2);
165
172
  const midNode = sorted[m];
166
- this.add([midNode.key, midNode.value], midNode.count);
173
+ this.add(midNode.key, midNode.value, midNode.count);
167
174
  buildBalanceBST(l, m - 1);
168
175
  buildBalanceBST(m + 1, r);
169
176
  };
@@ -179,7 +186,7 @@ class TreeMultimap extends avl_tree_1.AVLTree {
179
186
  if (l <= r) {
180
187
  const m = l + Math.floor((r - l) / 2);
181
188
  const midNode = sorted[m];
182
- this.add([midNode.key, midNode.value], midNode.count);
189
+ this.add(midNode.key, midNode.value, midNode.count);
183
190
  stack.push([m + 1, r]);
184
191
  stack.push([l, m - 1]);
185
192
  }
@@ -293,7 +300,7 @@ class TreeMultimap extends avl_tree_1.AVLTree {
293
300
  */
294
301
  clone() {
295
302
  const cloned = this.createTree();
296
- this.bfs(node => cloned.add([node.key, node.value], node.count));
303
+ this.bfs(node => cloned.add(node.key, node.value, node.count));
297
304
  return cloned;
298
305
  }
299
306
  /**