avl-tree-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
@@ -50,27 +50,29 @@ exports.AVLTreeNode = AVLTreeNode;
50
50
  */
51
51
  class AVLTree extends bst_1.BST {
52
52
  /**
53
- * The constructor function initializes an AVLTree object with optional keysOrNodesOrEntries and options.
54
- * @param [keysOrNodesOrEntries] - The `keysOrNodesOrEntries` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, NODE>`
55
- * objects. It represents a collection of nodes that will be added to the AVL tree during
56
- * initialization.
57
- * @param [options] - The `options` parameter is an optional object that allows you to customize the
58
- * behavior of the AVL tree. It is of type `Partial<AVLTreeOptions>`, which means that you can
59
- * provide only a subset of the properties defined in the `AVLTreeOptions` interface.
53
+ * This is a constructor function for an AVLTree class that initializes the tree with keys, nodes,
54
+ * entries, or raw elements.
55
+ * @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
56
+ * iterable object that can contain either keys, nodes, entries, or raw elements. These elements will
57
+ * be used to initialize the AVLTree.
58
+ * @param [options] - The `options` parameter is an optional object that can be used to customize the
59
+ * behavior of the AVLTree. It can include properties such as `compareFn` (a function used to compare
60
+ * keys), `allowDuplicates` (a boolean indicating whether duplicate keys are allowed), and
61
+ * `nodeBuilder` (
60
62
  */
61
- constructor(keysOrNodesOrEntries = [], options) {
63
+ constructor(keysOrNodesOrEntriesOrRawElements = [], options) {
62
64
  super([], options);
63
- if (keysOrNodesOrEntries)
64
- super.addMany(keysOrNodesOrEntries);
65
+ if (keysOrNodesOrEntriesOrRawElements)
66
+ super.addMany(keysOrNodesOrEntriesOrRawElements);
65
67
  }
66
68
  /**
67
- * The function creates a new AVL tree node with the specified key and value.
68
- * @param {K} key - The key parameter is the key value that will be associated with
69
- * the new node. It is used to determine the position of the node in the binary search tree.
70
- * @param [value] - The parameter `value` is an optional value that can be assigned to the node. It is of
71
- * type `V`, which means it can be any value that is assignable to the `value` property of the
72
- * node type `NODE`.
73
- * @returns a new AVLTreeNode object with the specified key and value.
69
+ * The function creates a new AVL tree node with the given key and value.
70
+ * @param {K} key - The key parameter is of type K, which represents the key of the node being
71
+ * created.
72
+ * @param {V} [value] - The "value" parameter is an optional parameter of type V. It represents the
73
+ * value associated with the key in the node being created.
74
+ * @returns The method is returning a new instance of the AVLTreeNode class, casted as the generic
75
+ * type NODE.
74
76
  */
75
77
  createNode(key, value) {
76
78
  return new AVLTreeNode(key, value);
@@ -86,12 +88,14 @@ class AVLTree extends bst_1.BST {
86
88
  return new AVLTree([], Object.assign({ iterationType: this.iterationType, comparator: this.comparator }, options));
87
89
  }
88
90
  /**
89
- * The function checks if an keyOrNodeOrEntry is an instance of AVLTreeNode.
90
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`.
91
- * @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the AVLTreeNode class.
91
+ * The function checks if the input is an instance of AVLTreeNode.
92
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
93
+ * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
94
+ * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
95
+ * an instance of the `AVLTreeNode` class.
92
96
  */
93
- isNode(keyOrNodeOrEntry) {
94
- return keyOrNodeOrEntry instanceof AVLTreeNode;
97
+ isNode(keyOrNodeOrEntryOrRawElement) {
98
+ return keyOrNodeOrEntryOrRawElement instanceof AVLTreeNode;
95
99
  }
96
100
  /**
97
101
  * Time Complexity: O(log n)
@@ -102,20 +106,21 @@ class AVLTree extends bst_1.BST {
102
106
  * Time Complexity: O(log n)
103
107
  * Space Complexity: O(1)
104
108
  *
105
- * The function overrides the add method of a binary tree node and balances the tree after inserting
106
- * a new node.
107
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be either a key, a node, or an
108
- * entry.
109
- * @param {V} [value] - The `value` parameter represents the value associated with the key that is
110
- * being added to the binary tree.
111
- * @returns The method is returning either the inserted node or undefined.
109
+ * The function overrides the add method of a class and inserts a key-value pair into a data
110
+ * structure, then balances the path.
111
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
112
+ * `keyOrNodeOrEntryOrRawElement` can accept values of type `R`, `KeyOrNodeOrEntry<K, V, NODE>`, or
113
+ * `RawElement`.
114
+ * @param {V} [value] - The `value` parameter is an optional value that you want to associate with
115
+ * the key or node being added to the data structure.
116
+ * @returns The method is returning a boolean value.
112
117
  */
113
- add(keyOrNodeOrEntry, value) {
114
- if (keyOrNodeOrEntry === null)
118
+ add(keyOrNodeOrEntryOrRawElement, value) {
119
+ if (keyOrNodeOrEntryOrRawElement === null)
115
120
  return false;
116
- const inserted = super.add(keyOrNodeOrEntry, value);
121
+ const inserted = super.add(keyOrNodeOrEntryOrRawElement, value);
117
122
  if (inserted)
118
- this._balancePath(keyOrNodeOrEntry);
123
+ this._balancePath(keyOrNodeOrEntryOrRawElement);
119
124
  return inserted;
120
125
  }
121
126
  /**
@@ -126,16 +131,14 @@ class AVLTree extends bst_1.BST {
126
131
  * Time Complexity: O(log n)
127
132
  * Space Complexity: O(1)
128
133
  *
129
- * The function overrides the delete method of a binary tree, performs the deletion, and then
130
- * balances the tree if necessary.
134
+ * The function overrides the delete method of a binary tree class and performs additional operations
135
+ * to balance the tree after deletion.
131
136
  * @param identifier - The `identifier` parameter is the value or condition used to identify the
132
- * node(s) to be deleted from the binary tree. It can be of any type and is the return type of the
133
- * `callback` function.
134
- * @param {C} callback - The `callback` parameter is a function that will be called for each node
135
- * that is deleted from the binary tree. It is an optional parameter and if not provided, it will
136
- * default to the `_DEFAULT_CALLBACK` function. The `callback` function should have a single
137
- * parameter of type `NODE
138
- * @returns The method is returning an array of `BinaryTreeDeleteResult<NODE>`.
137
+ * node(s) to be deleted from the binary tree. It can be of any type that is compatible with the
138
+ * binary tree's node type.
139
+ * @param {C} callback - The `callback` parameter is a function that will be used to determine if a
140
+ * node should be deleted or not. It is optional and has a default value of `this._DEFAULT_CALLBACK`.
141
+ * @returns The method is returning an array of BinaryTreeDeleteResult<NODE> objects.
139
142
  */
140
143
  delete(identifier, callback = this._DEFAULT_CALLBACK) {
141
144
  const deletedResults = super.delete(identifier, callback);
@@ -147,14 +150,21 @@ class AVLTree extends bst_1.BST {
147
150
  return deletedResults;
148
151
  }
149
152
  /**
150
- * The `_swapProperties` function swaps the key, value, and height properties between two nodes in a binary
151
- * tree.
152
- * @param {K | NODE | undefined} srcNode - The `srcNode` parameter represents the source node that
153
- * needs to be swapped with the destination node. It can be of type `K`, `NODE`, or `undefined`.
154
- * @param {K | NODE | undefined} destNode - The `destNode` parameter represents the destination
155
- * node where the values from the source node will be swapped to.
156
- * @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined`
157
- * if either `srcNode` or `destNode` is undefined.
153
+ * Time Complexity: O(1)
154
+ * Space Complexity: O(1)
155
+ */
156
+ /**
157
+ * Time Complexity: O(1)
158
+ * Space Complexity: O(1)
159
+ *
160
+ * The `_swapProperties` function swaps the key, value, and height properties between two nodes in a
161
+ * binary search tree.
162
+ * @param {R | BSTNKeyOrNode<K, NODE>} srcNode - The `srcNode` parameter represents either a node
163
+ * object (`NODE`) or a key-value pair (`R`) that is being swapped with another node.
164
+ * @param {R | BSTNKeyOrNode<K, NODE>} destNode - The `destNode` parameter is either an instance of
165
+ * `R` or an instance of `BSTNKeyOrNode<K, NODE>`.
166
+ * @returns The method is returning the `destNodeEnsured` object if both `srcNodeEnsured` and
167
+ * `destNodeEnsured` are truthy. Otherwise, it returns `undefined`.
158
168
  */
159
169
  _swapProperties(srcNode, destNode) {
160
170
  const srcNodeEnsured = this.ensureNode(srcNode);
@@ -184,7 +194,8 @@ class AVLTree extends bst_1.BST {
184
194
  * Space Complexity: O(1)
185
195
  *
186
196
  * The function calculates the balance factor of a node in a binary tree.
187
- * @param {NODE} node - The parameter "node" represents a node in a binary tree data structure.
197
+ * @param {NODE} node - The parameter "node" is of type "NODE", which likely represents a node in a
198
+ * binary tree data structure.
188
199
  * @returns the balance factor of a given node. The balance factor is calculated by subtracting the
189
200
  * height of the left subtree from the height of the right subtree.
190
201
  */
@@ -230,7 +241,7 @@ class AVLTree extends bst_1.BST {
230
241
  * Time Complexity: O(1)
231
242
  * Space Complexity: O(1)
232
243
  *
233
- * The function `_balanceLL` performs a left-left rotation to balance a binary tree.
244
+ * The `_balanceLL` function performs a left-left rotation to balance a binary search tree.
234
245
  * @param {NODE} A - A is a node in a binary tree.
235
246
  */
236
247
  _balanceLL(A) {
@@ -428,8 +439,8 @@ class AVLTree extends bst_1.BST {
428
439
  *
429
440
  * The `_balancePath` function is used to update the heights of nodes and perform rotation operations
430
441
  * to restore balance in an AVL tree after inserting a node.
431
- * @param {NODE} node - The `node` parameter in the `_balancePath` function represents the node in the
432
- * AVL tree that needs to be balanced.
442
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} node - The `node` parameter can be of type `R` or
443
+ * `KeyOrNodeOrEntry<K, V, NODE>`.
433
444
  */
434
445
  _balancePath(node) {
435
446
  node = this.ensureNode(node);
@@ -472,13 +483,21 @@ class AVLTree extends bst_1.BST {
472
483
  }
473
484
  }
474
485
  /**
475
- * The function replaces an old node with a new node while preserving the height of the old node.
476
- * @param {NODE} oldNode - The `oldNode` parameter is the node that you want to replace with the
477
- * `newNode`.
486
+ * Time Complexity: O(1)
487
+ * Space Complexity: O(1)
488
+ */
489
+ /**
490
+ * Time Complexity: O(1)
491
+ * Space Complexity: O(1)
492
+ *
493
+ * The function replaces an old node with a new node and sets the height of the new node to be the
494
+ * same as the old node.
495
+ * @param {NODE} oldNode - The `oldNode` parameter represents the node that needs to be replaced in
496
+ * the data structure.
478
497
  * @param {NODE} newNode - The `newNode` parameter is the new node that will replace the `oldNode` in
479
498
  * the data structure.
480
- * @returns the result of calling the `_replaceNode` method on the superclass, passing in the
481
- * `oldNode` and `newNode` as arguments.
499
+ * @returns The method is returning the result of calling the `_replaceNode` method from the
500
+ * superclass, with the `oldNode` and `newNode` as arguments.
482
501
  */
483
502
  _replaceNode(oldNode, newNode) {
484
503
  newNode.height = oldNode.height;