min-heap-typed 1.50.2 → 1.50.4

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 (92) hide show
  1. package/dist/data-structures/base/iterable-base.d.ts +6 -0
  2. package/dist/data-structures/binary-tree/{tree-multimap.d.ts → avl-tree-multi-map.d.ts} +43 -10
  3. package/dist/data-structures/binary-tree/{tree-multimap.js → avl-tree-multi-map.js} +49 -11
  4. package/dist/data-structures/binary-tree/avl-tree.d.ts +29 -1
  5. package/dist/data-structures/binary-tree/avl-tree.js +33 -1
  6. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +22 -0
  7. package/dist/data-structures/binary-tree/binary-indexed-tree.js +22 -0
  8. package/dist/data-structures/binary-tree/binary-tree.d.ts +1 -1
  9. package/dist/data-structures/binary-tree/binary-tree.js +1 -1
  10. package/dist/data-structures/binary-tree/bst.d.ts +46 -13
  11. package/dist/data-structures/binary-tree/bst.js +51 -20
  12. package/dist/data-structures/binary-tree/index.d.ts +2 -1
  13. package/dist/data-structures/binary-tree/index.js +2 -1
  14. package/dist/data-structures/binary-tree/rb-tree.d.ts +54 -2
  15. package/dist/data-structures/binary-tree/rb-tree.js +90 -24
  16. package/dist/data-structures/binary-tree/segment-tree.d.ts +99 -6
  17. package/dist/data-structures/binary-tree/segment-tree.js +127 -10
  18. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +200 -0
  19. package/dist/data-structures/binary-tree/tree-multi-map.js +399 -0
  20. package/dist/data-structures/graph/abstract-graph.d.ts +0 -78
  21. package/dist/data-structures/graph/abstract-graph.js +0 -189
  22. package/dist/data-structures/graph/directed-graph.d.ts +59 -0
  23. package/dist/data-structures/graph/directed-graph.js +105 -0
  24. package/dist/data-structures/graph/undirected-graph.d.ts +60 -7
  25. package/dist/data-structures/graph/undirected-graph.js +126 -18
  26. package/dist/data-structures/hash/hash-map.d.ts +143 -23
  27. package/dist/data-structures/hash/hash-map.js +196 -62
  28. package/dist/data-structures/heap/heap.d.ts +29 -19
  29. package/dist/data-structures/heap/heap.js +29 -20
  30. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +71 -25
  31. package/dist/data-structures/linked-list/doubly-linked-list.js +83 -25
  32. package/dist/data-structures/linked-list/singly-linked-list.d.ts +26 -3
  33. package/dist/data-structures/linked-list/singly-linked-list.js +34 -3
  34. package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -2
  35. package/dist/data-structures/linked-list/skip-linked-list.js +2 -2
  36. package/dist/data-structures/matrix/matrix.d.ts +1 -1
  37. package/dist/data-structures/matrix/matrix.js +1 -1
  38. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +10 -0
  39. package/dist/data-structures/priority-queue/max-priority-queue.js +10 -0
  40. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -0
  41. package/dist/data-structures/priority-queue/min-priority-queue.js +11 -0
  42. package/dist/data-structures/priority-queue/priority-queue.d.ts +8 -0
  43. package/dist/data-structures/priority-queue/priority-queue.js +8 -0
  44. package/dist/data-structures/queue/deque.d.ts +95 -21
  45. package/dist/data-structures/queue/deque.js +100 -16
  46. package/dist/data-structures/queue/queue.d.ts +65 -45
  47. package/dist/data-structures/queue/queue.js +65 -45
  48. package/dist/data-structures/stack/stack.d.ts +36 -22
  49. package/dist/data-structures/stack/stack.js +36 -22
  50. package/dist/data-structures/tree/tree.d.ts +57 -3
  51. package/dist/data-structures/tree/tree.js +77 -11
  52. package/dist/data-structures/trie/trie.d.ts +100 -36
  53. package/dist/data-structures/trie/trie.js +115 -36
  54. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +5 -0
  55. package/dist/types/data-structures/binary-tree/index.d.ts +2 -1
  56. package/dist/types/data-structures/binary-tree/index.js +2 -1
  57. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +5 -0
  58. package/dist/types/data-structures/binary-tree/tree-multi-map.js +2 -0
  59. package/package.json +2 -2
  60. package/src/data-structures/base/iterable-base.ts +12 -0
  61. package/src/data-structures/binary-tree/{tree-multimap.ts → avl-tree-multi-map.ts} +59 -20
  62. package/src/data-structures/binary-tree/avl-tree.ts +37 -3
  63. package/src/data-structures/binary-tree/binary-indexed-tree.ts +22 -0
  64. package/src/data-structures/binary-tree/binary-tree.ts +1 -1
  65. package/src/data-structures/binary-tree/bst.ts +51 -19
  66. package/src/data-structures/binary-tree/index.ts +2 -1
  67. package/src/data-structures/binary-tree/rb-tree.ts +99 -28
  68. package/src/data-structures/binary-tree/segment-tree.ts +145 -11
  69. package/src/data-structures/binary-tree/tree-multi-map.ts +463 -0
  70. package/src/data-structures/graph/abstract-graph.ts +0 -211
  71. package/src/data-structures/graph/directed-graph.ts +122 -0
  72. package/src/data-structures/graph/undirected-graph.ts +143 -19
  73. package/src/data-structures/hash/hash-map.ts +228 -76
  74. package/src/data-structures/heap/heap.ts +31 -20
  75. package/src/data-structures/linked-list/doubly-linked-list.ts +96 -29
  76. package/src/data-structures/linked-list/singly-linked-list.ts +42 -6
  77. package/src/data-structures/linked-list/skip-linked-list.ts +2 -2
  78. package/src/data-structures/matrix/matrix.ts +1 -1
  79. package/src/data-structures/priority-queue/max-priority-queue.ts +10 -0
  80. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -0
  81. package/src/data-structures/priority-queue/priority-queue.ts +8 -0
  82. package/src/data-structures/queue/deque.ts +118 -22
  83. package/src/data-structures/queue/queue.ts +68 -45
  84. package/src/data-structures/stack/stack.ts +39 -23
  85. package/src/data-structures/tree/tree.ts +89 -15
  86. package/src/data-structures/trie/trie.ts +131 -40
  87. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +8 -0
  88. package/src/types/data-structures/binary-tree/index.ts +2 -1
  89. package/src/types/data-structures/binary-tree/tree-multi-map.ts +8 -0
  90. package/dist/types/data-structures/binary-tree/tree-multimap.d.ts +0 -5
  91. package/src/types/data-structures/binary-tree/tree-multimap.ts +0 -8
  92. /package/dist/types/data-structures/binary-tree/{tree-multimap.js → avl-tree-multi-map.js} +0 -0
@@ -8,9 +8,57 @@ const base_1 = require("../base");
8
8
  */
9
9
  class TrieNode {
10
10
  constructor(key) {
11
- this.key = key;
12
- this.isEnd = false;
13
- this.children = new Map();
11
+ this._key = key;
12
+ this._isEnd = false;
13
+ this._children = new Map();
14
+ }
15
+ /**
16
+ * The function returns the value of the protected variable _key.
17
+ * @returns The value of the `_key` property, which is a string.
18
+ */
19
+ get key() {
20
+ return this._key;
21
+ }
22
+ /**
23
+ * The above function sets the value of a protected variable called "key".
24
+ * @param {string} value - The value parameter is a string that represents the value to be assigned
25
+ * to the key.
26
+ */
27
+ set key(value) {
28
+ this._key = value;
29
+ }
30
+ /**
31
+ * The function returns the children of a TrieNode as a Map.
32
+ * @returns The `children` property of the TrieNode object, which is a Map containing string keys and
33
+ * TrieNode values.
34
+ */
35
+ get children() {
36
+ return this._children;
37
+ }
38
+ /**
39
+ * The function sets the value of the `_children` property of a TrieNode object.
40
+ * @param value - The value parameter is a Map object that represents the children of a TrieNode. The
41
+ * keys of the map are strings, which represent the characters that are associated with each child
42
+ * TrieNode. The values of the map are TrieNode objects, which represent the child nodes of the
43
+ * current TrieNode.
44
+ */
45
+ set children(value) {
46
+ this._children = value;
47
+ }
48
+ /**
49
+ * The function returns a boolean value indicating whether a certain condition is met.
50
+ * @returns The method is returning a boolean value, specifically the value of the variable `_isEnd`.
51
+ */
52
+ get isEnd() {
53
+ return this._isEnd;
54
+ }
55
+ /**
56
+ * The function sets the value of the "_isEnd" property.
57
+ * @param {boolean} value - The value parameter is a boolean value that indicates whether the current
58
+ * state is the end state or not.
59
+ */
60
+ set isEnd(value) {
61
+ this._isEnd = value;
14
62
  }
15
63
  }
16
64
  exports.TrieNode = TrieNode;
@@ -57,9 +105,8 @@ class Trie extends base_1.IterableElementBase {
57
105
  return this._size;
58
106
  }
59
107
  /**
60
- * The caseSensitive function is a getter that returns the value of the private _caseSensitive property.
61
- *
62
- * @return The value of the _casesensitive private variable
108
+ * The caseSensitive function is a getter that returns the value of the protected _caseSensitive property.
109
+ * @return The value of the _caseSensitive protected variable
63
110
  */
64
111
  get caseSensitive() {
65
112
  return this._caseSensitive;
@@ -72,12 +119,12 @@ class Trie extends base_1.IterableElementBase {
72
119
  return this._root;
73
120
  }
74
121
  /**
75
- * Time Complexity: O(M), where M is the length of the word being added.
76
- * Space Complexity: O(M) - Each character in the word adds a TrieNode.
122
+ * Time Complexity: O(l), where l is the length of the word being added.
123
+ * Space Complexity: O(l) - Each character in the word adds a TrieNode.
77
124
  */
78
125
  /**
79
- * Time Complexity: O(M), where M is the length of the word being added.
80
- * Space Complexity: O(M) - Each character in the word adds a TrieNode.
126
+ * Time Complexity: O(l), where l is the length of the word being added.
127
+ * Space Complexity: O(l) - Each character in the word adds a TrieNode.
81
128
  *
82
129
  * Add a word to the Trie structure.
83
130
  * @param {string} word - The word to add.
@@ -103,11 +150,11 @@ class Trie extends base_1.IterableElementBase {
103
150
  return isNewWord;
104
151
  }
105
152
  /**
106
- * Time Complexity: O(M), where M is the length of the input word.
153
+ * Time Complexity: O(l), where l is the length of the input word.
107
154
  * Space Complexity: O(1) - Constant space.
108
155
  */
109
156
  /**
110
- * Time Complexity: O(M), where M is the length of the input word.
157
+ * Time Complexity: O(l), where l is the length of the input word.
111
158
  * Space Complexity: O(1) - Constant space.
112
159
  *
113
160
  * Check if the Trie contains a given word.
@@ -126,6 +173,13 @@ class Trie extends base_1.IterableElementBase {
126
173
  return cur.isEnd;
127
174
  }
128
175
  /**
176
+ * Time Complexity: O(1)
177
+ * Space Complexity: O(1)
178
+ */
179
+ /**
180
+ * Time Complexity: O(1)
181
+ * Space Complexity: O(1)
182
+ *
129
183
  * The isEmpty function checks if the size of the queue is 0.
130
184
  * @return True if the size of the queue is 0
131
185
  */
@@ -133,12 +187,26 @@ class Trie extends base_1.IterableElementBase {
133
187
  return this.size === 0;
134
188
  }
135
189
  /**
136
- * Time Complexity: O(M), where M is the length of the word being deleted.
137
- * Space Complexity: O(M) - Due to the recursive DFS approach.
190
+ * Time Complexity: O(1)
191
+ * Space Complexity: O(1)
192
+ */
193
+ /**
194
+ * Time Complexity: O(1)
195
+ * Space Complexity: O(1)
196
+ *
197
+ * The clear function resets the size of the Trie to 0 and creates a new root TrieNode.
198
+ */
199
+ clear() {
200
+ this._size = 0;
201
+ this._root = new TrieNode('');
202
+ }
203
+ /**
204
+ * Time Complexity: O(l), where l is the length of the word being deleted.
205
+ * Space Complexity: O(n) - Due to the recursive DFS approach.
138
206
  */
139
207
  /**
140
- * Time Complexity: O(M), where M is the length of the word being deleted.
141
- * Space Complexity: O(M) - Due to the recursive DFS approach.
208
+ * Time Complexity: O(l), where l is the length of the word being deleted.
209
+ * Space Complexity: O(n) - Due to the recursive DFS approach.
142
210
  *
143
211
  * Remove a word from the Trie structure.
144
212
  * @param{string} word - The word to delete.
@@ -180,11 +248,11 @@ class Trie extends base_1.IterableElementBase {
180
248
  return isDeleted;
181
249
  }
182
250
  /**
183
- * Time Complexity: O(N), where N is the total number of nodes in the trie.
251
+ * Time Complexity: O(n), where n is the total number of nodes in the trie.
184
252
  * Space Complexity: O(1) - Constant space.
185
253
  */
186
254
  /**
187
- * Time Complexity: O(N), where N is the total number of nodes in the trie.
255
+ * Time Complexity: O(n), where n is the total number of nodes in the trie.
188
256
  * Space Complexity: O(1) - Constant space.
189
257
  *
190
258
  */
@@ -208,11 +276,11 @@ class Trie extends base_1.IterableElementBase {
208
276
  return maxDepth;
209
277
  }
210
278
  /**
211
- * Time Complexity: O(M), where M is the length of the input prefix.
279
+ * Time Complexity: O(l), where l is the length of the input prefix.
212
280
  * Space Complexity: O(1) - Constant space.
213
281
  */
214
282
  /**
215
- * Time Complexity: O(M), where M is the length of the input prefix.
283
+ * Time Complexity: O(l), where l is the length of the input prefix.
216
284
  * Space Complexity: O(1) - Constant space.
217
285
  *
218
286
  * Check if a given input string has an absolute prefix in the Trie, meaning it's not a complete word.
@@ -231,11 +299,11 @@ class Trie extends base_1.IterableElementBase {
231
299
  return !cur.isEnd;
232
300
  }
233
301
  /**
234
- * Time Complexity: O(M), where M is the length of the input prefix.
302
+ * Time Complexity: O(l), where l is the length of the input prefix.
235
303
  * Space Complexity: O(1) - Constant space.
236
304
  */
237
305
  /**
238
- * Time Complexity: O(M), where M is the length of the input prefix.
306
+ * Time Complexity: O(l), where l is the length of the input prefix.
239
307
  * Space Complexity: O(1) - Constant space.
240
308
  *
241
309
  * Check if a given input string is a prefix of any existing word in the Trie, whether as an absolute prefix or a complete word.
@@ -254,12 +322,12 @@ class Trie extends base_1.IterableElementBase {
254
322
  return true;
255
323
  }
256
324
  /**
257
- * Time Complexity: O(N), where N is the total number of nodes in the trie.
258
- * Space Complexity: O(M), where M is the length of the input prefix.
325
+ * Time Complexity: O(n), where n is the total number of nodes in the trie.
326
+ * Space Complexity: O(l), where l is the length of the input prefix.
259
327
  */
260
328
  /**
261
- * Time Complexity: O(N), where N is the total number of nodes in the trie.
262
- * Space Complexity: O(M), where M is the length of the input prefix.
329
+ * Time Complexity: O(n), where n is the total number of nodes in the trie.
330
+ * Space Complexity: O(l), where l is the length of the input prefix.
263
331
  *
264
332
  * Check if the input string is a common prefix in the Trie, meaning it's a prefix shared by all words in the Trie.
265
333
  * @param {string} input - The input string representing the common prefix to check for.
@@ -283,12 +351,12 @@ class Trie extends base_1.IterableElementBase {
283
351
  return commonPre === input;
284
352
  }
285
353
  /**
286
- * Time Complexity: O(N), where N is the total number of nodes in the trie.
287
- * Space Complexity: O(M), where M is the length of the longest common prefix.
354
+ * Time Complexity: O(n), where n is the total number of nodes in the trie.
355
+ * Space Complexity: O(l), where l is the length of the longest common prefix.
288
356
  */
289
357
  /**
290
- * Time Complexity: O(N), where N is the total number of nodes in the trie.
291
- * Space Complexity: O(M), where M is the length of the longest common prefix.
358
+ * Time Complexity: O(n), where n is the total number of nodes in the trie.
359
+ * Space Complexity: O(l), where l is the length of the longest common prefix.
292
360
  *
293
361
  * Get the longest common prefix among all the words stored in the Trie.
294
362
  * @returns {string} The longest common prefix found in the Trie.
@@ -308,12 +376,12 @@ class Trie extends base_1.IterableElementBase {
308
376
  return commonPre;
309
377
  }
310
378
  /**
311
- * Time Complexity: O(K * L), where K is the number of words retrieved, and L is the average length of the words.
312
- * Space Complexity: O(K * L) - The space required for the output array.
379
+ * Time Complexity: O(w * l), where w is the number of words retrieved, and l is the average length of the words.
380
+ * Space Complexity: O(w * l) - The space required for the output array.
313
381
  */
314
382
  /**
315
- * Time Complexity: O(K * L), where K is the number of words retrieved, and L is the average length of the words.
316
- * Space Complexity: O(K * L) - The space required for the output array.
383
+ * Time Complexity: O(w * l), where w is the number of words retrieved, and l is the average length of the words.
384
+ * Space Complexity: O(w * l) - The space required for the output array.
317
385
  *
318
386
  * The `getAll` function returns an array of all words in a Trie data structure that start with a given prefix.
319
387
  * @param {string} prefix - The `prefix` parameter is a string that represents the prefix that we want to search for in the
@@ -422,6 +490,17 @@ class Trie extends base_1.IterableElementBase {
422
490
  }
423
491
  return newTrie;
424
492
  }
493
+ /**
494
+ * Time Complexity: O(n)
495
+ * Space Complexity: O(n)
496
+ */
497
+ /**
498
+ * Time Complexity: O(n)
499
+ * Space Complexity: O(n)
500
+ *
501
+ * The function `_getIterator` returns an iterable iterator that performs a depth-first search on a
502
+ * trie data structure and yields all the paths to the end nodes.
503
+ */
425
504
  *_getIterator() {
426
505
  function* _dfs(node, path) {
427
506
  if (node.isEnd) {
@@ -434,11 +513,11 @@ class Trie extends base_1.IterableElementBase {
434
513
  yield* _dfs(this.root, '');
435
514
  }
436
515
  /**
437
- * Time Complexity: O(M), where M is the length of the input string.
516
+ * Time Complexity: O(l), where l is the length of the input string.
438
517
  * Space Complexity: O(1) - Constant space.
439
518
  */
440
519
  /**
441
- * Time Complexity: O(M), where M is the length of the input string.
520
+ * Time Complexity: O(l), where l is the length of the input string.
442
521
  * Space Complexity: O(1) - Constant space.
443
522
  *
444
523
  * @param str
@@ -0,0 +1,5 @@
1
+ import { AVLTreeMultiMap, AVLTreeMultiMapNode } from '../../../data-structures';
2
+ import type { AVLTreeOptions } from './avl-tree';
3
+ export type AVLTreeMultiMapNodeNested<K, V> = AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
4
+ export type AVLTreeMultiMapNested<K, V, N extends AVLTreeMultiMapNode<K, V, N>> = AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
5
+ export type AVLTreeMultiMapOptions<K> = AVLTreeOptions<K> & {};
@@ -2,5 +2,6 @@ export * from './binary-tree';
2
2
  export * from './bst';
3
3
  export * from './avl-tree';
4
4
  export * from './segment-tree';
5
- export * from './tree-multimap';
5
+ export * from './avl-tree-multi-map';
6
6
  export * from './rb-tree';
7
+ export * from './tree-multi-map';
@@ -18,5 +18,6 @@ __exportStar(require("./binary-tree"), exports);
18
18
  __exportStar(require("./bst"), exports);
19
19
  __exportStar(require("./avl-tree"), exports);
20
20
  __exportStar(require("./segment-tree"), exports);
21
- __exportStar(require("./tree-multimap"), exports);
21
+ __exportStar(require("./avl-tree-multi-map"), exports);
22
22
  __exportStar(require("./rb-tree"), exports);
23
+ __exportStar(require("./tree-multi-map"), exports);
@@ -0,0 +1,5 @@
1
+ import { TreeMultiMap, TreeMultiMapNode } from '../../../data-structures';
2
+ import type { RBTreeOptions } from './rb-tree';
3
+ export type TreeMultiMapNodeNested<K, V> = TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
4
+ export type TreeMultiMapNested<K, V, N extends TreeMultiMapNode<K, V, N>> = TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
5
+ export type TreeMultiMapOptions<K> = RBTreeOptions<K> & {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "min-heap-typed",
3
- "version": "1.50.2",
3
+ "version": "1.50.4",
4
4
  "description": "Min Heap. Javascript & Typescript Data Structure.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -132,6 +132,6 @@
132
132
  "typescript": "^4.9.5"
133
133
  },
134
134
  "dependencies": {
135
- "data-structure-typed": "^1.50.2"
135
+ "data-structure-typed": "^1.50.4"
136
136
  }
137
137
  }
@@ -289,8 +289,14 @@ export abstract class IterableEntryBase<K = any, V = any> {
289
289
 
290
290
  abstract isEmpty(): boolean;
291
291
 
292
+ abstract clear(): void;
293
+
292
294
  abstract clone(): any;
293
295
 
296
+ abstract map(...args: any[]): any;
297
+
298
+ abstract filter(...args: any[]): any;
299
+
294
300
  protected abstract _getIterator(...args: any[]): IterableIterator<[K, V]>;
295
301
  }
296
302
 
@@ -497,7 +503,13 @@ export abstract class IterableElementBase<E = any, C = any> {
497
503
 
498
504
  abstract isEmpty(): boolean;
499
505
 
506
+ abstract clear(): void;
507
+
500
508
  abstract clone(): C;
501
509
 
510
+ abstract map(...args: any[]): any;
511
+
512
+ abstract filter(...args: any[]): any;
513
+
502
514
  protected abstract _getIterator(...args: any[]): IterableIterator<E>;
503
515
  }
@@ -6,25 +6,23 @@
6
6
  * @license MIT License
7
7
  */
8
8
  import type {
9
+ AVLTreeMultiMapNested,
10
+ AVLTreeMultiMapNodeNested,
11
+ AVLTreeMultiMapOptions,
9
12
  BinaryTreeDeleteResult,
10
13
  BSTNKeyOrNode,
11
14
  BTNCallback,
12
- KeyOrNodeOrEntry,
13
- TreeMultimapNested,
14
- TreeMultimapNodeNested,
15
- TreeMultimapOptions
15
+ KeyOrNodeOrEntry
16
16
  } from '../../types';
17
17
  import { FamilyPosition, IterationType } from '../../types';
18
18
  import { IBinaryTree } from '../../interfaces';
19
19
  import { AVLTree, AVLTreeNode } from './avl-tree';
20
20
 
21
- export class TreeMultimapNode<
21
+ export class AVLTreeMultiMapNode<
22
22
  K = any,
23
23
  V = any,
24
- NODE extends TreeMultimapNode<K, V, NODE> = TreeMultimapNodeNested<K, V>
24
+ NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNodeNested<K, V>
25
25
  > extends AVLTreeNode<K, V, NODE> {
26
- count: number;
27
-
28
26
  /**
29
27
  * The constructor function initializes a BinaryTreeNode object with a key, value, and count.
30
28
  * @param {K} key - The `key` parameter is of type `K` and represents the unique identifier
@@ -39,27 +37,51 @@ export class TreeMultimapNode<
39
37
  super(key, value);
40
38
  this.count = count;
41
39
  }
40
+
41
+ protected _count: number = 1;
42
+
43
+ /**
44
+ * The function returns the value of the protected variable _count.
45
+ * @returns The count property of the object, which is of type number.
46
+ */
47
+ get count(): number {
48
+ return this._count;
49
+ }
50
+
51
+ /**
52
+ * The above function sets the value of the count property.
53
+ * @param {number} value - The value parameter is of type number, which means it can accept any
54
+ * numeric value.
55
+ */
56
+ set count(value: number) {
57
+ this._count = value;
58
+ }
42
59
  }
43
60
 
44
61
  /**
45
- * The only distinction between a TreeMultimap and a AVLTree lies in the ability of the former to store duplicate nodes through the utilization of counters.
62
+ * The only distinction between a AVLTreeMultiMap and a AVLTree lies in the ability of the former to store duplicate nodes through the utilization of counters.
46
63
  */
47
- export class TreeMultimap<
64
+ export class AVLTreeMultiMap<
48
65
  K = any,
49
66
  V = any,
50
- NODE extends TreeMultimapNode<K, V, NODE> = TreeMultimapNode<K, V, TreeMultimapNodeNested<K, V>>,
51
- TREE extends TreeMultimap<K, V, NODE, TREE> = TreeMultimap<K, V, NODE, TreeMultimapNested<K, V, NODE>>
67
+ NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNodeNested<K, V>>,
68
+ TREE extends AVLTreeMultiMap<K, V, NODE, TREE> = AVLTreeMultiMap<K, V, NODE, AVLTreeMultiMapNested<K, V, NODE>>
52
69
  >
53
70
  extends AVLTree<K, V, NODE, TREE>
54
71
  implements IBinaryTree<K, V, NODE, TREE> {
55
- constructor(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, NODE>> = [], options?: TreeMultimapOptions<K>) {
72
+ constructor(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, NODE>> = [], options?: AVLTreeMultiMapOptions<K>) {
56
73
  super([], options);
57
74
  if (keysOrNodesOrEntries) this.addMany(keysOrNodesOrEntries);
58
75
  }
59
76
 
60
- private _count = 0;
77
+ protected _count = 0;
61
78
 
62
79
  // TODO the _count is not accurate after nodes count modified
80
+ /**
81
+ * The function calculates the sum of the count property of all nodes in a tree using depth-first
82
+ * search.
83
+ * @returns the sum of the count property of all nodes in the tree.
84
+ */
63
85
  get count(): number {
64
86
  let sum = 0;
65
87
  this.dfs(node => (sum += node.count));
@@ -76,11 +98,20 @@ export class TreeMultimap<
76
98
  * @returns A new instance of the BSTNode class with the specified key, value, and count (if provided).
77
99
  */
78
100
  override createNode(key: K, value?: V, count?: number): NODE {
79
- return new TreeMultimapNode(key, value, count) as NODE;
101
+ return new AVLTreeMultiMapNode(key, value, count) as NODE;
80
102
  }
81
103
 
82
- override createTree(options?: TreeMultimapOptions<K>): TREE {
83
- return new TreeMultimap<K, V, NODE, TREE>([], {
104
+ /**
105
+ * The function creates a new AVLTreeMultiMap object with the specified options and returns it.
106
+ * @param [options] - The `options` parameter is an optional object that contains additional
107
+ * configuration options for creating the `AVLTreeMultiMap` object. It can include properties such as
108
+ * `iterationType` and `variant`, which are used to specify the type of iteration and the variant of
109
+ * the tree, respectively. These properties can be
110
+ * @returns a new instance of the `AVLTreeMultiMap` class, with the provided options merged with the
111
+ * default options. The returned value is casted as `TREE`.
112
+ */
113
+ override createTree(options?: AVLTreeMultiMapOptions<K>): TREE {
114
+ return new AVLTreeMultiMap<K, V, NODE, TREE>([], {
84
115
  iterationType: this.iterationType,
85
116
  variant: this.variant,
86
117
  ...options
@@ -124,13 +155,13 @@ export class TreeMultimap<
124
155
  }
125
156
 
126
157
  /**
127
- * The function checks if an keyOrNodeOrEntry is an instance of the TreeMultimapNode class.
158
+ * The function checks if an keyOrNodeOrEntry is an instance of the AVLTreeMultiMapNode class.
128
159
  * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`.
129
- * @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the TreeMultimapNode
160
+ * @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the AVLTreeMultiMapNode
130
161
  * class.
131
162
  */
132
163
  override isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntry is NODE {
133
- return keyOrNodeOrEntry instanceof TreeMultimapNode;
164
+ return keyOrNodeOrEntry instanceof AVLTreeMultiMapNode;
134
165
  }
135
166
 
136
167
  /**
@@ -375,6 +406,14 @@ export class TreeMultimap<
375
406
  return undefined;
376
407
  }
377
408
 
409
+ /**
410
+ * The function replaces an old node with a new node and updates the count property of the new node.
411
+ * @param {NODE} oldNode - The `oldNode` parameter is of type `NODE` and represents the node that
412
+ * needs to be replaced in a data structure.
413
+ * @param {NODE} newNode - The `newNode` parameter is an object of type `NODE`.
414
+ * @returns The method is returning the result of calling the `_replaceNode` method from the
415
+ * superclass, after updating the `count` property of the `newNode` object.
416
+ */
378
417
  protected _replaceNode(oldNode: NODE, newNode: NODE): NODE {
379
418
  newNode.count = oldNode.count + newNode.count;
380
419
  return super._replaceNode(oldNode, newNode);
@@ -22,11 +22,36 @@ export class AVLTreeNode<
22
22
  V = any,
23
23
  NODE extends AVLTreeNode<K, V, NODE> = AVLTreeNodeNested<K, V>
24
24
  > extends BSTNode<K, V, NODE> {
25
- height: number;
26
-
25
+ /**
26
+ * The constructor function initializes a new instance of a class with a key and an optional value,
27
+ * and sets the height property to 0.
28
+ * @param {K} key - The "key" parameter is of type K, which represents the type of the key for the
29
+ * constructor. It is used to initialize the key property of the object being created.
30
+ * @param {V} [value] - The "value" parameter is an optional parameter of type V. It represents the
31
+ * value associated with the key in the constructor.
32
+ */
27
33
  constructor(key: K, value?: V) {
28
34
  super(key, value);
29
- this.height = 0;
35
+ this._height = 0;
36
+ }
37
+
38
+ protected _height: number;
39
+
40
+ /**
41
+ * The function returns the value of the height property.
42
+ * @returns The height of the object.
43
+ */
44
+ get height(): number {
45
+ return this._height;
46
+ }
47
+
48
+ /**
49
+ * The above function sets the value of the height property.
50
+ * @param {number} value - The value parameter is a number that represents the new height value to be
51
+ * set.
52
+ */
53
+ set height(value: number) {
54
+ this._height = value;
30
55
  }
31
56
  }
32
57
 
@@ -488,6 +513,15 @@ export class AVLTree<
488
513
  }
489
514
  }
490
515
 
516
+ /**
517
+ * The function replaces an old node with a new node while preserving the height of the old node.
518
+ * @param {NODE} oldNode - The `oldNode` parameter is the node that you want to replace with the
519
+ * `newNode`.
520
+ * @param {NODE} newNode - The `newNode` parameter is the new node that will replace the `oldNode` in
521
+ * the data structure.
522
+ * @returns the result of calling the `_replaceNode` method on the superclass, passing in the
523
+ * `oldNode` and `newNode` as arguments.
524
+ */
491
525
  protected _replaceNode(oldNode: NODE, newNode: NODE): NODE {
492
526
  newNode.height = oldNode.height;
493
527
 
@@ -27,26 +27,48 @@ export class BinaryIndexedTree {
27
27
 
28
28
  protected _freqMap: Record<number, number>;
29
29
 
30
+ /**
31
+ * The function returns the frequency map of numbers.
32
+ * @returns The `_freqMap` property, which is a record with number keys and number values, is being
33
+ * returned.
34
+ */
30
35
  get freqMap(): Record<number, number> {
31
36
  return this._freqMap;
32
37
  }
33
38
 
34
39
  protected _msb: number;
35
40
 
41
+ /**
42
+ * The function returns the value of the _msb property.
43
+ * @returns The `_msb` property of the object.
44
+ */
36
45
  get msb(): number {
37
46
  return this._msb;
38
47
  }
39
48
 
40
49
  protected _negativeCount: number;
41
50
 
51
+ /**
52
+ * The function returns the value of the _negativeCount property.
53
+ * @returns The method is returning the value of the variable `_negativeCount`, which is of type
54
+ * `number`.
55
+ */
42
56
  get negativeCount(): number {
43
57
  return this._negativeCount;
44
58
  }
45
59
 
60
+ /**
61
+ * The above function returns the value of the protected variable `_freq`.
62
+ * @returns The frequency value stored in the protected variable `_freq`.
63
+ */
46
64
  get freq(): number {
47
65
  return this._freq;
48
66
  }
49
67
 
68
+ /**
69
+ * The above function returns the maximum value.
70
+ * @returns The maximum value stored in the variable `_max`.
71
+ */
50
72
  get max(): number {
51
73
  return this._max;
52
74
  }
@@ -44,7 +44,7 @@ export class BinaryTreeNode<
44
44
  /**
45
45
  * The constructor function initializes an object with a key and an optional value.
46
46
  * @param {K} key - The "key" parameter is of type K, which represents the type of the key for the
47
- * constructor. It is used to set the value of the "key" property of the object being created.
47
+ * constructor. It is used to set the key property of the object being created.
48
48
  * @param {V} [value] - The "value" parameter is an optional parameter of type V. It represents the
49
49
  * value associated with the key in the constructor.
50
50
  */