avl-tree-typed 1.49.5 → 1.49.7

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 (100) hide show
  1. package/dist/data-structures/binary-tree/avl-tree.d.ts +53 -48
  2. package/dist/data-structures/binary-tree/avl-tree.js +55 -49
  3. package/dist/data-structures/binary-tree/binary-tree.d.ts +153 -130
  4. package/dist/data-structures/binary-tree/binary-tree.js +194 -153
  5. package/dist/data-structures/binary-tree/bst.d.ts +83 -71
  6. package/dist/data-structures/binary-tree/bst.js +114 -91
  7. package/dist/data-structures/binary-tree/rb-tree.d.ts +37 -35
  8. package/dist/data-structures/binary-tree/rb-tree.js +62 -59
  9. package/dist/data-structures/binary-tree/tree-multimap.d.ts +46 -39
  10. package/dist/data-structures/binary-tree/tree-multimap.js +58 -51
  11. package/dist/data-structures/hash/hash-map.d.ts +24 -27
  12. package/dist/data-structures/hash/hash-map.js +35 -35
  13. package/dist/data-structures/hash/index.d.ts +0 -1
  14. package/dist/data-structures/hash/index.js +0 -1
  15. package/dist/data-structures/heap/heap.d.ts +2 -1
  16. package/dist/data-structures/heap/heap.js +13 -13
  17. package/dist/data-structures/heap/max-heap.js +1 -1
  18. package/dist/data-structures/heap/min-heap.js +1 -1
  19. package/dist/data-structures/linked-list/doubly-linked-list.js +1 -1
  20. package/dist/data-structures/linked-list/singly-linked-list.js +1 -3
  21. package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -8
  22. package/dist/data-structures/linked-list/skip-linked-list.js +15 -18
  23. package/dist/data-structures/matrix/matrix.d.ts +2 -7
  24. package/dist/data-structures/matrix/matrix.js +0 -7
  25. package/dist/data-structures/priority-queue/max-priority-queue.js +1 -1
  26. package/dist/data-structures/priority-queue/min-priority-queue.js +1 -1
  27. package/dist/data-structures/priority-queue/priority-queue.js +1 -1
  28. package/dist/data-structures/queue/deque.d.ts +2 -11
  29. package/dist/data-structures/queue/deque.js +9 -13
  30. package/dist/data-structures/queue/queue.d.ts +13 -13
  31. package/dist/data-structures/queue/queue.js +29 -25
  32. package/dist/data-structures/stack/stack.js +2 -3
  33. package/dist/data-structures/trie/trie.d.ts +2 -2
  34. package/dist/data-structures/trie/trie.js +9 -5
  35. package/dist/interfaces/binary-tree.d.ts +3 -3
  36. package/dist/types/common.d.ts +3 -3
  37. package/dist/types/common.js +2 -2
  38. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +2 -2
  39. package/dist/types/data-structures/binary-tree/bst.d.ts +1 -1
  40. package/dist/types/data-structures/binary-tree/tree-multimap.d.ts +1 -1
  41. package/dist/types/data-structures/hash/hash-map.d.ts +5 -2
  42. package/dist/types/data-structures/hash/index.d.ts +0 -1
  43. package/dist/types/data-structures/hash/index.js +0 -1
  44. package/dist/types/data-structures/heap/heap.d.ts +1 -1
  45. package/dist/types/data-structures/linked-list/index.d.ts +1 -0
  46. package/dist/types/data-structures/linked-list/index.js +1 -0
  47. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +4 -1
  48. package/dist/types/data-structures/matrix/index.d.ts +1 -0
  49. package/dist/types/data-structures/matrix/index.js +1 -0
  50. package/dist/types/data-structures/matrix/matrix.d.ts +7 -1
  51. package/dist/types/data-structures/queue/deque.d.ts +3 -1
  52. package/dist/types/data-structures/trie/trie.d.ts +3 -1
  53. package/package.json +2 -2
  54. package/src/data-structures/binary-tree/avl-tree.ts +58 -53
  55. package/src/data-structures/binary-tree/binary-tree.ts +255 -211
  56. package/src/data-structures/binary-tree/bst.ts +126 -107
  57. package/src/data-structures/binary-tree/rb-tree.ts +66 -64
  58. package/src/data-structures/binary-tree/tree-multimap.ts +62 -56
  59. package/src/data-structures/hash/hash-map.ts +46 -50
  60. package/src/data-structures/hash/index.ts +0 -1
  61. package/src/data-structures/heap/heap.ts +20 -19
  62. package/src/data-structures/heap/max-heap.ts +1 -1
  63. package/src/data-structures/heap/min-heap.ts +1 -1
  64. package/src/data-structures/linked-list/doubly-linked-list.ts +1 -1
  65. package/src/data-structures/linked-list/singly-linked-list.ts +2 -5
  66. package/src/data-structures/linked-list/skip-linked-list.ts +15 -16
  67. package/src/data-structures/matrix/matrix.ts +2 -10
  68. package/src/data-structures/priority-queue/max-priority-queue.ts +1 -1
  69. package/src/data-structures/priority-queue/min-priority-queue.ts +1 -1
  70. package/src/data-structures/priority-queue/priority-queue.ts +1 -1
  71. package/src/data-structures/queue/deque.ts +11 -15
  72. package/src/data-structures/queue/queue.ts +29 -28
  73. package/src/data-structures/stack/stack.ts +3 -6
  74. package/src/data-structures/trie/trie.ts +10 -11
  75. package/src/interfaces/binary-tree.ts +3 -3
  76. package/src/types/common.ts +3 -3
  77. package/src/types/data-structures/binary-tree/binary-tree.ts +2 -2
  78. package/src/types/data-structures/binary-tree/bst.ts +1 -1
  79. package/src/types/data-structures/binary-tree/tree-multimap.ts +1 -1
  80. package/src/types/data-structures/hash/hash-map.ts +6 -2
  81. package/src/types/data-structures/hash/index.ts +0 -1
  82. package/src/types/data-structures/heap/heap.ts +1 -1
  83. package/src/types/data-structures/linked-list/index.ts +1 -0
  84. package/src/types/data-structures/linked-list/skip-linked-list.ts +1 -1
  85. package/src/types/data-structures/matrix/index.ts +1 -0
  86. package/src/types/data-structures/matrix/matrix.ts +7 -1
  87. package/src/types/data-structures/queue/deque.ts +1 -1
  88. package/src/types/data-structures/trie/trie.ts +1 -1
  89. package/dist/data-structures/hash/hash-table.d.ts +0 -108
  90. package/dist/data-structures/hash/hash-table.js +0 -281
  91. package/dist/types/data-structures/hash/hash-table.d.ts +0 -1
  92. package/dist/types/data-structures/hash/hash-table.js +0 -2
  93. package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -1
  94. package/dist/types/data-structures/matrix/matrix2d.js +0 -2
  95. package/dist/types/data-structures/matrix/vector2d.d.ts +0 -1
  96. package/dist/types/data-structures/matrix/vector2d.js +0 -2
  97. package/src/data-structures/hash/hash-table.ts +0 -318
  98. package/src/types/data-structures/hash/hash-table.ts +0 -1
  99. package/src/types/data-structures/matrix/matrix2d.ts +0 -1
  100. package/src/types/data-structures/matrix/vector2d.ts +0 -1
@@ -1 +1,2 @@
1
1
  export * from './navigator';
2
+ export * from './matrix';
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./navigator"), exports);
18
+ __exportStar(require("./matrix"), exports);
@@ -1 +1,7 @@
1
- export {};
1
+ export type MatrixOptions = {
2
+ rows?: number;
3
+ cols?: number;
4
+ addFn?: (a: number, b: number) => any;
5
+ subtractFn?: (a: number, b: number) => any;
6
+ multiplyFn?: (a: number, b: number) => any;
7
+ };
@@ -1 +1,3 @@
1
- export {};
1
+ export type DequeOptions = {
2
+ bucketSize?: number;
3
+ };
@@ -1 +1,3 @@
1
- export {};
1
+ export type TrieOptions = {
2
+ caseSensitive?: boolean;
3
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "avl-tree-typed",
3
- "version": "1.49.5",
3
+ "version": "1.49.7",
4
4
  "description": "AVLTree(Adelson-Velsky and Landis Tree). Javascript & Typescript Data Structure.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -163,6 +163,6 @@
163
163
  "typescript": "^4.9.5"
164
164
  },
165
165
  "dependencies": {
166
- "data-structure-typed": "^1.49.5"
166
+ "data-structure-typed": "^1.49.7"
167
167
  }
168
168
  }
@@ -13,8 +13,7 @@ import type {
13
13
  BinaryTreeDeleteResult,
14
14
  BSTNKeyOrNode,
15
15
  BTNCallback,
16
- BTNExemplar,
17
- BTNKeyOrNode
16
+ KeyOrNodeOrEntry
18
17
  } from '../../types';
19
18
  import { IBinaryTree } from '../../interfaces';
20
19
 
@@ -49,17 +48,17 @@ export class AVLTree<
49
48
  extends BST<K, V, N, TREE>
50
49
  implements IBinaryTree<K, V, N, TREE> {
51
50
  /**
52
- * The constructor function initializes an AVLTree object with optional elements and options.
53
- * @param [elements] - The `elements` parameter is an optional iterable of `BTNExemplar<K, V, N>`
54
- * objects. It represents a collection of elements that will be added to the AVL tree during
51
+ * The constructor function initializes an AVLTree object with optional keysOrNodesOrEntries and options.
52
+ * @param [keysOrNodesOrEntries] - The `keysOrNodesOrEntries` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, N>`
53
+ * objects. It represents a collection of nodes that will be added to the AVL tree during
55
54
  * initialization.
56
55
  * @param [options] - The `options` parameter is an optional object that allows you to customize the
57
56
  * behavior of the AVL tree. It is of type `Partial<AVLTreeOptions>`, which means that you can
58
57
  * provide only a subset of the properties defined in the `AVLTreeOptions` interface.
59
58
  */
60
- constructor(elements?: Iterable<BTNExemplar<K, V, N>>, options?: Partial<AVLTreeOptions<K>>) {
59
+ constructor(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, N>> = [], options?: AVLTreeOptions<K>) {
61
60
  super([], options);
62
- if (elements) super.addMany(elements);
61
+ if (keysOrNodesOrEntries) super.addMany(keysOrNodesOrEntries);
63
62
  }
64
63
 
65
64
  /**
@@ -91,12 +90,12 @@ export class AVLTree<
91
90
  }
92
91
 
93
92
  /**
94
- * The function checks if an exemplar is an instance of AVLTreeNode.
95
- * @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`.
96
- * @returns a boolean value indicating whether the exemplar is an instance of the AVLTreeNode class.
93
+ * The function checks if an keyOrNodeOrEntry is an instance of AVLTreeNode.
94
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`.
95
+ * @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the AVLTreeNode class.
97
96
  */
98
- override isNode(exemplar: BTNExemplar<K, V, N>): exemplar is N {
99
- return exemplar instanceof AVLTreeNode;
97
+ override isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>): keyOrNodeOrEntry is N {
98
+ return keyOrNodeOrEntry instanceof AVLTreeNode;
100
99
  }
101
100
 
102
101
  /**
@@ -105,18 +104,19 @@ export class AVLTree<
105
104
  * data type.
106
105
  * @returns a boolean value indicating whether the potentialKey is of type number or not.
107
106
  */
108
- override isNotNodeInstance(potentialKey: BTNKeyOrNode<K, N>): potentialKey is K {
107
+ override isNotNodeInstance(potentialKey: KeyOrNodeOrEntry<K, V, N>): potentialKey is K {
109
108
  return !(potentialKey instanceof AVLTreeNode);
110
109
  }
111
110
 
112
111
  /**
113
- * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
114
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
112
+ * Time Complexity: O(log n)
113
+ * Space Complexity: O(1)
114
+ * logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity. constant space, as it doesn't use additional data structures that scale with input size.
115
115
  */
116
116
 
117
117
  /**
118
- * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
119
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
118
+ * Time Complexity: O(log n)
119
+ * Space Complexity: O(1)
120
120
  *
121
121
  * The function overrides the add method of a binary tree node and balances the tree after inserting
122
122
  * a new node.
@@ -126,21 +126,21 @@ export class AVLTree<
126
126
  * being added to the binary tree.
127
127
  * @returns The method is returning either the inserted node or undefined.
128
128
  */
129
- override add(keyOrNodeOrEntry: BTNExemplar<K, V, N>, value?: V): N | undefined {
130
- if (keyOrNodeOrEntry === null) return undefined;
129
+ override add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V): boolean {
130
+ if (keyOrNodeOrEntry === null) return false;
131
131
  const inserted = super.add(keyOrNodeOrEntry, value);
132
- if (inserted) this._balancePath(inserted);
132
+ if (inserted) this._balancePath(keyOrNodeOrEntry);
133
133
  return inserted;
134
134
  }
135
135
 
136
136
  /**
137
- * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
138
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
137
+ * Time Complexity: O(log n)
138
+ * Space Complexity: O(1)
139
139
  */
140
140
 
141
141
  /**
142
- * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The delete method of the superclass (BST) has logarithmic time complexity.
143
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
142
+ * Time Complexity: O(log n)
143
+ * Space Complexity: O(1)
144
144
  *
145
145
  * The function overrides the delete method of a binary tree, performs the deletion, and then
146
146
  * balances the tree if necessary.
@@ -203,13 +203,14 @@ export class AVLTree<
203
203
  }
204
204
 
205
205
  /**
206
- * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
207
- * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
206
+ * Time Complexity: O(1)
207
+ * Space Complexity: O(1)
208
+ * constant time, as it performs a fixed number of operations. constant space, as it only uses a constant amount of memory.
208
209
  */
209
210
 
210
211
  /**
211
- * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
212
- * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
212
+ * Time Complexity: O(1)
213
+ * Space Complexity: O(1)
213
214
  *
214
215
  * The function calculates the balance factor of a node in a binary tree.
215
216
  * @param {N} node - The parameter "node" represents a node in a binary tree data structure.
@@ -227,13 +228,14 @@ export class AVLTree<
227
228
  }
228
229
 
229
230
  /**
230
- * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
231
- * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
231
+ * Time Complexity: O(1)
232
+ * Space Complexity: O(1)
233
+ * constant time, as it performs a fixed number of operations. constant space, as it only uses a constant amount of memory.
232
234
  */
233
235
 
234
236
  /**
235
- * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
236
- * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
237
+ * Time Complexity: O(1)
238
+ * Space Complexity: O(1)
237
239
  *
238
240
  * The function updates the height of a node in a binary tree based on the heights of its left and
239
241
  * right children.
@@ -249,20 +251,22 @@ export class AVLTree<
249
251
  }
250
252
 
251
253
  /**
252
- * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The method traverses the path from the inserted node to the root.
253
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
254
+ * Time Complexity: O(log n)
255
+ * Space Complexity: O(1)
256
+ * logarithmic time, where "n" is the number of nodes in the tree. The method traverses the path from the inserted node to the root. constant space, as it doesn't use additional data structures that scale with input size.
254
257
  */
255
258
 
256
259
  /**
257
- * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The method traverses the path from the inserted node to the root.
258
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
260
+ * Time Complexity: O(log n)
261
+ * Space Complexity: O(1)
259
262
  *
260
263
  * The `_balancePath` function is used to update the heights of nodes and perform rotation operations
261
264
  * to restore balance in an AVL tree after inserting a node.
262
265
  * @param {N} node - The `node` parameter in the `_balancePath` function represents the node in the
263
266
  * AVL tree that needs to be balanced.
264
267
  */
265
- protected _balancePath(node: N): void {
268
+ protected _balancePath(node: KeyOrNodeOrEntry<K, V, N>): void {
269
+ node = this.ensureNode(node);
266
270
  const path = this.getPathToRoot(node, false); // first O(log n) + O(log n)
267
271
  for (let i = 0; i < path.length; i++) {
268
272
  // second O(log n)
@@ -302,13 +306,14 @@ export class AVLTree<
302
306
  }
303
307
 
304
308
  /**
305
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
306
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
309
+ * Time Complexity: O(1)
310
+ * Space Complexity: O(1)
311
+ * constant time, as these methods perform a fixed number of operations. constant space, as they only use a constant amount of memory.
307
312
  */
308
313
 
309
314
  /**
310
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
311
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
315
+ * Time Complexity: O(1)
316
+ * Space Complexity: O(1)
312
317
  *
313
318
  * The function `_balanceLL` performs a left-left rotation to balance a binary tree.
314
319
  * @param {N} A - A is a node in a binary tree.
@@ -340,13 +345,13 @@ export class AVLTree<
340
345
  }
341
346
 
342
347
  /**
343
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
344
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
348
+ * Time Complexity: O(1)
349
+ * Space Complexity: O(1)
345
350
  */
346
351
 
347
352
  /**
348
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
349
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
353
+ * Time Complexity: O(1)
354
+ * Space Complexity: O(1)
350
355
  *
351
356
  * The `_balanceLR` function performs a left-right rotation to balance a binary tree.
352
357
  * @param {N} A - A is a node in a binary tree.
@@ -396,13 +401,13 @@ export class AVLTree<
396
401
  }
397
402
 
398
403
  /**
399
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
400
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
404
+ * Time Complexity: O(1)
405
+ * Space Complexity: O(1)
401
406
  */
402
407
 
403
408
  /**
404
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
405
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
409
+ * Time Complexity: O(1)
410
+ * Space Complexity: O(1)
406
411
  *
407
412
  * The function `_balanceRR` performs a right-right rotation to balance a binary tree.
408
413
  * @param {N} A - A is a node in a binary tree.
@@ -439,13 +444,13 @@ export class AVLTree<
439
444
  }
440
445
 
441
446
  /**
442
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
443
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
447
+ * Time Complexity: O(1)
448
+ * Space Complexity: O(1)
444
449
  */
445
450
 
446
451
  /**
447
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
448
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
452
+ * Time Complexity: O(1)
453
+ * Space Complexity: O(1)
449
454
  *
450
455
  * The function `_balanceRL` performs a right-left rotation to balance a binary tree.
451
456
  * @param {N} A - A is a node in a binary tree.