min-heap-typed 1.51.9 → 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 (94) 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 +3 -3
  8. package/dist/data-structures/binary-tree/avl-tree.d.ts +3 -3
  9. package/dist/data-structures/binary-tree/binary-tree.d.ts +4 -4
  10. package/dist/data-structures/binary-tree/binary-tree.js +5 -3
  11. package/dist/data-structures/binary-tree/bst.d.ts +3 -11
  12. package/dist/data-structures/binary-tree/bst.js +2 -10
  13. package/dist/data-structures/binary-tree/rb-tree.d.ts +3 -3
  14. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +3 -3
  15. package/dist/data-structures/hash/hash-map.d.ts +2 -2
  16. package/dist/data-structures/heap/heap.d.ts +43 -114
  17. package/dist/data-structures/heap/heap.js +59 -127
  18. package/dist/data-structures/heap/max-heap.d.ts +50 -4
  19. package/dist/data-structures/heap/max-heap.js +76 -10
  20. package/dist/data-structures/heap/min-heap.d.ts +51 -5
  21. package/dist/data-structures/heap/min-heap.js +68 -11
  22. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +22 -28
  23. package/dist/data-structures/linked-list/doubly-linked-list.js +26 -28
  24. package/dist/data-structures/linked-list/singly-linked-list.d.ts +22 -25
  25. package/dist/data-structures/linked-list/singly-linked-list.js +29 -26
  26. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +50 -4
  27. package/dist/data-structures/priority-queue/max-priority-queue.js +79 -10
  28. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +51 -5
  29. package/dist/data-structures/priority-queue/min-priority-queue.js +71 -11
  30. package/dist/data-structures/priority-queue/priority-queue.d.ts +50 -4
  31. package/dist/data-structures/priority-queue/priority-queue.js +70 -1
  32. package/dist/data-structures/queue/deque.d.ts +20 -18
  33. package/dist/data-structures/queue/deque.js +27 -20
  34. package/dist/data-structures/queue/queue.d.ts +8 -28
  35. package/dist/data-structures/queue/queue.js +15 -31
  36. package/dist/data-structures/stack/stack.d.ts +17 -22
  37. package/dist/data-structures/stack/stack.js +25 -24
  38. package/dist/data-structures/trie/trie.d.ts +18 -13
  39. package/dist/data-structures/trie/trie.js +26 -15
  40. package/dist/interfaces/binary-tree.d.ts +2 -2
  41. package/dist/types/data-structures/base/base.d.ts +5 -2
  42. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -3
  43. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +2 -3
  44. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +2 -3
  45. package/dist/types/data-structures/binary-tree/bst.d.ts +2 -3
  46. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +2 -3
  47. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -3
  48. package/dist/types/data-structures/heap/heap.d.ts +3 -2
  49. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
  50. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +2 -1
  51. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  52. package/dist/types/data-structures/queue/deque.d.ts +3 -2
  53. package/dist/types/data-structures/queue/queue.d.ts +2 -1
  54. package/dist/types/data-structures/stack/stack.d.ts +2 -1
  55. package/dist/types/data-structures/trie/trie.d.ts +3 -2
  56. package/package.json +2 -2
  57. package/src/data-structures/base/index.ts +2 -1
  58. package/src/data-structures/base/iterable-element-base.ts +250 -0
  59. package/src/data-structures/base/{iterable-base.ts → iterable-entry-base.ts} +22 -213
  60. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +2 -3
  61. package/src/data-structures/binary-tree/avl-tree.ts +2 -3
  62. package/src/data-structures/binary-tree/binary-tree.ts +6 -6
  63. package/src/data-structures/binary-tree/bst.ts +8 -19
  64. package/src/data-structures/binary-tree/rb-tree.ts +2 -3
  65. package/src/data-structures/binary-tree/tree-multi-map.ts +2 -3
  66. package/src/data-structures/hash/hash-map.ts +4 -4
  67. package/src/data-structures/heap/heap.ts +71 -152
  68. package/src/data-structures/heap/max-heap.ts +88 -13
  69. package/src/data-structures/heap/min-heap.ts +78 -15
  70. package/src/data-structures/linked-list/doubly-linked-list.ts +32 -32
  71. package/src/data-structures/linked-list/singly-linked-list.ts +37 -29
  72. package/src/data-structures/priority-queue/max-priority-queue.ts +94 -13
  73. package/src/data-structures/priority-queue/min-priority-queue.ts +84 -15
  74. package/src/data-structures/priority-queue/priority-queue.ts +81 -4
  75. package/src/data-structures/queue/deque.ts +35 -24
  76. package/src/data-structures/queue/queue.ts +23 -36
  77. package/src/data-structures/stack/stack.ts +31 -26
  78. package/src/data-structures/trie/trie.ts +33 -18
  79. package/src/interfaces/binary-tree.ts +1 -2
  80. package/src/types/data-structures/base/base.ts +14 -6
  81. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +2 -3
  82. package/src/types/data-structures/binary-tree/avl-tree.ts +2 -3
  83. package/src/types/data-structures/binary-tree/binary-tree.ts +3 -4
  84. package/src/types/data-structures/binary-tree/bst.ts +2 -3
  85. package/src/types/data-structures/binary-tree/rb-tree.ts +2 -3
  86. package/src/types/data-structures/binary-tree/tree-multi-map.ts +2 -3
  87. package/src/types/data-structures/heap/heap.ts +4 -1
  88. package/src/types/data-structures/linked-list/doubly-linked-list.ts +3 -1
  89. package/src/types/data-structures/linked-list/singly-linked-list.ts +3 -1
  90. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -1
  91. package/src/types/data-structures/queue/deque.ts +3 -1
  92. package/src/types/data-structures/queue/queue.ts +3 -1
  93. package/src/types/data-structures/stack/stack.ts +3 -1
  94. package/src/types/data-structures/trie/trie.ts +3 -1
@@ -1,7 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IterableElementBase = exports.IterableEntryBase = void 0;
3
+ exports.IterableEntryBase = void 0;
4
4
  class IterableEntryBase {
5
+ // protected _toEntryFn?: (rawElement: R) => BTNEntry<K, V>;
6
+ //
7
+ // /**
8
+ // * The function returns the value of the _toEntryFn property.
9
+ // * @returns The function being returned is `this._toEntryFn`.
10
+ // */
11
+ // get toEntryFn() {
12
+ // return this._toEntryFn;
13
+ // }
5
14
  /**
6
15
  * Time Complexity: O(n)
7
16
  * Space Complexity: O(1)
@@ -262,32 +271,6 @@ class IterableEntryBase {
262
271
  }
263
272
  return accumulator;
264
273
  }
265
- /**
266
- * Time Complexity: O(n)
267
- * Space Complexity: O(n)
268
- */
269
- print() {
270
- console.log([...this]);
271
- }
272
- }
273
- exports.IterableEntryBase = IterableEntryBase;
274
- class IterableElementBase {
275
- /**
276
- * Time Complexity: O(n)
277
- * Space Complexity: O(1)
278
- */
279
- /**
280
- * Time Complexity: O(n)
281
- * Space Complexity: O(1)
282
- *
283
- * The function is an implementation of the Symbol.iterator method that returns an IterableIterator.
284
- * @param {any[]} args - The `args` parameter in the code snippet represents a rest parameter. It
285
- * allows the function to accept any number of arguments as an array. In this case, the `args`
286
- * parameter is used to pass any number of arguments to the `_getIterator` method.
287
- */
288
- *[Symbol.iterator](...args) {
289
- yield* this._getIterator(...args);
290
- }
291
274
  /**
292
275
  * Time Complexity: O(n)
293
276
  * Space Complexity: O(n)
@@ -296,170 +279,10 @@ class IterableElementBase {
296
279
  * Time Complexity: O(n)
297
280
  * Space Complexity: O(n)
298
281
  *
299
- * The function returns an iterator that yields all the values in the object.
300
- */
301
- *values() {
302
- for (const item of this) {
303
- yield item;
304
- }
305
- }
306
- /**
307
- * Time Complexity: O(n)
308
- * Space Complexity: O(1)
309
- */
310
- /**
311
- * Time Complexity: O(n)
312
- * Space Complexity: O(1)
313
- *
314
- * The `every` function checks if every element in the array satisfies a given predicate.
315
- * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
316
- * the current element being processed, its index, and the array it belongs to. It should return a
317
- * boolean value indicating whether the element satisfies a certain condition or not.
318
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
319
- * to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
320
- * passed as the `this` value to the `predicate` function. If `thisArg` is
321
- * @returns The `every` method is returning a boolean value. It returns `true` if every element in
322
- * the array satisfies the provided predicate function, and `false` otherwise.
323
- */
324
- every(predicate, thisArg) {
325
- let index = 0;
326
- for (const item of this) {
327
- if (!predicate.call(thisArg, item, index++, this)) {
328
- return false;
329
- }
330
- }
331
- return true;
332
- }
333
- /**
334
- * Time Complexity: O(n)
335
- * Space Complexity: O(1)
336
- */
337
- /**
338
- * Time Complexity: O(n)
339
- * Space Complexity: O(1)
340
- */
341
- /**
342
- * Time Complexity: O(n)
343
- * Space Complexity: O(1)
344
- *
345
- * The "some" function checks if at least one element in a collection satisfies a given predicate.
346
- * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
347
- * `value`, `index`, and `array`. It should return a boolean value indicating whether the current
348
- * element satisfies the condition.
349
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
350
- * to be used as the `this` value when executing the `predicate` function. If `thisArg` is provided,
351
- * it will be passed as the `this` value to the `predicate` function. If `thisArg
352
- * @returns a boolean value. It returns true if the predicate function returns true for any element
353
- * in the collection, and false otherwise.
354
- */
355
- some(predicate, thisArg) {
356
- let index = 0;
357
- for (const item of this) {
358
- if (predicate.call(thisArg, item, index++, this)) {
359
- return true;
360
- }
361
- }
362
- return false;
363
- }
364
- /**
365
- * Time Complexity: O(n)
366
- * Space Complexity: O(1)
367
- */
368
- /**
369
- * Time Complexity: O(n)
370
- * Space Complexity: O(1)
371
- *
372
- * The `forEach` function iterates over each element in an array-like object and calls a callback
373
- * function for each element.
374
- * @param callbackfn - The callbackfn parameter is a function that will be called for each element in
375
- * the array. It takes three arguments: the current element being processed, the index of the current
376
- * element, and the array that forEach was called upon.
377
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
378
- * to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
379
- * be passed as the `this` value to the `callbackfn` function. If `thisArg
380
- */
381
- forEach(callbackfn, thisArg) {
382
- let index = 0;
383
- for (const item of this) {
384
- callbackfn.call(thisArg, item, index++, this);
385
- }
386
- }
387
- /**
388
- * Time Complexity: O(n)
389
- * Space Complexity: O(1)
390
- */
391
- /**
392
- * Time Complexity: O(n)
393
- * Space Complexity: O(1)
394
- *
395
- * The `find` function iterates over the elements of an array-like object and returns the first
396
- * element that satisfies the provided callback function.
397
- * @param callbackfn - The callbackfn parameter is a function that will be called for each element in
398
- * the array. It takes three arguments: the current element being processed, the index of the current
399
- * element, and the array itself. The function should return a boolean value indicating whether the
400
- * current element matches the desired condition.
401
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
402
- * to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
403
- * be passed as the `this` value to the `callbackfn` function. If `thisArg
404
- * @returns The `find` method returns the first element in the array that satisfies the provided
405
- * callback function. If no element satisfies the callback function, `undefined` is returned.
406
- */
407
- find(callbackfn, thisArg) {
408
- let index = 0;
409
- for (const item of this) {
410
- if (callbackfn.call(thisArg, item, index++, this))
411
- return item;
412
- }
413
- return;
414
- }
415
- /**
416
- * Time Complexity: O(n)
417
- * Space Complexity: O(1)
418
- *
419
- * The function checks if a given element exists in a collection.
420
- * @param {E} element - The parameter "element" is of type E, which means it can be any type. It
421
- * represents the element that we want to check for existence in the collection.
422
- * @returns a boolean value. It returns true if the element is found in the collection, and false
423
- * otherwise.
424
- */
425
- has(element) {
426
- for (const ele of this) {
427
- if (ele === element)
428
- return true;
429
- }
430
- return false;
431
- }
432
- /**
433
- * Time Complexity: O(n)
434
- * Space Complexity: O(1)
435
- */
436
- /**
437
- * Time Complexity: O(n)
438
- * Space Complexity: O(1)
439
- *
440
- * The `reduce` function iterates over the elements of an array-like object and applies a callback
441
- * function to reduce them into a single value.
442
- * @param callbackfn - The callbackfn parameter is a function that will be called for each element in
443
- * the array. It takes four arguments:
444
- * @param {U} initialValue - The initialValue parameter is the initial value of the accumulator. It
445
- * is the value that the accumulator starts with before the reduction operation begins.
446
- * @returns The `reduce` method is returning the final value of the accumulator after iterating over
447
- * all the elements in the array and applying the callback function to each element.
448
- */
449
- reduce(callbackfn, initialValue) {
450
- let accumulator = initialValue;
451
- let index = 0;
452
- for (const item of this) {
453
- accumulator = callbackfn(accumulator, item, index++, this);
454
- }
455
- return accumulator;
456
- }
457
- /**
458
- * Time Complexity: O(n)
459
- * Space Complexity: O(n)
282
+ * The print function logs the elements of an array to the console.
460
283
  */
461
284
  print() {
462
285
  console.log([...this]);
463
286
  }
464
287
  }
465
- exports.IterableElementBase = IterableElementBase;
288
+ exports.IterableEntryBase = IterableEntryBase;
@@ -5,11 +5,11 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { AVLTreeMultiMapNested, AVLTreeMultiMapNodeNested, AVLTreeMultiMapOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, Comparable, IterationType, KeyOrNodeOrEntry } from '../../types';
8
+ import type { AVLTreeMultiMapNested, AVLTreeMultiMapNodeNested, AVLTreeMultiMapOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, IterationType, KeyOrNodeOrEntry } from '../../types';
9
9
  import { BTNEntry } from '../../types';
10
10
  import { IBinaryTree } from '../../interfaces';
11
11
  import { AVLTree, AVLTreeNode } from './avl-tree';
12
- export declare class AVLTreeMultiMapNode<K extends Comparable, V = any, NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNodeNested<K, V>> extends AVLTreeNode<K, V, NODE> {
12
+ export declare class AVLTreeMultiMapNode<K = any, V = any, NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNodeNested<K, V>> extends AVLTreeNode<K, V, NODE> {
13
13
  /**
14
14
  * The constructor function initializes a BinaryTreeNode object with a key, value, and count.
15
15
  * @param {K} key - The `key` parameter is of type `K` and represents the unique identifier
@@ -37,7 +37,7 @@ export declare class AVLTreeMultiMapNode<K extends Comparable, V = any, NODE ext
37
37
  /**
38
38
  * 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.
39
39
  */
40
- export declare class AVLTreeMultiMap<K extends Comparable, V = any, R = BTNEntry<K, V>, NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNodeNested<K, V>>, TREE extends AVLTreeMultiMap<K, V, R, NODE, TREE> = AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMapNested<K, V, R, NODE>>> extends AVLTree<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
40
+ export declare class AVLTreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNodeNested<K, V>>, TREE extends AVLTreeMultiMap<K, V, R, NODE, TREE> = AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMapNested<K, V, R, NODE>>> extends AVLTree<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
41
41
  /**
42
42
  * The constructor initializes a new AVLTreeMultiMap object with optional initial elements.
43
43
  * @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
@@ -6,10 +6,10 @@
6
6
  * @license MIT License
7
7
  */
8
8
  import { BST, BSTNode } from './bst';
9
- import type { AVLTreeNested, AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, Comparable, KeyOrNodeOrEntry } from '../../types';
9
+ import type { AVLTreeNested, AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, KeyOrNodeOrEntry } from '../../types';
10
10
  import { BTNEntry } from '../../types';
11
11
  import { IBinaryTree } from '../../interfaces';
12
- export declare class AVLTreeNode<K extends Comparable, V = any, NODE extends AVLTreeNode<K, V, NODE> = AVLTreeNodeNested<K, V>> extends BSTNode<K, V, NODE> {
12
+ export declare class AVLTreeNode<K = any, V = any, NODE extends AVLTreeNode<K, V, NODE> = AVLTreeNodeNested<K, V>> extends BSTNode<K, V, NODE> {
13
13
  /**
14
14
  * The constructor function initializes a new instance of a class with a key and an optional value,
15
15
  * and sets the height property to 0.
@@ -41,7 +41,7 @@ export declare class AVLTreeNode<K extends Comparable, V = any, NODE extends AVL
41
41
  * 6. Complex Insertions and Deletions: Due to rebalancing, these operations are more complex than in a regular BST.
42
42
  * 7. Path Length: The path length from the root to any leaf is longer compared to an unbalanced BST, but shorter than a linear chain of nodes.
43
43
  */
44
- export declare class AVLTree<K extends Comparable, V = any, R = BTNEntry<K, V>, NODE extends AVLTreeNode<K, V, NODE> = AVLTreeNode<K, V, AVLTreeNodeNested<K, V>>, TREE extends AVLTree<K, V, R, NODE, TREE> = AVLTree<K, V, R, NODE, AVLTreeNested<K, V, R, NODE>>> extends BST<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
44
+ export declare class AVLTree<K = any, V = any, R = BTNEntry<K, V>, NODE extends AVLTreeNode<K, V, NODE> = AVLTreeNode<K, V, AVLTreeNodeNested<K, V>>, TREE extends AVLTree<K, V, R, NODE, TREE> = AVLTree<K, V, R, NODE, AVLTreeNested<K, V, R, NODE>>> extends BST<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
45
45
  /**
46
46
  * This is a constructor function for an AVLTree class that initializes the tree with keys, nodes,
47
47
  * entries, or raw elements.
@@ -5,7 +5,7 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BinaryTreePrintOptions, BTNCallback, BTNEntry, Comparable, DFSOrderPattern, EntryCallback, FamilyPosition, IterationType, KeyOrNodeOrEntry, NodeDisplayLayout } from '../../types';
8
+ import type { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BinaryTreePrintOptions, BTNCallback, BTNEntry, DFSOrderPattern, EntryCallback, FamilyPosition, IterationType, KeyOrNodeOrEntry, NodeDisplayLayout } from '../../types';
9
9
  import { IBinaryTree } from '../../interfaces';
10
10
  import { IterableEntryBase } from '../base';
11
11
  /**
@@ -13,7 +13,7 @@ import { IterableEntryBase } from '../base';
13
13
  * @template V - The type of data stored in the node.
14
14
  * @template NODE - The type of the family relationship in the binary tree.
15
15
  */
16
- export declare class BinaryTreeNode<K extends Comparable, V = any, NODE extends BinaryTreeNode<K, V, NODE> = BinaryTreeNode<K, V, BinaryTreeNodeNested<K, V>>> {
16
+ export declare class BinaryTreeNode<K = any, V = any, NODE extends BinaryTreeNode<K, V, NODE> = BinaryTreeNode<K, V, BinaryTreeNodeNested<K, V>>> {
17
17
  key: K;
18
18
  value?: V;
19
19
  parent?: NODE;
@@ -65,11 +65,11 @@ export declare class BinaryTreeNode<K extends Comparable, V = any, NODE extends
65
65
  * 4. Subtrees: Each child of a node forms the root of a subtree.
66
66
  * 5. Leaf Nodes: Nodes without children are leaves.
67
67
  */
68
- export declare class BinaryTree<K extends Comparable, V = any, R = BTNEntry<K, V>, NODE extends BinaryTreeNode<K, V, NODE> = BinaryTreeNode<K, V, BinaryTreeNodeNested<K, V>>, TREE extends BinaryTree<K, V, R, NODE, TREE> = BinaryTree<K, V, R, NODE, BinaryTreeNested<K, V, R, NODE>>> extends IterableEntryBase<K, V | undefined> implements IBinaryTree<K, V, R, NODE, TREE> {
68
+ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE extends BinaryTreeNode<K, V, NODE> = BinaryTreeNode<K, V, BinaryTreeNodeNested<K, V>>, TREE extends BinaryTree<K, V, R, NODE, TREE> = BinaryTree<K, V, R, NODE, BinaryTreeNested<K, V, R, NODE>>> extends IterableEntryBase<K, V | undefined> implements IBinaryTree<K, V, R, NODE, TREE> {
69
69
  iterationType: IterationType;
70
70
  /**
71
71
  * The constructor function initializes a binary tree object with optional keysOrNodesOrEntriesOrRawElements and options.
72
- * @param [keysOrNodesOrEntriesOrRawElements] - An optional iterable of KeyOrNodeOrEntry objects. These objects represent the
72
+ * @param [keysOrNodesOrEntriesOrRawElements] - Optional iterable of KeyOrNodeOrEntry objects. These objects represent the
73
73
  * nodes to be added to the binary tree.
74
74
  * @param [options] - The `options` parameter is an optional object that can contain additional
75
75
  * configuration options for the binary tree. In this case, it is of type
@@ -96,7 +96,7 @@ exports.BinaryTreeNode = BinaryTreeNode;
96
96
  class BinaryTree extends base_1.IterableEntryBase {
97
97
  /**
98
98
  * The constructor function initializes a binary tree object with optional keysOrNodesOrEntriesOrRawElements and options.
99
- * @param [keysOrNodesOrEntriesOrRawElements] - An optional iterable of KeyOrNodeOrEntry objects. These objects represent the
99
+ * @param [keysOrNodesOrEntriesOrRawElements] - Optional iterable of KeyOrNodeOrEntry objects. These objects represent the
100
100
  * nodes to be added to the binary tree.
101
101
  * @param [options] - The `options` parameter is an optional object that can contain additional
102
102
  * configuration options for the binary tree. In this case, it is of type
@@ -115,6 +115,8 @@ class BinaryTree extends base_1.IterableEntryBase {
115
115
  this.iterationType = iterationType;
116
116
  if (typeof toEntryFn === 'function')
117
117
  this._toEntryFn = toEntryFn;
118
+ else if (toEntryFn)
119
+ throw TypeError('toEntryFn must be a function type');
118
120
  }
119
121
  if (keysOrNodesOrEntriesOrRawElements)
120
122
  this.addMany(keysOrNodesOrEntriesOrRawElements);
@@ -1699,12 +1701,12 @@ class BinaryTree extends base_1.IterableEntryBase {
1699
1701
  }
1700
1702
  else if (node !== null && node !== undefined) {
1701
1703
  // Display logic of normal nodes
1702
- const key = node.key, line = this.isNIL(node) ? 'S' : key.toString(), width = line.length;
1704
+ const key = node.key, line = this.isNIL(node) ? 'S' : String(key), width = line.length;
1703
1705
  return _buildNodeDisplay(line, width, this._displayAux(node.left, options), this._displayAux(node.right, options));
1704
1706
  }
1705
1707
  else {
1706
1708
  // For cases where none of the conditions are met, null, undefined, and NaN nodes are not displayed
1707
- const line = node === undefined ? 'U' : 'NODE', width = line.length;
1709
+ const line = node === undefined ? 'U' : 'N', width = line.length;
1708
1710
  return _buildNodeDisplay(line, width, [[''], 1, 0, 0], [[''], 1, 0, 0]);
1709
1711
  }
1710
1712
  function _buildNodeDisplay(line, width, left, right) {
@@ -5,11 +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
9
  import { BTNEntry } from '../../types';
10
10
  import { BinaryTree, BinaryTreeNode } from './binary-tree';
11
11
  import { IBinaryTree } from '../../interfaces';
12
- 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> {
13
13
  parent?: NODE;
14
14
  constructor(key: K, value?: V);
15
15
  protected _left?: NODE;
@@ -47,7 +47,7 @@ export declare class BSTNode<K extends Comparable, V = any, NODE extends BSTNode
47
47
  * 6. Balance Variability: Can become unbalanced; special types maintain balance.
48
48
  * 7. No Auto-Balancing: Standard BSTs don't automatically balance themselves.
49
49
  */
50
- export declare class BST<K extends Comparable, 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
+ 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> {
51
51
  /**
52
52
  * This is the constructor function for a Binary Search Tree class in TypeScript.
53
53
  * @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
@@ -349,15 +349,7 @@ export declare class BST<K extends Comparable, V = any, R = BTNEntry<K, V>, NODE
349
349
  * @returns a boolean value.
350
350
  */
351
351
  isAVLBalanced(iterationType?: IterationType): boolean;
352
- /**
353
- * Time complexity: O(n)
354
- * Space complexity: O(n)
355
- */
356
352
  protected _DEFAULT_COMPARATOR: (a: K, b: K) => number;
357
- /**
358
- * Time complexity: O(n)
359
- * Space complexity: O(n)
360
- */
361
353
  protected _comparator: Comparator<K>;
362
354
  /**
363
355
  * Time Complexity: O(n)
@@ -70,13 +70,9 @@ class BST extends binary_tree_1.BinaryTree {
70
70
  constructor(keysOrNodesOrEntriesOrRawElements = [], options) {
71
71
  super([], options);
72
72
  this._root = undefined;
73
- /**
74
- * Time complexity: O(n)
75
- * Space complexity: O(n)
76
- */
77
73
  this._DEFAULT_COMPARATOR = (a, b) => {
78
- if (typeof a === 'object' && typeof b === 'object' && this.comparator === this._DEFAULT_COMPARATOR) {
79
- throw TypeError('When comparing two object types, it is necessary to customize a [comparator] function of options parameter during the instantiation of the data structure.');
74
+ if (typeof a === 'object' || typeof b === 'object') {
75
+ throw TypeError(`When comparing object types, a custom comparator must be defined in the constructor's options parameter.`);
80
76
  }
81
77
  if (a > b)
82
78
  return 1;
@@ -84,10 +80,6 @@ class BST extends binary_tree_1.BinaryTree {
84
80
  return -1;
85
81
  return 0;
86
82
  };
87
- /**
88
- * Time complexity: O(n)
89
- * Space complexity: O(n)
90
- */
91
83
  this._comparator = this._DEFAULT_COMPARATOR;
92
84
  if (options) {
93
85
  const { comparator } = options;
@@ -1,8 +1,8 @@
1
- import type { BinaryTreeDeleteResult, BTNCallback, Comparable, CRUD, KeyOrNodeOrEntry, RBTNColor, RBTreeOptions, RedBlackTreeNested, RedBlackTreeNodeNested } from '../../types';
1
+ import type { BinaryTreeDeleteResult, BTNCallback, CRUD, KeyOrNodeOrEntry, RBTNColor, RBTreeOptions, RedBlackTreeNested, RedBlackTreeNodeNested } from '../../types';
2
2
  import { BTNEntry } from '../../types';
3
3
  import { BST, BSTNode } from './bst';
4
4
  import { IBinaryTree } from '../../interfaces';
5
- export declare class RedBlackTreeNode<K extends Comparable, V = any, NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNodeNested<K, V>> extends BSTNode<K, V, NODE> {
5
+ export declare class RedBlackTreeNode<K = any, V = any, NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNodeNested<K, V>> extends BSTNode<K, V, NODE> {
6
6
  /**
7
7
  * The constructor function initializes a Red-Black Tree Node with a key, an optional value, and a
8
8
  * color.
@@ -27,7 +27,7 @@ export declare class RedBlackTreeNode<K extends Comparable, V = any, NODE extend
27
27
  */
28
28
  set color(value: RBTNColor);
29
29
  }
30
- export declare class RedBlackTree<K extends Comparable, V = any, R = BTNEntry<K, V>, NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNode<K, V, RedBlackTreeNodeNested<K, V>>, TREE extends RedBlackTree<K, V, R, NODE, TREE> = RedBlackTree<K, V, R, NODE, RedBlackTreeNested<K, V, R, NODE>>> extends BST<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
30
+ export declare class RedBlackTree<K = any, V = any, R = BTNEntry<K, V>, NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNode<K, V, RedBlackTreeNodeNested<K, V>>, TREE extends RedBlackTree<K, V, R, NODE, TREE> = RedBlackTree<K, V, R, NODE, RedBlackTreeNested<K, V, R, NODE>>> extends BST<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
31
31
  /**
32
32
  * This is the constructor function for a Red-Black Tree data structure in TypeScript.
33
33
  * @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
@@ -5,11 +5,11 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, Comparable, IterationType, KeyOrNodeOrEntry, RBTNColor, TreeMultiMapNested, TreeMultiMapNodeNested, TreeMultiMapOptions } from '../../types';
8
+ import type { BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, IterationType, KeyOrNodeOrEntry, RBTNColor, TreeMultiMapNested, TreeMultiMapNodeNested, TreeMultiMapOptions } from '../../types';
9
9
  import { BTNEntry } from '../../types';
10
10
  import { IBinaryTree } from '../../interfaces';
11
11
  import { RedBlackTree, RedBlackTreeNode } from './rb-tree';
12
- export declare class TreeMultiMapNode<K extends Comparable, V = any, NODE extends TreeMultiMapNode<K, V, NODE> = TreeMultiMapNodeNested<K, V>> extends RedBlackTreeNode<K, V, NODE> {
12
+ export declare class TreeMultiMapNode<K = any, V = any, NODE extends TreeMultiMapNode<K, V, NODE> = TreeMultiMapNodeNested<K, V>> extends RedBlackTreeNode<K, V, NODE> {
13
13
  /**
14
14
  * The constructor function initializes a Red-Black Tree node with a key, value, count, and color.
15
15
  * @param {K} key - The key parameter represents the key of the node in the Red-Black Tree. It is
@@ -36,7 +36,7 @@ export declare class TreeMultiMapNode<K extends Comparable, V = any, NODE extend
36
36
  */
37
37
  set count(value: number);
38
38
  }
39
- export declare class TreeMultiMap<K extends Comparable, V = any, R = BTNEntry<K, V>, NODE extends TreeMultiMapNode<K, V, NODE> = TreeMultiMapNode<K, V, TreeMultiMapNodeNested<K, V>>, TREE extends TreeMultiMap<K, V, R, NODE, TREE> = TreeMultiMap<K, V, R, NODE, TreeMultiMapNested<K, V, R, NODE>>> extends RedBlackTree<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
39
+ export declare class TreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE extends TreeMultiMapNode<K, V, NODE> = TreeMultiMapNode<K, V, TreeMultiMapNodeNested<K, V>>, TREE extends TreeMultiMap<K, V, R, NODE, TREE> = TreeMultiMap<K, V, R, NODE, TreeMultiMapNested<K, V, R, NODE>>> extends RedBlackTree<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
40
40
  /**
41
41
  * The constructor function initializes a TreeMultiMap object with optional initial data.
42
42
  * @param keysOrNodesOrEntriesOrRawElements - The parameter `keysOrNodesOrEntriesOrRawElements` is an
@@ -150,7 +150,7 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
150
150
  * @returns The `map` method is returning a new `HashMap` object with the transformed values based on
151
151
  * the provided callback function.
152
152
  */
153
- map<U>(callbackfn: EntryCallback<K, V, U>, thisArg?: any): HashMap<K, U>;
153
+ map<VM>(callbackfn: EntryCallback<K, V, VM>, thisArg?: any): HashMap<K, VM>;
154
154
  /**
155
155
  * Time Complexity: O(n)
156
156
  * Space Complexity: O(n)
@@ -482,7 +482,7 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
482
482
  * @returns a new `LinkedHashMap` object with the values mapped according to the provided callback
483
483
  * function.
484
484
  */
485
- map<NV>(callback: EntryCallback<K, V, NV>, thisArg?: any): LinkedHashMap<K, NV>;
485
+ map<VM>(callback: EntryCallback<K, V, VM>, thisArg?: any): LinkedHashMap<K, VM>;
486
486
  /**
487
487
  * Time Complexity: O(1)
488
488
  * Space Complexity: O(1)