undirected-graph-typed 1.51.8 → 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.
Files changed (108) 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 +106 -68
  8. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +119 -87
  9. package/dist/data-structures/binary-tree/avl-tree.d.ts +82 -62
  10. package/dist/data-structures/binary-tree/avl-tree.js +78 -59
  11. package/dist/data-structures/binary-tree/binary-tree.d.ts +333 -241
  12. package/dist/data-structures/binary-tree/binary-tree.js +478 -366
  13. package/dist/data-structures/binary-tree/bst.d.ts +202 -212
  14. package/dist/data-structures/binary-tree/bst.js +208 -250
  15. package/dist/data-structures/binary-tree/rb-tree.d.ts +73 -74
  16. package/dist/data-structures/binary-tree/rb-tree.js +107 -98
  17. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +92 -75
  18. package/dist/data-structures/binary-tree/tree-multi-map.js +105 -93
  19. package/dist/data-structures/graph/abstract-graph.d.ts +10 -15
  20. package/dist/data-structures/graph/abstract-graph.js +10 -15
  21. package/dist/data-structures/graph/directed-graph.js +2 -1
  22. package/dist/data-structures/hash/hash-map.d.ts +33 -40
  23. package/dist/data-structures/hash/hash-map.js +40 -55
  24. package/dist/data-structures/heap/heap.d.ts +43 -114
  25. package/dist/data-structures/heap/heap.js +59 -127
  26. package/dist/data-structures/heap/max-heap.d.ts +50 -4
  27. package/dist/data-structures/heap/max-heap.js +76 -10
  28. package/dist/data-structures/heap/min-heap.d.ts +51 -5
  29. package/dist/data-structures/heap/min-heap.js +68 -11
  30. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +22 -28
  31. package/dist/data-structures/linked-list/doubly-linked-list.js +26 -28
  32. package/dist/data-structures/linked-list/singly-linked-list.d.ts +22 -25
  33. package/dist/data-structures/linked-list/singly-linked-list.js +29 -26
  34. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +50 -4
  35. package/dist/data-structures/priority-queue/max-priority-queue.js +79 -10
  36. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +51 -5
  37. package/dist/data-structures/priority-queue/min-priority-queue.js +71 -11
  38. package/dist/data-structures/priority-queue/priority-queue.d.ts +50 -4
  39. package/dist/data-structures/priority-queue/priority-queue.js +70 -1
  40. package/dist/data-structures/queue/deque.d.ts +28 -20
  41. package/dist/data-structures/queue/deque.js +45 -24
  42. package/dist/data-structures/queue/queue.d.ts +8 -29
  43. package/dist/data-structures/queue/queue.js +15 -32
  44. package/dist/data-structures/stack/stack.d.ts +17 -22
  45. package/dist/data-structures/stack/stack.js +25 -24
  46. package/dist/data-structures/trie/trie.d.ts +19 -14
  47. package/dist/data-structures/trie/trie.js +27 -16
  48. package/dist/interfaces/binary-tree.d.ts +7 -7
  49. package/dist/types/common.d.ts +1 -23
  50. package/dist/types/data-structures/base/base.d.ts +5 -2
  51. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +3 -4
  52. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +3 -4
  53. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +22 -5
  54. package/dist/types/data-structures/binary-tree/bst.d.ts +7 -5
  55. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +3 -4
  56. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3 -4
  57. package/dist/types/data-structures/heap/heap.d.ts +3 -2
  58. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
  59. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +2 -1
  60. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  61. package/dist/types/data-structures/queue/deque.d.ts +4 -2
  62. package/dist/types/data-structures/queue/queue.d.ts +2 -1
  63. package/dist/types/data-structures/stack/stack.d.ts +2 -1
  64. package/dist/types/data-structures/trie/trie.d.ts +3 -2
  65. package/dist/utils/utils.js +3 -5
  66. package/package.json +2 -2
  67. package/src/data-structures/base/index.ts +2 -1
  68. package/src/data-structures/base/iterable-element-base.ts +250 -0
  69. package/src/data-structures/base/{iterable-base.ts → iterable-entry-base.ts} +22 -213
  70. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +146 -97
  71. package/src/data-structures/binary-tree/avl-tree.ts +97 -70
  72. package/src/data-structures/binary-tree/binary-tree.ts +591 -455
  73. package/src/data-structures/binary-tree/bst.ts +266 -293
  74. package/src/data-structures/binary-tree/rb-tree.ts +124 -104
  75. package/src/data-structures/binary-tree/tree-multi-map.ts +128 -103
  76. package/src/data-structures/graph/abstract-graph.ts +10 -10
  77. package/src/data-structures/graph/directed-graph.ts +2 -1
  78. package/src/data-structures/hash/hash-map.ts +46 -53
  79. package/src/data-structures/heap/heap.ts +71 -152
  80. package/src/data-structures/heap/max-heap.ts +88 -13
  81. package/src/data-structures/heap/min-heap.ts +78 -15
  82. package/src/data-structures/linked-list/doubly-linked-list.ts +32 -32
  83. package/src/data-structures/linked-list/singly-linked-list.ts +37 -29
  84. package/src/data-structures/priority-queue/max-priority-queue.ts +94 -13
  85. package/src/data-structures/priority-queue/min-priority-queue.ts +84 -15
  86. package/src/data-structures/priority-queue/priority-queue.ts +81 -4
  87. package/src/data-structures/queue/deque.ts +52 -27
  88. package/src/data-structures/queue/queue.ts +23 -37
  89. package/src/data-structures/stack/stack.ts +31 -26
  90. package/src/data-structures/trie/trie.ts +35 -20
  91. package/src/interfaces/binary-tree.ts +10 -10
  92. package/src/types/common.ts +2 -25
  93. package/src/types/data-structures/base/base.ts +14 -6
  94. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +3 -4
  95. package/src/types/data-structures/binary-tree/avl-tree.ts +3 -4
  96. package/src/types/data-structures/binary-tree/binary-tree.ts +26 -6
  97. package/src/types/data-structures/binary-tree/bst.ts +11 -5
  98. package/src/types/data-structures/binary-tree/rb-tree.ts +3 -4
  99. package/src/types/data-structures/binary-tree/tree-multi-map.ts +3 -4
  100. package/src/types/data-structures/heap/heap.ts +4 -1
  101. package/src/types/data-structures/linked-list/doubly-linked-list.ts +3 -1
  102. package/src/types/data-structures/linked-list/singly-linked-list.ts +3 -1
  103. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -1
  104. package/src/types/data-structures/queue/deque.ts +6 -1
  105. package/src/types/data-structures/queue/queue.ts +3 -1
  106. package/src/types/data-structures/stack/stack.ts +3 -1
  107. package/src/types/data-structures/trie/trie.ts +3 -1
  108. package/src/utils/utils.ts +3 -3
@@ -1,7 +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
+ import { BTNEntry } from '../../types';
2
3
  import { BST, BSTNode } from './bst';
3
4
  import { IBinaryTree } from '../../interfaces';
4
- 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> {
5
6
  /**
6
7
  * The constructor function initializes a Red-Black Tree Node with a key, an optional value, and a
7
8
  * color.
@@ -26,18 +27,18 @@ export declare class RedBlackTreeNode<K extends Comparable, V = any, NODE extend
26
27
  */
27
28
  set color(value: RBTNColor);
28
29
  }
29
- export declare class RedBlackTree<K extends Comparable, V = any, NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNode<K, V, RedBlackTreeNodeNested<K, V>>, TREE extends RedBlackTree<K, V, NODE, TREE> = RedBlackTree<K, V, NODE, RedBlackTreeNested<K, V, NODE>>> extends BST<K, V, NODE, TREE> implements IBinaryTree<K, V, 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> {
30
31
  /**
31
32
  * This is the constructor function for a Red-Black Tree data structure in TypeScript.
32
- * @param keysOrNodesOrEntries - The `keysOrNodesOrEntries` parameter is an iterable object that can
33
- * contain keys, nodes, or entries. It is used to initialize the RBTree with the provided keys,
34
- * nodes, or entries.
33
+ * @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
34
+ * iterable object that can contain either keys, nodes, entries, or raw elements. It is used to
35
+ * initialize the RBTree with the provided elements.
35
36
  * @param [options] - The `options` parameter is an optional object that can be passed to the
36
- * constructor. It allows you to customize the behavior of the RBTree. It can include properties such
37
- * as `compareKeys`, `compareValues`, `allowDuplicates`, etc. These properties define how the RBTree
38
- * should compare keys and
37
+ * constructor. It is of type `RBTreeOptions<K, V, R>`. This object can contain various options for
38
+ * configuring the behavior of the Red-Black Tree. The specific properties and their meanings would
39
+ * depend on the implementation
39
40
  */
40
- constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, options?: RBTreeOptions<K>);
41
+ constructor(keysOrNodesOrEntriesOrRawElements?: Iterable<R | BTNKeyOrNodeOrEntry<K, V, NODE>>, options?: RBTreeOptions<K, V, R>);
41
42
  protected _root: NODE | undefined;
42
43
  /**
43
44
  * The function returns the root node of a tree or undefined if there is no root.
@@ -46,54 +47,41 @@ export declare class RedBlackTree<K extends Comparable, V = any, NODE extends Re
46
47
  get root(): NODE | undefined;
47
48
  /**
48
49
  * The function creates a new Red-Black Tree node with the specified key, value, and color.
49
- * @param {K} key - The key parameter represents the key of the node being created. It is of type K,
50
- * which is a generic type representing the key's data type.
50
+ * @param {K} key - The key parameter represents the key value of the node being created. It is of
51
+ * type K, which is a generic type that can be replaced with any specific type when using the
52
+ * function.
51
53
  * @param {V} [value] - The `value` parameter is an optional parameter that represents the value
52
- * associated with the key in the node. It is not required and can be omitted if not needed.
53
- * @param {RBTNColor} color - The "color" parameter is used to specify the color of the node in a
54
- * Red-Black Tree. It is an optional parameter with a default value of "'BLACK'". The color
55
- * can be either "'RED'" or "'BLACK'".
56
- * @returns The method is returning a new instance of a RedBlackTreeNode with the specified key,
57
- * value, and color.
54
+ * associated with the key in the node. It is not required and can be omitted if you only need to
55
+ * create a node with a key.
56
+ * @param {RBTNColor} [color=BLACK] - The "color" parameter is used to specify the color of the node
57
+ * in a Red-Black Tree. It can have two possible values: "RED" or "BLACK". By default, the color is
58
+ * set to "BLACK" if not specified.
59
+ * @returns A new instance of a RedBlackTreeNode with the specified key, value, and color is being
60
+ * returned.
58
61
  */
59
62
  createNode(key: K, value?: V, color?: RBTNColor): NODE;
60
63
  /**
61
- * The function creates a Red-Black Tree with the given options and returns it.
62
- * @param [options] - The `options` parameter is an optional object that contains configuration
63
- * options for creating the Red-Black Tree. It is of type `RBTreeOptions<K>`, where `K` represents
64
- * the type of keys in the tree.
64
+ * The function creates a new Red-Black Tree with the specified options.
65
+ * @param [options] - The `options` parameter is an optional object that contains additional
66
+ * configuration options for creating the Red-Black Tree. It has the following properties:
65
67
  * @returns a new instance of a RedBlackTree object.
66
68
  */
67
- createTree(options?: RBTreeOptions<K>): TREE;
69
+ createTree(options?: RBTreeOptions<K, V, R>): TREE;
68
70
  /**
69
71
  * Time Complexity: O(1)
70
72
  * Space Complexity: O(1)
71
73
  */
72
74
  /**
73
- * Time Complexity: O(1)
74
- * Space Complexity: O(1)
75
- *
76
- * The function `keyValueOrEntryToNode` takes a key, value, or entry and returns a node if it is
77
- * valid, otherwise it returns undefined.
78
- * @param {KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntry - The key, value, or entry to convert.
79
- * @param {V} [value] - The value associated with the key (if `keyOrNodeOrEntry` is a key).
80
- * @returns {NODE | undefined} - The corresponding Red-Black Tree node, or `undefined` if conversion fails.
81
- */
82
- keyValueOrEntryToNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V): NODE | undefined;
83
- /**
84
- * Time Complexity: O(1)
85
- * Space Complexity: O(1)
86
- * /
87
-
88
- /**
89
75
  * Time Complexity: O(1)
90
76
  * Space Complexity: O(1)
91
77
  *
92
78
  * The function checks if the input is an instance of the RedBlackTreeNode class.
93
- * @param {KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntry - The object to check.
94
- * @returns {boolean} - `true` if the object is a Red-Black Tree node, `false` otherwise.
79
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
80
+ * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
81
+ * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
82
+ * an instance of the `RedBlackTreeNode` class.
95
83
  */
96
- isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntry is NODE;
84
+ isNode(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntryOrRawElement is NODE;
97
85
  /**
98
86
  * Time Complexity: O(1)
99
87
  * Space Complexity: O(1)
@@ -114,16 +102,18 @@ export declare class RedBlackTree<K extends Comparable, V = any, NODE extends Re
114
102
  * Time Complexity: O(log n)
115
103
  * Space Complexity: O(1)
116
104
  *
117
- * The function adds a new node to a Red-Black Tree data structure and returns a boolean indicating
118
- * whether the operation was successful.
119
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be either a key, a node, or an
120
- * entry.
121
- * @param {V} [value] - The `value` parameter is the value associated with the key that is being
122
- * added to the tree.
123
- * @returns The method is returning a boolean value. It returns true if the node was successfully
124
- * added or updated, and false otherwise.
105
+ * The function adds a new node to a binary search tree and returns true if the node was successfully
106
+ * added.
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
+ * @param {V} [value] - The `value` parameter is an optional value that you want to associate with
110
+ * the key in the data structure. It represents the value that you want to add or update in the data
111
+ * structure.
112
+ * @returns The method is returning a boolean value. If a new node is successfully added to the tree,
113
+ * the method returns true. If the node already exists and its value is updated, the method also
114
+ * returns true. If the node cannot be added or updated, the method returns false.
125
115
  */
126
- add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean;
116
+ add(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean;
127
117
  /**
128
118
  * Time Complexity: O(log n)
129
119
  * Space Complexity: O(1)
@@ -132,20 +122,27 @@ export declare class RedBlackTree<K extends Comparable, V = any, NODE extends Re
132
122
  * Time Complexity: O(log n)
133
123
  * Space Complexity: O(1)
134
124
  *
135
- * The function `delete` in a binary tree class deletes a node from the tree and fixes the tree if
136
- * necessary.
137
- * @param {ReturnType<C> | null | undefined} identifier - The `identifier` parameter is the
138
- * identifier of the node that needs to be deleted from the binary tree. It can be of any type that
139
- * is returned by the callback function `C`. It can also be `null` or `undefined` if the node to be
140
- * deleted is not found.
141
- * @param {C} callback - The `callback` parameter is a function that is used to retrieve a node from
142
- * the binary tree based on its identifier. It is an optional parameter and if not provided, the
143
- * `_DEFAULT_CALLBACK` function is used as the default callback. The callback function should
144
- * return the identifier of the node to
125
+ * The function overrides the delete method of a binary tree data structure, allowing for the
126
+ * deletion of a node and maintaining the balance of the tree.
127
+ * @param {ReturnType<C> | null | undefined} identifier - The `identifier` parameter is the value
128
+ * that identifies the node to be deleted from the binary tree. It can be of any type that is
129
+ * returned by the callback function `C`. It can also be `null` or `undefined` if there is no node to
130
+ * delete.
131
+ * @param {C} callback - The `callback` parameter is a function that is used to determine the
132
+ * equality of nodes in the binary tree. It is optional and has a default value of
133
+ * `this._DEFAULT_CALLBACK`. The type of the `callback` parameter is `C`, which is a generic type
134
+ * that extends the `BTNCallback
145
135
  * @returns an array of BinaryTreeDeleteResult<NODE> objects.
146
136
  */
147
137
  delete<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | null | undefined, callback?: C): BinaryTreeDeleteResult<NODE>[];
148
138
  /**
139
+ * Time Complexity: O(1)
140
+ * Space Complexity: O(1)
141
+ */
142
+ /**
143
+ * Time Complexity: O(1)
144
+ * Space Complexity: O(1)
145
+ *
149
146
  * The function sets the root of a tree-like structure and updates the parent property of the new
150
147
  * root.
151
148
  * @param {NODE | undefined} v - v is a parameter of type NODE or undefined.
@@ -162,8 +159,8 @@ export declare class RedBlackTree<K extends Comparable, V = any, NODE extends Re
162
159
  * The function replaces an old node with a new node while preserving the color of the old node.
163
160
  * @param {NODE} oldNode - The `oldNode` parameter represents the node that needs to be replaced in
164
161
  * the data structure.
165
- * @param {NODE} newNode - The `newNode` parameter is the new node that will replace the old node in
166
- * the data structure.
162
+ * @param {NODE} newNode - The `newNode` parameter is of type `NODE`, which represents a node in a
163
+ * data structure.
167
164
  * @returns The method is returning the result of calling the `_replaceNode` method from the
168
165
  * superclass, with the `oldNode` and `newNode` parameters.
169
166
  */
@@ -176,12 +173,13 @@ export declare class RedBlackTree<K extends Comparable, V = any, NODE extends Re
176
173
  * Time Complexity: O(log n)
177
174
  * Space Complexity: O(1)
178
175
  *
179
- * The `_insert` function inserts or updates a node in a binary search tree and performs necessary
180
- * fix-ups to maintain the red-black tree properties.
181
- * @param {NODE} node - The `node` parameter represents the node that needs to be inserted into a
182
- * binary search tree. It contains a `key` property that is used to determine the position of the
183
- * node in the tree.
184
- * @returns {'inserted' | 'updated'} - The result of the insertion.
176
+ * The `_insert` function inserts a node into a binary search tree and performs necessary fix-ups to
177
+ * maintain the red-black tree properties.
178
+ * @param {NODE} node - The `node` parameter represents the node that needs to be inserted into the
179
+ * binary search tree.
180
+ * @returns a string value indicating the result of the insertion operation. It can return either
181
+ * 'UPDATED' if the node with the same key already exists and was updated, or 'CREATED' if a new node
182
+ * was created and inserted into the tree.
185
183
  */
186
184
  protected _insert(node: NODE): CRUD;
187
185
  /**
@@ -207,8 +205,8 @@ export declare class RedBlackTree<K extends Comparable, V = any, NODE extends Re
207
205
  * Space Complexity: O(1)
208
206
  *
209
207
  * The `_insertFixup` function is used to fix the Red-Black Tree after inserting a new node.
210
- * @param {NODE | undefined} z - The parameter `z` represents a node in the Red-Black Tree. It can
211
- * either be a valid node object or `undefined`.
208
+ * @param {NODE | undefined} z - The parameter `z` represents a node in the Red-Black Tree data
209
+ * structure. It can either be a valid node or `undefined`.
212
210
  */
213
211
  protected _insertFixup(z: NODE | undefined): void;
214
212
  /**
@@ -221,9 +219,10 @@ export declare class RedBlackTree<K extends Comparable, V = any, NODE extends Re
221
219
  *
222
220
  * The `_deleteFixup` function is used to fix the red-black tree after a node deletion by adjusting
223
221
  * the colors and performing rotations.
224
- * @param {NODE | undefined} node - The `node` parameter represents a node in a Red-Black Tree data
225
- * structure. It can be either a valid node object or `undefined`.
226
- * @returns The function does not return any value. It has a return type of `void`.
222
+ * @param {NODE | undefined} node - The `node` parameter represents a node in a binary tree. It can
223
+ * be either a valid node object or `undefined`.
224
+ * @returns The function does not return any value. It has a return type of `void`, which means it
225
+ * does not return anything.
227
226
  */
228
227
  protected _deleteFixup(node: NODE | undefined): void;
229
228
  /**
@@ -37,19 +37,19 @@ exports.RedBlackTreeNode = RedBlackTreeNode;
37
37
  class RedBlackTree extends bst_1.BST {
38
38
  /**
39
39
  * This is the constructor function for a Red-Black Tree data structure in TypeScript.
40
- * @param keysOrNodesOrEntries - The `keysOrNodesOrEntries` parameter is an iterable object that can
41
- * contain keys, nodes, or entries. It is used to initialize the RBTree with the provided keys,
42
- * nodes, or entries.
40
+ * @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
41
+ * iterable object that can contain either keys, nodes, entries, or raw elements. It is used to
42
+ * initialize the RBTree with the provided elements.
43
43
  * @param [options] - The `options` parameter is an optional object that can be passed to the
44
- * constructor. It allows you to customize the behavior of the RBTree. It can include properties such
45
- * as `compareKeys`, `compareValues`, `allowDuplicates`, etc. These properties define how the RBTree
46
- * should compare keys and
44
+ * constructor. It is of type `RBTreeOptions<K, V, R>`. This object can contain various options for
45
+ * configuring the behavior of the Red-Black Tree. The specific properties and their meanings would
46
+ * depend on the implementation
47
47
  */
48
- constructor(keysOrNodesOrEntries = [], options) {
48
+ constructor(keysOrNodesOrEntriesOrRawElements = [], options) {
49
49
  super([], options);
50
50
  this._root = this.NIL;
51
- if (keysOrNodesOrEntries) {
52
- this.addMany(keysOrNodesOrEntries);
51
+ if (keysOrNodesOrEntriesOrRawElements) {
52
+ this.addMany(keysOrNodesOrEntriesOrRawElements);
53
53
  }
54
54
  }
55
55
  /**
@@ -61,24 +61,25 @@ class RedBlackTree extends bst_1.BST {
61
61
  }
62
62
  /**
63
63
  * The function creates a new Red-Black Tree node with the specified key, value, and color.
64
- * @param {K} key - The key parameter represents the key of the node being created. It is of type K,
65
- * which is a generic type representing the key's data type.
64
+ * @param {K} key - The key parameter represents the key value of the node being created. It is of
65
+ * type K, which is a generic type that can be replaced with any specific type when using the
66
+ * function.
66
67
  * @param {V} [value] - The `value` parameter is an optional parameter that represents the value
67
- * associated with the key in the node. It is not required and can be omitted if not needed.
68
- * @param {RBTNColor} color - The "color" parameter is used to specify the color of the node in a
69
- * Red-Black Tree. It is an optional parameter with a default value of "'BLACK'". The color
70
- * can be either "'RED'" or "'BLACK'".
71
- * @returns The method is returning a new instance of a RedBlackTreeNode with the specified key,
72
- * value, and color.
68
+ * associated with the key in the node. It is not required and can be omitted if you only need to
69
+ * create a node with a key.
70
+ * @param {RBTNColor} [color=BLACK] - The "color" parameter is used to specify the color of the node
71
+ * in a Red-Black Tree. It can have two possible values: "RED" or "BLACK". By default, the color is
72
+ * set to "BLACK" if not specified.
73
+ * @returns A new instance of a RedBlackTreeNode with the specified key, value, and color is being
74
+ * returned.
73
75
  */
74
76
  createNode(key, value, color = 'BLACK') {
75
77
  return new RedBlackTreeNode(key, value, color);
76
78
  }
77
79
  /**
78
- * The function creates a Red-Black Tree with the given options and returns it.
79
- * @param [options] - The `options` parameter is an optional object that contains configuration
80
- * options for creating the Red-Black Tree. It is of type `RBTreeOptions<K>`, where `K` represents
81
- * the type of keys in the tree.
80
+ * The function creates a new Red-Black Tree with the specified options.
81
+ * @param [options] - The `options` parameter is an optional object that contains additional
82
+ * configuration options for creating the Red-Black Tree. It has the following properties:
82
83
  * @returns a new instance of a RedBlackTree object.
83
84
  */
84
85
  createTree(options) {
@@ -89,56 +90,53 @@ class RedBlackTree extends bst_1.BST {
89
90
  * Space Complexity: O(1)
90
91
  */
91
92
  /**
92
- * Time Complexity: O(1)
93
- * Space Complexity: O(1)
94
- *
95
- * The function `keyValueOrEntryToNode` takes a key, value, or entry and returns a node if it is
96
- * valid, otherwise it returns undefined.
97
- * @param {KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntry - The key, value, or entry to convert.
98
- * @param {V} [value] - The value associated with the key (if `keyOrNodeOrEntry` is a key).
99
- * @returns {NODE | undefined} - The corresponding Red-Black Tree node, or `undefined` if conversion fails.
100
- */
101
- keyValueOrEntryToNode(keyOrNodeOrEntry, value) {
102
- let node;
103
- if (keyOrNodeOrEntry === null || keyOrNodeOrEntry === undefined) {
104
- return;
105
- }
106
- else if (this.isNode(keyOrNodeOrEntry)) {
107
- node = keyOrNodeOrEntry;
108
- }
109
- else if (this.isEntry(keyOrNodeOrEntry)) {
110
- const [key, value] = keyOrNodeOrEntry;
111
- if (key === undefined || key === null) {
112
- return;
113
- }
114
- else {
115
- node = this.createNode(key, value, 'RED');
116
- }
117
- }
118
- else if (!this.isNode(keyOrNodeOrEntry)) {
119
- node = this.createNode(keyOrNodeOrEntry, value, 'RED');
120
- }
121
- else {
122
- return;
123
- }
124
- return node;
125
- }
126
- /**
127
- * Time Complexity: O(1)
128
- * Space Complexity: O(1)
129
- * /
130
-
131
- /**
132
93
  * Time Complexity: O(1)
133
94
  * Space Complexity: O(1)
134
95
  *
135
96
  * The function checks if the input is an instance of the RedBlackTreeNode class.
136
- * @param {KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntry - The object to check.
137
- * @returns {boolean} - `true` if the object is a Red-Black Tree node, `false` otherwise.
97
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
98
+ * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
99
+ * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
100
+ * an instance of the `RedBlackTreeNode` class.
138
101
  */
139
- isNode(keyOrNodeOrEntry) {
140
- return keyOrNodeOrEntry instanceof RedBlackTreeNode;
102
+ isNode(keyOrNodeOrEntryOrRawElement) {
103
+ return keyOrNodeOrEntryOrRawElement instanceof RedBlackTreeNode;
141
104
  }
105
+ // /**
106
+ // * Time Complexity: O(1)
107
+ // * Space Complexity: O(1)
108
+ // */
109
+ //
110
+ // /**
111
+ // * Time Complexity: O(1)
112
+ // * Space Complexity: O(1)
113
+ // *
114
+ // * The function `keyValueOrEntryOrRawElementToNode` takes a key, value, or entry and returns a node if it is
115
+ // * valid, otherwise it returns undefined.
116
+ // * @param {BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The key, value, or entry to convert.
117
+ // * @param {V} [value] - The value associated with the key (if `keyOrNodeOrEntryOrRawElement` is a key).
118
+ // * @returns {NODE | undefined} - The corresponding Red-Black Tree node, or `undefined` if conversion fails.
119
+ // */
120
+ // override keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V): NODE | undefined {
121
+ //
122
+ // if (keyOrNodeOrEntryOrRawElement === null || keyOrNodeOrEntryOrRawElement === undefined) return;
123
+ // if (this.isNode(keyOrNodeOrEntryOrRawElement)) return keyOrNodeOrEntryOrRawElement;
124
+ //
125
+ // if (this.toEntryFn) {
126
+ // const [key, entryValue] = this.toEntryFn(keyOrNodeOrEntryOrRawElement as R);
127
+ // if (key) return this.createNode(key, entryValue ?? value, 'RED');
128
+ // }
129
+ //
130
+ // if (this.isEntry(keyOrNodeOrEntryOrRawElement)) {
131
+ // const [key, value] = keyOrNodeOrEntryOrRawElement;
132
+ // if (key === undefined || key === null) return;
133
+ // else return this.createNode(key, value, 'RED');
134
+ // }
135
+ //
136
+ // if (this.isKey(keyOrNodeOrEntryOrRawElement)) return this.createNode(keyOrNodeOrEntryOrRawElement, value, 'RED');
137
+ //
138
+ // return ;
139
+ // }
142
140
  /**
143
141
  * Time Complexity: O(1)
144
142
  * Space Complexity: O(1)
@@ -162,17 +160,19 @@ class RedBlackTree extends bst_1.BST {
162
160
  * Time Complexity: O(log n)
163
161
  * Space Complexity: O(1)
164
162
  *
165
- * The function adds a new node to a Red-Black Tree data structure and returns a boolean indicating
166
- * whether the operation was successful.
167
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be either a key, a node, or an
168
- * entry.
169
- * @param {V} [value] - The `value` parameter is the value associated with the key that is being
170
- * added to the tree.
171
- * @returns The method is returning a boolean value. It returns true if the node was successfully
172
- * added or updated, and false otherwise.
163
+ * The function adds a new node to a binary search tree and returns true if the node was successfully
164
+ * added.
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
+ * @param {V} [value] - The `value` parameter is an optional value that you want to associate with
168
+ * the key in the data structure. It represents the value that you want to add or update in the data
169
+ * structure.
170
+ * @returns The method is returning a boolean value. If a new node is successfully added to the tree,
171
+ * the method returns true. If the node already exists and its value is updated, the method also
172
+ * returns true. If the node cannot be added or updated, the method returns false.
173
173
  */
174
- add(keyOrNodeOrEntry, value) {
175
- const newNode = this.keyValueOrEntryToNode(keyOrNodeOrEntry, value);
174
+ add(keyOrNodeOrEntryOrRawElement, value) {
175
+ const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value);
176
176
  if (!this.isRealNode(newNode))
177
177
  return false;
178
178
  const insertStatus = this._insert(newNode);
@@ -198,16 +198,16 @@ class RedBlackTree extends bst_1.BST {
198
198
  * Time Complexity: O(log n)
199
199
  * Space Complexity: O(1)
200
200
  *
201
- * The function `delete` in a binary tree class deletes a node from the tree and fixes the tree if
202
- * necessary.
203
- * @param {ReturnType<C> | null | undefined} identifier - The `identifier` parameter is the
204
- * identifier of the node that needs to be deleted from the binary tree. It can be of any type that
205
- * is returned by the callback function `C`. It can also be `null` or `undefined` if the node to be
206
- * deleted is not found.
207
- * @param {C} callback - The `callback` parameter is a function that is used to retrieve a node from
208
- * the binary tree based on its identifier. It is an optional parameter and if not provided, the
209
- * `_DEFAULT_CALLBACK` function is used as the default callback. The callback function should
210
- * return the identifier of the node to
201
+ * The function overrides the delete method of a binary tree data structure, allowing for the
202
+ * deletion of a node and maintaining the balance of the tree.
203
+ * @param {ReturnType<C> | null | undefined} identifier - The `identifier` parameter is the value
204
+ * that identifies the node to be deleted from the binary tree. It can be of any type that is
205
+ * returned by the callback function `C`. It can also be `null` or `undefined` if there is no node to
206
+ * delete.
207
+ * @param {C} callback - The `callback` parameter is a function that is used to determine the
208
+ * equality of nodes in the binary tree. It is optional and has a default value of
209
+ * `this._DEFAULT_CALLBACK`. The type of the `callback` parameter is `C`, which is a generic type
210
+ * that extends the `BTNCallback
211
211
  * @returns an array of BinaryTreeDeleteResult<NODE> objects.
212
212
  */
213
213
  delete(identifier, callback = this._DEFAULT_CALLBACK) {
@@ -263,6 +263,13 @@ class RedBlackTree extends bst_1.BST {
263
263
  return results;
264
264
  }
265
265
  /**
266
+ * Time Complexity: O(1)
267
+ * Space Complexity: O(1)
268
+ */
269
+ /**
270
+ * Time Complexity: O(1)
271
+ * Space Complexity: O(1)
272
+ *
266
273
  * The function sets the root of a tree-like structure and updates the parent property of the new
267
274
  * root.
268
275
  * @param {NODE | undefined} v - v is a parameter of type NODE or undefined.
@@ -284,8 +291,8 @@ class RedBlackTree extends bst_1.BST {
284
291
  * The function replaces an old node with a new node while preserving the color of the old node.
285
292
  * @param {NODE} oldNode - The `oldNode` parameter represents the node that needs to be replaced in
286
293
  * the data structure.
287
- * @param {NODE} newNode - The `newNode` parameter is the new node that will replace the old node in
288
- * the data structure.
294
+ * @param {NODE} newNode - The `newNode` parameter is of type `NODE`, which represents a node in a
295
+ * data structure.
289
296
  * @returns The method is returning the result of calling the `_replaceNode` method from the
290
297
  * superclass, with the `oldNode` and `newNode` parameters.
291
298
  */
@@ -301,12 +308,13 @@ class RedBlackTree extends bst_1.BST {
301
308
  * Time Complexity: O(log n)
302
309
  * Space Complexity: O(1)
303
310
  *
304
- * The `_insert` function inserts or updates a node in a binary search tree and performs necessary
305
- * fix-ups to maintain the red-black tree properties.
306
- * @param {NODE} node - The `node` parameter represents the node that needs to be inserted into a
307
- * binary search tree. It contains a `key` property that is used to determine the position of the
308
- * node in the tree.
309
- * @returns {'inserted' | 'updated'} - The result of the insertion.
311
+ * The `_insert` function inserts a node into a binary search tree and performs necessary fix-ups to
312
+ * maintain the red-black tree properties.
313
+ * @param {NODE} node - The `node` parameter represents the node that needs to be inserted into the
314
+ * binary search tree.
315
+ * @returns a string value indicating the result of the insertion operation. It can return either
316
+ * 'UPDATED' if the node with the same key already exists and was updated, or 'CREATED' if a new node
317
+ * was created and inserted into the tree.
310
318
  */
311
319
  _insert(node) {
312
320
  var _a, _b;
@@ -378,8 +386,8 @@ class RedBlackTree extends bst_1.BST {
378
386
  * Space Complexity: O(1)
379
387
  *
380
388
  * The `_insertFixup` function is used to fix the Red-Black Tree after inserting a new node.
381
- * @param {NODE | undefined} z - The parameter `z` represents a node in the Red-Black Tree. It can
382
- * either be a valid node object or `undefined`.
389
+ * @param {NODE | undefined} z - The parameter `z` represents a node in the Red-Black Tree data
390
+ * structure. It can either be a valid node or `undefined`.
383
391
  */
384
392
  _insertFixup(z) {
385
393
  var _a, _b, _c, _d;
@@ -450,9 +458,10 @@ class RedBlackTree extends bst_1.BST {
450
458
  *
451
459
  * The `_deleteFixup` function is used to fix the red-black tree after a node deletion by adjusting
452
460
  * the colors and performing rotations.
453
- * @param {NODE | undefined} node - The `node` parameter represents a node in a Red-Black Tree data
454
- * structure. It can be either a valid node object or `undefined`.
455
- * @returns The function does not return any value. It has a return type of `void`.
461
+ * @param {NODE | undefined} node - The `node` parameter represents a node in a binary tree. It can
462
+ * be either a valid node object or `undefined`.
463
+ * @returns The function does not return any value. It has a return type of `void`, which means it
464
+ * does not return anything.
456
465
  */
457
466
  _deleteFixup(node) {
458
467
  var _a, _b, _c, _d;