linked-list-typed 1.51.8 → 1.52.0

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 +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 +318 -226
  12. package/dist/data-structures/binary-tree/binary-tree.js +475 -363
  13. package/dist/data-structures/binary-tree/bst.d.ts +192 -202
  14. package/dist/data-structures/binary-tree/bst.js +207 -249
  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/hash/hash-map.d.ts +33 -40
  22. package/dist/data-structures/hash/hash-map.js +40 -55
  23. package/dist/data-structures/heap/heap.d.ts +43 -114
  24. package/dist/data-structures/heap/heap.js +59 -127
  25. package/dist/data-structures/heap/max-heap.d.ts +50 -4
  26. package/dist/data-structures/heap/max-heap.js +76 -10
  27. package/dist/data-structures/heap/min-heap.d.ts +51 -5
  28. package/dist/data-structures/heap/min-heap.js +68 -11
  29. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +22 -28
  30. package/dist/data-structures/linked-list/doubly-linked-list.js +26 -28
  31. package/dist/data-structures/linked-list/singly-linked-list.d.ts +22 -25
  32. package/dist/data-structures/linked-list/singly-linked-list.js +29 -26
  33. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +50 -4
  34. package/dist/data-structures/priority-queue/max-priority-queue.js +79 -10
  35. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +51 -5
  36. package/dist/data-structures/priority-queue/min-priority-queue.js +71 -11
  37. package/dist/data-structures/priority-queue/priority-queue.d.ts +50 -4
  38. package/dist/data-structures/priority-queue/priority-queue.js +70 -1
  39. package/dist/data-structures/queue/deque.d.ts +21 -20
  40. package/dist/data-structures/queue/deque.js +29 -23
  41. package/dist/data-structures/queue/queue.d.ts +8 -28
  42. package/dist/data-structures/queue/queue.js +15 -31
  43. package/dist/data-structures/stack/stack.d.ts +17 -22
  44. package/dist/data-structures/stack/stack.js +25 -24
  45. package/dist/data-structures/trie/trie.d.ts +19 -14
  46. package/dist/data-structures/trie/trie.js +27 -16
  47. package/dist/interfaces/binary-tree.d.ts +7 -7
  48. package/dist/types/common.d.ts +1 -2
  49. package/dist/types/data-structures/base/base.d.ts +5 -2
  50. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +3 -4
  51. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +3 -4
  52. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +5 -5
  53. package/dist/types/data-structures/binary-tree/bst.d.ts +4 -5
  54. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +3 -4
  55. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3 -4
  56. package/dist/types/data-structures/heap/heap.d.ts +3 -2
  57. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
  58. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +2 -1
  59. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  60. package/dist/types/data-structures/queue/deque.d.ts +3 -2
  61. package/dist/types/data-structures/queue/queue.d.ts +2 -1
  62. package/dist/types/data-structures/stack/stack.d.ts +2 -1
  63. package/dist/types/data-structures/trie/trie.d.ts +3 -2
  64. package/dist/utils/utils.js +3 -5
  65. package/package.json +2 -2
  66. package/src/data-structures/base/index.ts +2 -1
  67. package/src/data-structures/base/iterable-element-base.ts +250 -0
  68. package/src/data-structures/base/{iterable-base.ts → iterable-entry-base.ts} +22 -213
  69. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +144 -95
  70. package/src/data-structures/binary-tree/avl-tree.ts +96 -69
  71. package/src/data-structures/binary-tree/binary-tree.ts +535 -403
  72. package/src/data-structures/binary-tree/bst.ts +247 -277
  73. package/src/data-structures/binary-tree/rb-tree.ts +123 -103
  74. package/src/data-structures/binary-tree/tree-multi-map.ts +127 -102
  75. package/src/data-structures/graph/abstract-graph.ts +10 -10
  76. package/src/data-structures/hash/hash-map.ts +46 -53
  77. package/src/data-structures/heap/heap.ts +71 -152
  78. package/src/data-structures/heap/max-heap.ts +88 -13
  79. package/src/data-structures/heap/min-heap.ts +78 -15
  80. package/src/data-structures/linked-list/doubly-linked-list.ts +32 -32
  81. package/src/data-structures/linked-list/singly-linked-list.ts +37 -29
  82. package/src/data-structures/priority-queue/max-priority-queue.ts +94 -13
  83. package/src/data-structures/priority-queue/min-priority-queue.ts +84 -15
  84. package/src/data-structures/priority-queue/priority-queue.ts +81 -4
  85. package/src/data-structures/queue/deque.ts +37 -26
  86. package/src/data-structures/queue/queue.ts +23 -36
  87. package/src/data-structures/stack/stack.ts +31 -26
  88. package/src/data-structures/trie/trie.ts +35 -20
  89. package/src/interfaces/binary-tree.ts +9 -9
  90. package/src/types/common.ts +1 -2
  91. package/src/types/data-structures/base/base.ts +14 -6
  92. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +3 -4
  93. package/src/types/data-structures/binary-tree/avl-tree.ts +3 -4
  94. package/src/types/data-structures/binary-tree/binary-tree.ts +6 -6
  95. package/src/types/data-structures/binary-tree/bst.ts +4 -5
  96. package/src/types/data-structures/binary-tree/rb-tree.ts +3 -4
  97. package/src/types/data-structures/binary-tree/tree-multi-map.ts +3 -4
  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 +3 -1
  103. package/src/types/data-structures/queue/queue.ts +3 -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/utils/utils.ts +3 -3
@@ -5,10 +5,11 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { BSTNested, BSTNKeyOrNode, BSTNodeNested, BSTOptions, BTNCallback, Comparable, Comparator, CP, DFSOrderPattern, IterationType, KeyOrNodeOrEntry } from '../../types';
8
+ import type { BSTNested, BSTNKeyOrNode, BSTNodeNested, BSTOptions, BTNCallback, Comparator, CP, DFSOrderPattern, IterationType, KeyOrNodeOrEntry } from '../../types';
9
+ import { BTNEntry } from '../../types';
9
10
  import { BinaryTree, BinaryTreeNode } from './binary-tree';
10
11
  import { IBinaryTree } from '../../interfaces';
11
- export declare class BSTNode<K extends Comparable, V = any, NODE extends BSTNode<K, V, NODE> = BSTNodeNested<K, V>> extends BinaryTreeNode<K, V, NODE> {
12
+ export declare class BSTNode<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BSTNodeNested<K, V>> extends BinaryTreeNode<K, V, NODE> {
12
13
  parent?: NODE;
13
14
  constructor(key: K, value?: V);
14
15
  protected _left?: NODE;
@@ -46,29 +47,22 @@ export declare class BSTNode<K extends Comparable, V = any, NODE extends BSTNode
46
47
  * 6. Balance Variability: Can become unbalanced; special types maintain balance.
47
48
  * 7. No Auto-Balancing: Standard BSTs don't automatically balance themselves.
48
49
  */
49
- export declare class BST<K extends Comparable, V = any, NODE extends BSTNode<K, V, NODE> = BSTNode<K, V, BSTNodeNested<K, V>>, TREE extends BST<K, V, NODE, TREE> = BST<K, V, NODE, BSTNested<K, V, NODE>>> extends BinaryTree<K, V, NODE, TREE> implements IBinaryTree<K, V, NODE, TREE> {
50
+ export declare class BST<K = any, V = any, R = BTNEntry<K, V>, NODE extends BSTNode<K, V, NODE> = BSTNode<K, V, BSTNodeNested<K, V>>, TREE extends BST<K, V, R, NODE, TREE> = BST<K, V, R, NODE, BSTNested<K, V, R, NODE>>> extends BinaryTree<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
50
51
  /**
51
- * This is the constructor function for a Binary Search Tree class in TypeScript, which initializes
52
- * the tree with keys, nodes, or entries and optional options.
53
- * @param keysOrNodesOrEntries - The `keysOrNodesOrEntries` parameter is an iterable object that can
54
- * contain keys, nodes, or entries. It is used to initialize the binary search tree with the provided
55
- * keys, nodes, or entries.
56
- * @param [options] - The `options` parameter is an optional object that can contain additional
57
- * configuration options for the binary search tree. It can have the following properties:
52
+ * This is the constructor function for a Binary Search Tree class in TypeScript.
53
+ * @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
54
+ * iterable that can contain either keys, nodes, entries, or raw elements. These elements will be
55
+ * added to the binary search tree during the construction of the object.
56
+ * @param [options] - An optional object that contains additional options for the Binary Search Tree.
57
+ * It can include a comparator function that defines the order of the elements in the tree.
58
58
  */
59
- constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, options?: BSTOptions<K>);
59
+ constructor(keysOrNodesOrEntriesOrRawElements?: Iterable<R | KeyOrNodeOrEntry<K, V, NODE>>, options?: BSTOptions<K, V, R>);
60
60
  protected _root?: NODE;
61
61
  /**
62
62
  * The function returns the root node of a tree structure.
63
63
  * @returns The `_root` property of the object, which is of type `NODE` or `undefined`.
64
64
  */
65
65
  get root(): NODE | undefined;
66
- protected _comparator: Comparator<K>;
67
- /**
68
- * The function returns the value of the _comparator property.
69
- * @returns The `_comparator` property is being returned.
70
- */
71
- get comparator(): Comparator<K>;
72
66
  /**
73
67
  * The function creates a new BSTNode with the given key and value and returns it.
74
68
  * @param {K} key - The key parameter is of type K, which represents the type of the key for the node
@@ -81,72 +75,69 @@ export declare class BST<K extends Comparable, V = any, NODE extends BSTNode<K,
81
75
  /**
82
76
  * The function creates a new binary search tree with the specified options.
83
77
  * @param [options] - The `options` parameter is an optional object that allows you to customize the
84
- * behavior of the `createTree` method. It is of type `Partial<BSTOptions<K>>`, which means it is a
85
- * partial object of type `BSTOptions<K>`.
86
- * @returns a new instance of the BST class, with the provided options merged with the default
87
- * options. The returned value is casted as TREE.
88
- */
89
- createTree(options?: Partial<BSTOptions<K>>): TREE;
90
- /**
91
- * The function `keyValueOrEntryToNode` takes an keyOrNodeOrEntry and returns a node if the keyOrNodeOrEntry is valid,
92
- * otherwise it returns undefined.
93
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`, where:
94
- * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
95
- * `keyValueOrEntryToNode` function. It represents the value associated with the keyOrNodeOrEntry node.
96
- * @returns a node of type NODE or undefined.
78
+ * behavior of the `createTree` method. It accepts a partial `BSTOptions` object, which has the
79
+ * following properties:
80
+ * @returns a new instance of the BST class with the provided options.
97
81
  */
98
- keyValueOrEntryToNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V): NODE | undefined;
82
+ createTree(options?: Partial<BSTOptions<K, V, R>>): TREE;
99
83
  /**
100
- * Time Complexity: O(log n)
101
- * Space Complexity: O(log n)
84
+ * The function overrides a method and converts a key, value pair or entry or raw element to a node.
85
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - A variable that can be of
86
+ * type R or KeyOrNodeOrEntry<K, V, NODE>. It represents either a key, a node, an entry, or a raw
87
+ * element.
88
+ * @param {V} [value] - The `value` parameter is an optional value of type `V`. It represents the
89
+ * value associated with a key in a key-value pair.
90
+ * @returns either a NODE object or undefined.
102
91
  */
92
+ keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>, value?: V): NODE | undefined;
103
93
  /**
104
94
  * Time Complexity: O(log n)
105
95
  * Space Complexity: O(log n)
106
96
  *
107
- * The function `ensureNode` returns the node corresponding to the given key if it is a node key,
108
- * otherwise it returns the key itself.
109
- * @param {K | NODE | undefined} keyOrNodeOrEntry - The `key` parameter can be of type `K`, `NODE`, or
110
- * `undefined`.
111
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
112
- * type of iteration to be performed. It has a default value of `'ITERATIVE'`.
113
- * @returns either a node object (NODE) or undefined.
114
- */
115
- ensureNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | undefined;
116
- /**
117
- * The function checks if an keyOrNodeOrEntry is an instance of BSTNode.
118
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is a variable of type `KeyOrNodeOrEntry<K, V, NODE>`.
119
- * @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the BSTNode class.
120
- */
121
- isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntry is NODE;
122
- /**
123
- * Time Complexity: O(log n)
124
- * Space Complexity: O(1)
125
- */
97
+ * The function ensures the existence of a node in a data structure and returns it, or undefined if
98
+ * it doesn't exist.
99
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
100
+ * `keyOrNodeOrEntryOrRawElement` can accept a value of type `R`, which represents the key, node,
101
+ * entry, or raw element that needs to be ensured in the tree.
102
+ * @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
103
+ * parameter that specifies the type of iteration to be used when ensuring a node. It has a default
104
+ * value of `'ITERATIVE'`.
105
+ * @returns The method is returning either the node that was ensured or `undefined` if the node could
106
+ * not be ensured.
107
+ */
108
+ ensureNode(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | undefined;
109
+ /**
110
+ * The function checks if the input is an instance of the BSTNode class.
111
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
112
+ * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
113
+ * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
114
+ * an instance of the `BSTNode` class.
115
+ */
116
+ isNode(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntryOrRawElement is NODE;
126
117
  /**
127
118
  * Time Complexity: O(log n)
128
119
  * Space Complexity: O(1)
129
120
  *
130
- * The `add` function in TypeScript adds a new node to a binary search tree based on the key value,
131
- * updating the value if the key already exists.
132
- * @param keyOrNodeOrEntry - It is a parameter that can accept three types of values:
133
- * @param {V} [value] - The value to be added to the binary search tree.
134
- * @returns The method returns a boolean value.
121
+ * The `add` function in TypeScript adds a new node to a binary search tree based on the key value.
122
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
123
+ * `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
124
+ * @param {V} [value] - The `value` parameter is an optional value that can be associated with the
125
+ * key in the binary search tree. If provided, it will be stored in the node along with the key.
126
+ * @returns a boolean value.
135
127
  */
136
- add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean;
128
+ add(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean;
137
129
  /**
138
- * Time Complexity: O(k log n)
139
- * Space Complexity: O(k + log n)
130
+ * Time Complexity: O(log n)
131
+ * Space Complexity: O(log n)
140
132
  */
141
133
  /**
142
134
  * Time Complexity: O(k log n)
143
135
  * Space Complexity: O(k + log n)
144
136
  *
145
- * The `addMany` function in TypeScript adds multiple keys or nodes to a data structure, balancing
146
- * the structure if specified, and returns an array indicating whether each key or node was
147
- * successfully inserted.
148
- * @param keysOrNodesOrEntries - An iterable containing keys, nodes, or entries to be added to the
149
- * data structure.
137
+ * The `addMany` function in TypeScript adds multiple keys or nodes to a data structure and returns
138
+ * an array indicating whether each key or node was successfully inserted.
139
+ * @param keysOrNodesOrEntriesOrRawElements - An iterable containing keys, nodes, entries, or raw
140
+ * elements to be added to the data structure.
150
141
  * @param [values] - An optional iterable of values to be associated with the keys or nodes being
151
142
  * added. If provided, the values will be assigned to the corresponding keys or nodes in the same
152
143
  * order. If not provided, undefined will be assigned as the value for each key or node.
@@ -155,42 +146,35 @@ export declare class BST<K extends Comparable, V = any, NODE extends BSTNode<K,
155
146
  * algorithm. If set to false, the elements will be added without balancing the tree. The default
156
147
  * value is true.
157
148
  * @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
158
- * specifies the type of iteration to use when adding multiple keys or nodes to the binary tree. It
159
- * has a default value of `this.iterationType`, which means it will use the iteration type specified
160
- * in the binary tree instance.
161
- * @returns The function `addMany` returns an array of booleans indicating whether each key or node
162
- * or entry was successfully inserted into the data structure.
149
+ * specifies the type of iteration to use when adding multiple keys or nodes to the binary search
150
+ * tree. It can have two possible values:
151
+ * @returns The function `addMany` returns an array of booleans indicating whether each element was
152
+ * successfully inserted into the data structure.
163
153
  */
164
- addMany(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, values?: Iterable<V | undefined>, isBalanceAdd?: boolean, iterationType?: IterationType): boolean[];
154
+ addMany(keysOrNodesOrEntriesOrRawElements: Iterable<R | KeyOrNodeOrEntry<K, V, NODE>>, values?: Iterable<V | undefined>, isBalanceAdd?: boolean, iterationType?: IterationType): boolean[];
165
155
  /**
166
- * Time Complexity: O(log n)
167
- * Space Complexity: O(k + log n)
168
- * /
169
-
170
- /**
171
156
  * Time Complexity: O(log n)
172
157
  * Space Complexity: O(k + log n)
173
158
  *
174
- * The function `getNodes` returns an array of nodes that match a given identifier, using either a
175
- * recursive or iterative approach.
159
+ * The `getNodes` function in TypeScript retrieves nodes from a binary tree based on a given
160
+ * identifier and callback function.
176
161
  * @param {ReturnType<C> | undefined} identifier - The `identifier` parameter is the value that you
177
- * want to search for in the nodes of the binary tree. It can be of any type that is returned by the
178
- * callback function `C`.
179
- * @param {C} callback - The `callback` parameter is a function that takes a node of type `NODE` as its
180
- * argument and returns a value of type `ReturnType<C>`. The `C` type parameter represents a callback
181
- * function type that extends the `BTNCallback<NODE>` type. The `BTNCallback<NODE>` type is
182
- * @param [onlyOne=false] - A boolean flag indicating whether to stop searching after finding the
183
- * first node that matches the identifier. If set to true, the function will return an array
184
- * containing only the first matching node. If set to false (default), the function will continue
185
- * searching for all nodes that match the identifier and return an array containing
186
- * @param {K | NODE | undefined} beginRoot - The `beginRoot` parameter represents the starting node
187
- * for the traversal. It can be either a key value or a node object. If it is undefined, the
188
- * traversal will start from the root of the tree.
189
- * @param iterationType - The `iterationType` parameter determines the type of iteration to be
190
- * performed on the binary tree. It can have two possible values:
191
- * @returns The method returns an array of nodes (`NODE[]`).
192
- */
193
- getNodes<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | undefined, callback?: C, onlyOne?: boolean, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE[];
162
+ * want to search for in the binary tree. It can be of any type that is returned by the callback
163
+ * function.
164
+ * @param {C} callback - The `callback` parameter is a function that takes a node as input and
165
+ * returns a value. This value is used to identify the nodes that match the given identifier. The
166
+ * `callback` function is optional and defaults to `this._DEFAULT_CALLBACK`.
167
+ * @param [onlyOne=false] - A boolean value indicating whether to return only the first matching node
168
+ * or all matching nodes. If set to true, only the first matching node will be returned. If set to
169
+ * false, all matching nodes will be returned. The default value is false.
170
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
171
+ * point for the search in the binary tree. It can be either a node object, a key-value pair, or an
172
+ * entry object. If it is not provided, the `root` of the binary tree is used as the starting point.
173
+ * @param {IterationType} iterationType - The `iterationType` parameter determines the type of
174
+ * iteration to be performed. It can have two possible values:
175
+ * @returns The method `getNodes` returns an array of `NODE` objects.
176
+ */
177
+ getNodes<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | undefined, callback?: C, onlyOne?: boolean, beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE[];
194
178
  /**
195
179
  * Time Complexity: O(log n)
196
180
  * Space Complexity: O(1)
@@ -199,46 +183,45 @@ export declare class BST<K extends Comparable, V = any, NODE extends BSTNode<K,
199
183
  * Time Complexity: O(log n)
200
184
  * Space Complexity: O(1)
201
185
  *
202
- * The `getNode` function retrieves a node from a Red-Black Tree based on the provided identifier and
203
- * callback function.
204
- * @param {ReturnType<C> | undefined} identifier - The `identifier` parameter is the value or key
205
- * that you want to search for in the binary search tree. It can be of any type that is compatible
206
- * with the type of nodes in the tree.
207
- * @param {C} callback - The `callback` parameter is a function that will be called for each node in
208
- * the tree. It is used to determine whether a node matches the given identifier. The `callback`
209
- * function should take a node as its parameter and return a value that can be compared to the
210
- * `identifier` parameter.
186
+ * The function `getNode` returns the first node that matches the given identifier and callback
187
+ * function in a binary search tree.
188
+ * @param {ReturnType<C> | undefined} identifier - The `identifier` parameter is the value that you
189
+ * want to search for in the binary search tree. It can be of any type that is compatible with the
190
+ * type returned by the callback function.
191
+ * @param {C} callback - The `callback` parameter is a function that will be used to determine if a
192
+ * node matches the desired criteria. It should be a function that takes a node as an argument and
193
+ * returns a boolean value indicating whether the node matches the criteria or not. If no callback is
194
+ * provided, the default callback will be
211
195
  * @param beginRoot - The `beginRoot` parameter is the starting point for the search in the binary
212
- * search tree. It can be either a key or a node. If it is a key, it will be converted to a node
213
- * using the `ensureNode` method. If it is not provided, the `root`
214
- * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
215
- * be performed when searching for nodes in the binary search tree. It is an optional parameter and
216
- * its default value is taken from the `iterationType` property of the class.
217
- * @returns The method is returning a value of type `NODE | null | undefined`.
196
+ * search tree. It can be either a key or a node. If it is a key, the search will start from the node
197
+ * with that key. If it is a node, the search will start from that node.
198
+ * @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
199
+ * of iteration to be performed when searching for nodes in the binary search tree. It can have one
200
+ * of the following values:
201
+ * @returns The method is returning a NODE object or undefined.
218
202
  */
219
- getNode<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | undefined, callback?: C, beginRoot?: BSTNKeyOrNode<K, NODE>, iterationType?: IterationType): NODE | undefined;
203
+ getNode<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | undefined, callback?: C, beginRoot?: R | BSTNKeyOrNode<K, NODE>, iterationType?: IterationType): NODE | undefined;
220
204
  /**
221
- * Time Complexity: O(log n)
222
- * Space Complexity: O(1)
205
+ * Time Complexity: O(k log n)
206
+ * Space Complexity: O(k + log n)
223
207
  */
224
208
  /**
225
209
  * Time Complexity: O(log n)
226
210
  * Space Complexity: O(1)
227
211
  *
228
- * The function `getNodeByKey` searches for a node in a binary tree based on a given key, using
229
- * either recursive or iterative methods.
230
- * @param {K} key - The `key` parameter is the key value that we are searching for in the tree.
231
- * It is used to identify the node that we want to retrieve.
232
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
233
- * type of iteration to use when searching for a node in the binary tree. It can have two possible
234
- * values:
235
- * @returns The function `getNodeByKey` returns a node (`NODE`) if a node with the specified key is
236
- * found in the binary tree. If no node is found, it returns `undefined`.
212
+ * The function `getNodeByKey` returns a node with a specific key from a tree data structure.
213
+ * @param {K} key - The key parameter is the value used to search for a specific node in the tree. It
214
+ * is typically a unique identifier or a value that can be used to determine the position of the node
215
+ * in the tree structure.
216
+ * @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
217
+ * parameter that specifies the type of iteration to be used when searching for a node in the tree.
218
+ * It has a default value of `'ITERATIVE'`.
219
+ * @returns The method is returning a NODE object or undefined.
237
220
  */
238
221
  getNodeByKey(key: K, iterationType?: IterationType): NODE | undefined;
239
222
  /**
240
- * Time complexity: O(n)
241
- * Space complexity: O(n)
223
+ * Time Complexity: O(log n)
224
+ * Space Complexity: O(k + log n)
242
225
  */
243
226
  /**
244
227
  * Time complexity: O(n)
@@ -247,22 +230,23 @@ export declare class BST<K extends Comparable, V = any, NODE extends BSTNode<K,
247
230
  * The function overrides the depth-first search method and returns an array of the return types of
248
231
  * the callback function.
249
232
  * @param {C} callback - The `callback` parameter is a function that will be called for each node
250
- * during the depth-first search traversal. It is an optional parameter and if not provided, a
251
- * default callback function will be used.
252
- * @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter specifies the order in which the
253
- * nodes are visited during the depth-first search. It can have one of the following values:
254
- * @param beginRoot - The `beginRoot` parameter is used to specify the starting point for the
255
- * Depth-First Search (DFS) traversal. It can be either a key, a node, or an entry in the tree. If no
256
- * value is provided, the DFS traversal will start from the root of the tree.
257
- * @param {IterationType} iterationType - The `iterationType` parameter specifies the type of
258
- * iteration to be used during the Depth-First Search (DFS) traversal. It can have one of the
233
+ * during the depth-first search traversal. It is an optional parameter and defaults to
234
+ * `this._DEFAULT_CALLBACK`. The type `C` represents the type of the callback function.
235
+ * @param {DFSOrderPattern} [pattern=IN] - The "pattern" parameter in the code snippet refers to the
236
+ * order in which the Depth-First Search (DFS) algorithm visits the nodes in a tree or graph. It can
237
+ * take one of the following values:
238
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
239
+ * point for the depth-first search traversal. It can be either a root node, a key-value pair, or a
240
+ * node entry. If not specified, the default value is the root of the tree.
241
+ * @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter specifies the
242
+ * type of iteration to be used during the Depth-First Search (DFS) traversal. It can have one of the
259
243
  * following values:
260
244
  * @returns The method is returning an array of the return type of the callback function.
261
245
  */
262
- dfs<C extends BTNCallback<NODE>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[];
246
+ dfs<C extends BTNCallback<NODE>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[];
263
247
  /**
264
- * Time complexity: O(n)
265
- * Space complexity: O(n)
248
+ * Time Complexity: O(log n)
249
+ * Space Complexity: O(1)
266
250
  */
267
251
  /**
268
252
  * Time complexity: O(n)
@@ -271,109 +255,115 @@ export declare class BST<K extends Comparable, V = any, NODE extends BSTNode<K,
271
255
  * The function overrides the breadth-first search method and returns an array of the return types of
272
256
  * the callback function.
273
257
  * @param {C} callback - The `callback` parameter is a function that will be called for each node
274
- * visited during the breadth-first search traversal. It is an optional parameter and if not
275
- * provided, a default callback function will be used.
276
- * @param beginRoot - The `beginRoot` parameter is the starting point for the breadth-first search
277
- * traversal. It can be either a key, a node, or an entry in the tree. If not specified, the root of
278
- * the tree is used as the starting point.
279
- * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
280
- * be performed during the breadth-first search (BFS) traversal. It determines the order in which the
281
- * nodes are visited.
282
- * @returns The method is returning an array of the return type of the callback function.
283
- */
284
- bfs<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[];
258
+ * visited during the breadth-first search. It should take a single argument, which is the current
259
+ * node being visited, and it can return a value of any type.
260
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
261
+ * point for the breadth-first search. It can be either a root node, a key-value pair, or an entry
262
+ * object. If no value is provided, the default value is the root of the tree.
263
+ * @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
264
+ * of iteration to be performed during the breadth-first search (BFS) traversal. It can have one of
265
+ * the following values:
266
+ * @returns an array of the return type of the callback function.
267
+ */
268
+ bfs<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[];
285
269
  /**
286
- * Time complexity: O(n)
287
- * Space complexity: O(n)
270
+ * Time Complexity: O(log n)
271
+ * Space Complexity: O(1)
288
272
  */
289
273
  /**
290
274
  * Time complexity: O(n)
291
275
  * Space complexity: O(n)
292
276
  *
293
- * The function overrides the listLevels method and returns an array of arrays containing the return
294
- * type of the callback function for each level of the tree.
277
+ * The function overrides the listLevels method from the superclass and returns an array of arrays
278
+ * containing the results of the callback function applied to each level of the tree.
295
279
  * @param {C} callback - The `callback` parameter is a generic type `C` that extends
296
- * `BTNCallback<NODE>`. It represents a callback function that will be called for each node in the tree
297
- * during the level listing process.
298
- * @param beginRoot - The `beginRoot` parameter is used to specify the starting point for listing the
299
- * levels of a binary tree. It can be either a key, a node, or an entry in the binary tree. If not
300
- * provided, the root of the binary tree is used as the starting point.
301
- * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
302
- * be performed on the tree. It determines the order in which the nodes are visited during the
303
- * iteration.
280
+ * `BTNCallback<NODE>`. It represents a callback function that will be called for each node in the
281
+ * tree during the iteration process.
282
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
283
+ * point for listing the levels of the binary tree. It can be either a root node of the tree, a
284
+ * key-value pair representing a node in the tree, or a key representing a node in the tree. If no
285
+ * value is provided, the root of
286
+ * @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
287
+ * of iteration to be performed on the tree. It can have one of the following values:
304
288
  * @returns The method is returning a two-dimensional array of the return type of the callback
305
289
  * function.
306
290
  */
307
- listLevels<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[][];
291
+ listLevels<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[][];
308
292
  /**
309
- * Time Complexity: O(log n)
310
- * Space Complexity: O(log n)
293
+ * Time complexity: O(n)
294
+ * Space complexity: O(n)
311
295
  */
312
296
  /**
313
- * Time Complexity: O(log n)
314
- * Space Complexity: O(log n)
297
+ * Time complexity: O(n)
298
+ * Space complexity: O(n)
315
299
  *
316
- * The `lesserOrGreaterTraverse` function traverses a binary tree and returns an array of nodes that
317
- * are either lesser or greater than a target node, depending on the specified comparison type.
300
+ * The `lesserOrGreaterTraverse` function traverses a binary tree and applies a callback function to
301
+ * each node that meets a certain condition based on a target node and a comparison value.
318
302
  * @param {C} callback - The `callback` parameter is a function that will be called for each node
319
- * that satisfies the condition specified by the `lesserOrGreater` parameter. It takes a single
320
- * parameter of type `NODE` (the node type) and returns a value of any type.
303
+ * that meets the condition specified by the `lesserOrGreater` parameter. It takes a single argument,
304
+ * which is the current node being traversed, and returns a value of any type.
321
305
  * @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to
322
- * traverse nodes that are lesser than, greater than, or equal to the `targetNode`. It is of type
323
- * `CP`, which is a custom type representing the comparison operator. The possible values for
324
- * `lesserOrGreater` are
325
- * @param {K | NODE | undefined} targetNode - The `targetNode` parameter represents the node in the
326
- * binary tree that you want to traverse from. It can be specified either by its key, by the node
327
- * object itself, or it can be left undefined to start the traversal from the root of the tree.
328
- * @param iterationType - The `iterationType` parameter determines the type of traversal to be
329
- * performed on the binary tree. It can have two possible values:
306
+ * traverse nodes that are lesser, greater, or both than the `targetNode`. It accepts the values -1,
307
+ * 0, or 1, where:
308
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} targetNode - The `targetNode` parameter is the node in
309
+ * the binary tree that you want to start traversing from. It can be specified either by providing
310
+ * the key of the node, the node itself, or an entry containing the key and value of the node. If no
311
+ * `targetNode` is provided,
312
+ * @param {IterationType} iterationType - The `iterationType` parameter determines the type of
313
+ * traversal to be performed on the binary tree. It can have two possible values:
330
314
  * @returns The function `lesserOrGreaterTraverse` returns an array of values of type
331
315
  * `ReturnType<C>`, which is the return type of the callback function passed as an argument.
332
316
  */
333
- lesserOrGreaterTraverse<C extends BTNCallback<NODE>>(callback?: C, lesserOrGreater?: CP, targetNode?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[];
317
+ lesserOrGreaterTraverse<C extends BTNCallback<NODE>>(callback?: C, lesserOrGreater?: CP, targetNode?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[];
334
318
  /**
335
- * Time Complexity: O(log n)
336
- * Space Complexity: O(log n)
319
+ * Time complexity: O(n)
320
+ * Space complexity: O(n)
337
321
  */
338
322
  /**
339
- * Time Complexity: O(log n)
340
- * Space Complexity: O(log n)
323
+ * Time complexity: O(n)
324
+ * Space complexity: O(n)
341
325
  *
342
- * The `perfectlyBalance` function balances a binary search tree by adding nodes in a way that
343
- * ensures the tree is perfectly balanced.
344
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
345
- * type of iteration to use when building a balanced binary search tree. It can have two possible
346
- * values:
326
+ * The `perfectlyBalance` function takes an optional `iterationType` parameter and returns `true` if
327
+ * the binary search tree is perfectly balanced, otherwise it returns `false`.
328
+ * @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
329
+ * specifies the type of iteration to use when building a balanced binary search tree. It has a
330
+ * default value of `this.iterationType`, which means it will use the iteration type specified in the
331
+ * current instance of the class.
347
332
  * @returns The function `perfectlyBalance` returns a boolean value.
348
333
  */
349
334
  perfectlyBalance(iterationType?: IterationType): boolean;
350
335
  /**
351
- * Balancing Adjustment:
352
- * Perfectly Balanced Binary Tree: Since the balance of a perfectly balanced binary tree is already fixed, no additional balancing adjustment is needed. Any insertion or deletion operation will disrupt the perfect balance, often requiring a complete reconstruction of the tree.
353
- * AVL Tree: After insertion or deletion operations, an AVL tree performs rotation adjustments based on the balance factor of nodes to restore the tree's balance. These rotations can be left rotations, right rotations, left-right rotations, or right-left rotations, performed as needed.
354
- *
355
- * Use Cases and Efficiency:
356
- * Perfectly Balanced Binary Tree: Perfectly balanced binary trees are typically used in specific scenarios such as complete binary heaps in heap sort or certain types of Huffman trees. However, they are not suitable for dynamic operations requiring frequent insertions and deletions, as these operations often necessitate full tree reconstruction.
357
- * AVL Tree: AVL trees are well-suited for scenarios involving frequent searching, insertion, and deletion operations. Through rotation adjustments, AVL trees maintain their balance, ensuring average and worst-case time complexity of O(log n).
336
+ * Time complexity: O(n)
337
+ * Space complexity: O(n)
358
338
  */
359
339
  /**
360
340
  * Time Complexity: O(n)
361
341
  * Space Complexity: O(log n)
342
+ *
343
+ * The function `isAVLBalanced` checks if a binary tree is AVL balanced using either a recursive or
344
+ * iterative approach.
345
+ * @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
346
+ * specifies the type of iteration to use when checking if the AVL tree is balanced. It has a default
347
+ * value of `this.iterationType`, which means it will use the iteration type specified in the current
348
+ * instance of the AVL tree.
349
+ * @returns a boolean value.
362
350
  */
351
+ isAVLBalanced(iterationType?: IterationType): boolean;
352
+ protected _DEFAULT_COMPARATOR: (a: K, b: K) => number;
353
+ protected _comparator: Comparator<K>;
363
354
  /**
364
355
  * Time Complexity: O(n)
365
356
  * Space Complexity: O(log n)
366
- *
367
- * The function checks if a binary tree is AVL balanced using either recursive or iterative approach.
368
- * @param iterationType - The `iterationType` parameter is used to determine the method of iteration
369
- * to check if the AVL tree is balanced. It can have two possible values:
370
- * @returns a boolean value.
371
357
  */
372
- isAVLBalanced(iterationType?: IterationType): boolean;
373
358
  /**
374
- * The function sets the root property of an object and updates the parent property of the new root.
375
- * @param {NODE | undefined} v - The parameter `v` is of type `NODE | undefined`. This means that it
376
- * can either be an object of type `NODE` or it can be `undefined`.
359
+ * The function returns the value of the _comparator property.
360
+ * @returns The `_comparator` property is being returned.
361
+ */
362
+ get comparator(): Comparator<K>;
363
+ /**
364
+ * The function sets the root of a tree-like structure and updates the parent property of the new
365
+ * root.
366
+ * @param {NODE | undefined} v - v is a parameter of type NODE or undefined.
377
367
  */
378
368
  protected _setRoot(v: NODE | undefined): void;
379
369
  }