heap-typed 1.51.7 → 1.51.9

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 (56) hide show
  1. package/README.md +72 -80
  2. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +103 -74
  3. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +116 -93
  4. package/dist/data-structures/binary-tree/avl-tree.d.ts +82 -62
  5. package/dist/data-structures/binary-tree/avl-tree.js +90 -71
  6. package/dist/data-structures/binary-tree/binary-tree.d.ts +318 -233
  7. package/dist/data-structures/binary-tree/binary-tree.js +492 -392
  8. package/dist/data-structures/binary-tree/bst.d.ts +204 -251
  9. package/dist/data-structures/binary-tree/bst.js +256 -358
  10. package/dist/data-structures/binary-tree/rb-tree.d.ts +74 -85
  11. package/dist/data-structures/binary-tree/rb-tree.js +111 -119
  12. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +92 -76
  13. package/dist/data-structures/binary-tree/tree-multi-map.js +105 -93
  14. package/dist/data-structures/graph/abstract-graph.d.ts +10 -15
  15. package/dist/data-structures/graph/abstract-graph.js +10 -15
  16. package/dist/data-structures/hash/hash-map.d.ts +31 -38
  17. package/dist/data-structures/hash/hash-map.js +40 -55
  18. package/dist/data-structures/heap/heap.d.ts +1 -3
  19. package/dist/data-structures/queue/deque.d.ts +2 -3
  20. package/dist/data-structures/queue/deque.js +2 -3
  21. package/dist/data-structures/trie/trie.d.ts +1 -1
  22. package/dist/data-structures/trie/trie.js +1 -1
  23. package/dist/interfaces/binary-tree.d.ts +7 -7
  24. package/dist/types/common.d.ts +2 -3
  25. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +4 -3
  26. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +4 -3
  27. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +6 -5
  28. package/dist/types/data-structures/binary-tree/bst.d.ts +6 -5
  29. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +4 -3
  30. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +4 -3
  31. package/dist/types/utils/utils.d.ts +10 -1
  32. package/dist/utils/utils.d.ts +2 -1
  33. package/dist/utils/utils.js +27 -1
  34. package/package.json +2 -2
  35. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +142 -100
  36. package/src/data-structures/binary-tree/avl-tree.ts +109 -80
  37. package/src/data-structures/binary-tree/binary-tree.ts +556 -433
  38. package/src/data-structures/binary-tree/bst.ts +286 -375
  39. package/src/data-structures/binary-tree/rb-tree.ts +132 -125
  40. package/src/data-structures/binary-tree/tree-multi-map.ts +129 -102
  41. package/src/data-structures/graph/abstract-graph.ts +10 -10
  42. package/src/data-structures/hash/hash-map.ts +42 -49
  43. package/src/data-structures/heap/heap.ts +1 -1
  44. package/src/data-structures/queue/deque.ts +2 -2
  45. package/src/data-structures/queue/queue.ts +1 -1
  46. package/src/data-structures/trie/trie.ts +2 -2
  47. package/src/interfaces/binary-tree.ts +11 -9
  48. package/src/types/common.ts +2 -3
  49. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +4 -3
  50. package/src/types/data-structures/binary-tree/avl-tree.ts +4 -3
  51. package/src/types/data-structures/binary-tree/binary-tree.ts +7 -6
  52. package/src/types/data-structures/binary-tree/bst.ts +6 -5
  53. package/src/types/data-structures/binary-tree/rb-tree.ts +4 -3
  54. package/src/types/data-structures/binary-tree/tree-multi-map.ts +4 -3
  55. package/src/types/utils/utils.ts +14 -1
  56. package/src/utils/utils.ts +20 -1
package/README.md CHANGED
@@ -45,8 +45,8 @@ Max Heap
45
45
  import {MinHeap, MaxHeap} from 'data-structure-typed';
46
46
  // /* or if you prefer */ import {MinHeap, MaxHeap} from 'heap-typed';
47
47
 
48
- const minNumHeap = new MinHeap<number>();
49
- minNumHeap.add(1).add(6).add(2).add(0).add(5).add(9);
48
+ const minNumHeap = new MinHeap<number>([1, 6, 2, 0, 5]);
49
+ minNumHeap.add(9);
50
50
  minNumHeap.has(1) // true
51
51
  minNumHeap.has(2) // true
52
52
  minNumHeap.poll() // 0
@@ -54,6 +54,7 @@ Max Heap
54
54
  minNumHeap.peek() // 2
55
55
  minNumHeap.has(1); // false
56
56
  minNumHeap.has(2); // true
57
+
57
58
  const arrFromHeap = minNumHeap.toArray();
58
59
  arrFromHeap.length // 4
59
60
  arrFromHeap[0] // 2
@@ -61,38 +62,33 @@ Max Heap
61
62
  arrFromHeap[2] // 9
62
63
  arrFromHeap[3] // 6
63
64
  minNumHeap.sort() // [2, 5, 6, 9]
65
+
66
+ const maxHeap = new MaxHeap<{ keyA: string }>([], {comparator: (a, b) => b.keyA - a.keyA});
67
+ const obj1 = {keyA: 'a1'}, obj6 = {keyA: 'a6'}, obj5 = {keyA: 'a5'}, obj2 = {keyA: 'a2'},
68
+ obj0 = {keyA: 'a0'}, obj9 = {keyA: 'a9'};
64
69
 
70
+ maxHeap.add(obj1);
71
+ maxHeap.has(obj1) // true
72
+ maxHeap.has(obj9) // false
73
+ maxHeap.add(obj6);
74
+ maxHeap.has(obj6) // true
75
+ maxHeap.add(obj5);
76
+ maxHeap.add(obj2);
77
+ maxHeap.add(obj0);
78
+ maxHeap.add(obj9);
79
+ maxHeap.has(obj9) // true
65
80
 
66
- const maxHeap = new MaxHeap<{ keyA: string }>();
67
- const myObj1 = {keyA: 'a1'}, myObj6 = {keyA: 'a6'}, myObj5 = {keyA: 'a5'}, myObj2 = {keyA: 'a2'},
68
- myObj0 = {keyA: 'a0'}, myObj9 = {keyA: 'a9'};
69
- maxHeap.add(1, myObj1);
70
- maxHeap.has(myObj1) // true
71
- maxHeap.has(myObj9) // false
72
- maxHeap.add(6, myObj6);
73
- maxHeap.has(myObj6) // true
74
- maxHeap.add(5, myObj5);
75
- maxHeap.has(myObj5) // true
76
- maxHeap.add(2, myObj2);
77
- maxHeap.has(myObj2) // true
78
- maxHeap.has(myObj6) // true
79
- maxHeap.add(0, myObj0);
80
- maxHeap.has(myObj0) // true
81
- maxHeap.has(myObj9) // false
82
- maxHeap.add(9, myObj9);
83
- maxHeap.has(myObj9) // true
84
-
85
- const peek9 = maxHeap.peek(true);
86
- peek9 && peek9.val && peek9.val.keyA // 'a9'
81
+ const peek9 = maxHeap.peek();
82
+ console.log(peek9.keyA) // 'a9'
87
83
 
88
- const heapToArr = maxHeap.toArray(true);
89
- heapToArr.map(item => item?.val?.keyA) // ['a9', 'a2', 'a6', 'a1', 'a0', 'a5']
84
+ const heapToArr = maxHeap.toArray();
85
+ console.log(heapToArr.map(ele => ele?.keyA)); // ['a9', 'a2', 'a6', 'a1', 'a0', 'a5']
90
86
 
91
87
  const values = ['a9', 'a6', 'a5', 'a2', 'a1', 'a0'];
92
88
  let i = 0;
93
89
  while (maxHeap.size > 0) {
94
- const polled = maxHeap.poll(true);
95
- polled && polled.val && polled.val.keyA // values[i]
90
+ const polled = maxHeap.poll();
91
+ console.log(polled.keyA) // values[i]
96
92
  i++;
97
93
  }
98
94
  ```
@@ -100,59 +96,55 @@ Max Heap
100
96
  #### JS
101
97
 
102
98
  ```javascript
103
- const {MinHeap, MaxHeap} = require('data-structure-typed');
104
- // /* or if you prefer */ const {MinHeap, MaxHeap} = require('heap-typed');
105
-
106
- const minNumHeap = new MinHeap();
107
- minNumHeap.add(1).add(6).add(2).add(0).add(5).add(9);
108
- minNumHeap.has(1) // true
109
- minNumHeap.has(2) // true
110
- minNumHeap.poll() // 0
111
- minNumHeap.poll() // 1
112
- minNumHeap.peek() // 2
113
- minNumHeap.has(1); // false
114
- minNumHeap.has(2); // true
115
- const arrFromHeap = minNumHeap.toArray();
116
- arrFromHeap.length // 4
117
- arrFromHeap[0] // 2
118
- arrFromHeap[1] // 5
119
- arrFromHeap[2] // 9
120
- arrFromHeap[3] // 6
121
- minNumHeap.sort() // [2, 5, 6, 9]
122
-
123
-
124
- const maxHeap = new MaxHeap();
125
- const myObj1 = {keyA: 'a1'}, myObj6 = {keyA: 'a6'}, myObj5 = {keyA: 'a5'}, myObj2 = {keyA: 'a2'},
126
- myObj0 = {keyA: 'a0'}, myObj9 = {keyA: 'a9'};
127
- maxHeap.add(1, myObj1);
128
- maxHeap.has(myObj1) // true
129
- maxHeap.has(myObj9) // false
130
- maxHeap.add(6, myObj6);
131
- maxHeap.has(myObj6) // true
132
- maxHeap.add(5, myObj5);
133
- maxHeap.has(myObj5) // true
134
- maxHeap.add(2, myObj2);
135
- maxHeap.has(myObj2) // true
136
- maxHeap.has(myObj6) // true
137
- maxHeap.add(0, myObj0);
138
- maxHeap.has(myObj0) // true
139
- maxHeap.has(myObj9) // false
140
- maxHeap.add(9, myObj9);
141
- maxHeap.has(myObj9) // true
142
-
143
- const peek9 = maxHeap.peek(true);
144
- peek9 && peek9.val && peek9.val.keyA // 'a9'
145
-
146
- const heapToArr = maxHeap.toArray(true);
147
- heapToArr.map(item => item?.val?.keyA) // ['a9', 'a2', 'a6', 'a1', 'a0', 'a5']
148
-
149
- const values = ['a9', 'a6', 'a5', 'a2', 'a1', 'a0'];
150
- let i = 0;
151
- while (maxHeap.size > 0) {
152
- const polled = maxHeap.poll(true);
153
- polled && polled.val && polled.val.keyA // values[i]
154
- i++;
155
- }
99
+ const {MinHeap, MaxHeap} = require('data-structure-typed');
100
+ // /* or if you prefer */ const {MinHeap, MaxHeap} = require('heap-typed');
101
+
102
+ const minNumHeap = new MinHeap([1, 6, 2, 0, 5]);
103
+ minNumHeap.add(9);
104
+ minNumHeap.has(1) // true
105
+ minNumHeap.has(2) // true
106
+ minNumHeap.poll() // 0
107
+ minNumHeap.poll() // 1
108
+ minNumHeap.peek() // 2
109
+ minNumHeap.has(1); // false
110
+ minNumHeap.has(2); // true
111
+
112
+ const arrFromHeap = minNumHeap.toArray();
113
+ arrFromHeap.length // 4
114
+ arrFromHeap[0] // 2
115
+ arrFromHeap[1] // 5
116
+ arrFromHeap[2] // 9
117
+ arrFromHeap[3] // 6
118
+ minNumHeap.sort() // [2, 5, 6, 9]
119
+
120
+ const maxHeap = new MaxHeap([], {comparator: (a, b) => b.keyA - a.keyA});
121
+ const obj1 = {keyA: 'a1'}, obj6 = {keyA: 'a6'}, obj5 = {keyA: 'a5'}, obj2 = {keyA: 'a2'},
122
+ obj0 = {keyA: 'a0'}, obj9 = {keyA: 'a9'};
123
+
124
+ maxHeap.add(obj1);
125
+ maxHeap.has(obj1) // true
126
+ maxHeap.has(obj9) // false
127
+ maxHeap.add(obj6);
128
+ maxHeap.has(obj6) // true
129
+ maxHeap.add(obj5);
130
+ maxHeap.add(obj2);
131
+ maxHeap.add(obj0);
132
+ maxHeap.add(obj9);
133
+ maxHeap.has(obj9) // true
134
+
135
+ const peek9 = maxHeap.peek();
136
+ console.log(peek9.keyA) // 'a9'
137
+
138
+ const heapToArr = maxHeap.toArray();
139
+ console.log(heapToArr.map(ele => ele?.keyA)); // ['a9', 'a2', 'a6', 'a1', 'a0', 'a5']
140
+
141
+ const values = ['a9', 'a6', 'a5', 'a2', 'a1', 'a0'];
142
+ let i = 0;
143
+ while (maxHeap.size > 0) {
144
+ const polled = maxHeap.poll();
145
+ console.log(polled.keyA) // values[i]
146
+ i++;
147
+ }
156
148
  ```
157
149
 
158
150
 
@@ -5,10 +5,11 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { AVLTreeMultiMapNested, AVLTreeMultiMapNodeNested, AVLTreeMultiMapOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, IterationType, KeyOrNodeOrEntry } from '../../types';
8
+ import type { AVLTreeMultiMapNested, AVLTreeMultiMapNodeNested, AVLTreeMultiMapOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, Comparable, IterationType, KeyOrNodeOrEntry } from '../../types';
9
+ import { BTNEntry } from '../../types';
9
10
  import { IBinaryTree } from '../../interfaces';
10
11
  import { AVLTree, AVLTreeNode } from './avl-tree';
11
- export declare class AVLTreeMultiMapNode<K = any, V = any, NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNodeNested<K, V>> extends AVLTreeNode<K, V, NODE> {
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
13
  /**
13
14
  * The constructor function initializes a BinaryTreeNode object with a key, value, and count.
14
15
  * @param {K} key - The `key` parameter is of type `K` and represents the unique identifier
@@ -36,8 +37,16 @@ export declare class AVLTreeMultiMapNode<K = any, V = any, NODE extends AVLTreeM
36
37
  /**
37
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.
38
39
  */
39
- export declare class AVLTreeMultiMap<K = any, V = any, NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNodeNested<K, V>>, TREE extends AVLTreeMultiMap<K, V, NODE, TREE> = AVLTreeMultiMap<K, V, NODE, AVLTreeMultiMapNested<K, V, NODE>>> extends AVLTree<K, V, NODE, TREE> implements IBinaryTree<K, V, NODE, TREE> {
40
- constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, options?: AVLTreeMultiMapOptions<K>);
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> {
41
+ /**
42
+ * The constructor initializes a new AVLTreeMultiMap object with optional initial elements.
43
+ * @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
44
+ * iterable object that can contain either keys, nodes, entries, or raw elements.
45
+ * @param [options] - The `options` parameter is an optional object that can be used to customize the
46
+ * behavior of the AVLTreeMultiMap. It can include properties such as `compareKeys` and
47
+ * `compareValues` functions to define custom comparison logic for keys and values, respectively.
48
+ */
49
+ constructor(keysOrNodesOrEntriesOrRawElements?: Iterable<R | KeyOrNodeOrEntry<K, V, NODE>>, options?: AVLTreeMultiMapOptions<K, V, R>);
41
50
  protected _count: number;
42
51
  /**
43
52
  * The function calculates the sum of the count property of all nodes in a tree using depth-first
@@ -59,44 +68,46 @@ export declare class AVLTreeMultiMap<K = any, V = any, NODE extends AVLTreeMulti
59
68
  */
60
69
  getComputedCount(): number;
61
70
  /**
62
- * The function creates a new BSTNode with the given key, value, and count.
63
- * @param {K} key - The key parameter is the unique identifier for the binary tree node. It is used to
64
- * distinguish one node from another in the tree.
65
- * @param {NODE} value - The `value` parameter represents the value that will be stored in the binary search tree node.
66
- * @param {number} [count] - The "count" parameter is an optional parameter of type number. It represents the number of
67
- * occurrences of the value in the binary search tree node. If not provided, the count will default to 1.
68
- * @returns A new instance of the BSTNode class with the specified key, value, and count (if provided).
71
+ * The function creates a new AVLTreeMultiMapNode with the specified key, value, and count.
72
+ * @param {K} key - The key parameter represents the key of the node being created. It is of type K,
73
+ * which is a generic type that can be replaced with any specific type when using the function.
74
+ * @param {V} [value] - The `value` parameter is an optional parameter that represents the value
75
+ * associated with the key in the node. It is of type `V`, which can be any data type.
76
+ * @param {number} [count] - The `count` parameter represents the number of occurrences of a
77
+ * key-value pair in the AVLTreeMultiMapNode. It is an optional parameter, so it can be omitted when
78
+ * calling the `createNode` method. If provided, it specifies the initial count for the node.
79
+ * @returns a new instance of the AVLTreeMultiMapNode class, casted as NODE.
69
80
  */
70
81
  createNode(key: K, value?: V, count?: number): NODE;
71
82
  /**
72
83
  * The function creates a new AVLTreeMultiMap object with the specified options and returns it.
73
84
  * @param [options] - The `options` parameter is an optional object that contains additional
74
- * configuration options for creating the `AVLTreeMultiMap` object. It can include properties such as
75
- * `iterationType` and `variant`, which are used to specify the type of iteration and the variant of
76
- * the tree, respectively. These properties can be
77
- * @returns a new instance of the `AVLTreeMultiMap` class, with the provided options merged with the
78
- * default options. The returned value is casted as `TREE`.
79
- */
80
- createTree(options?: AVLTreeMultiMapOptions<K>): TREE;
81
- /**
82
- * The function `keyValueOrEntryToNode` converts an keyOrNodeOrEntry object into a node object.
83
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`, which means it
84
- * can be one of the following:
85
- * @param {V} [value] - The `value` parameter is an optional argument that represents the value
86
- * associated with the node. It is of type `V`, which can be any data type. If no value is provided,
87
- * it defaults to `undefined`.
85
+ * configuration options for creating the AVLTreeMultiMap. It can have the following properties:
86
+ * @returns a new instance of the AVLTreeMultiMap class, with the specified options, as a TREE
87
+ * object.
88
+ */
89
+ createTree(options?: AVLTreeMultiMapOptions<K, V, R>): TREE;
90
+ /**
91
+ * The function checks if the input is an instance of AVLTreeMultiMapNode.
92
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
93
+ * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
94
+ * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
95
+ * an instance of the `AVLTreeMultiMapNode` class.
96
+ */
97
+ isNode(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntryOrRawElement is NODE;
98
+ /**
99
+ * The function `keyValueOrEntryOrRawElementToNode` converts a key, value, entry, or raw element into
100
+ * a node object.
101
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
102
+ * `keyOrNodeOrEntryOrRawElement` parameter can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
103
+ * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
104
+ * `override` function. It represents the value associated with the key in the data structure. If no
105
+ * value is provided, it will default to `undefined`.
88
106
  * @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
89
- * times the value should be added to the node. If not provided, it defaults to 1.
90
- * @returns a node of type `NODE` or `undefined`.
91
- */
92
- keyValueOrEntryToNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V, count?: number): NODE | undefined;
93
- /**
94
- * The function checks if an keyOrNodeOrEntry is an instance of the AVLTreeMultiMapNode class.
95
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`.
96
- * @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the AVLTreeMultiMapNode
97
- * class.
107
+ * times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
108
+ * @returns either a NODE object or undefined.
98
109
  */
99
- isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntry is NODE;
110
+ keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>, value?: V, count?: number): NODE | undefined;
100
111
  /**
101
112
  * Time Complexity: O(log n)
102
113
  * Space Complexity: O(1)
@@ -105,19 +116,20 @@ export declare class AVLTreeMultiMap<K = any, V = any, NODE extends AVLTreeMulti
105
116
  * Time Complexity: O(log n)
106
117
  * Space Complexity: O(1)
107
118
  *
108
- * The function overrides the add method of a binary tree node and adds a new node to the tree.
109
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be either a key, a node, or an
110
- * entry. It represents the key, node, or entry that you want to add to the binary tree.
119
+ * The function overrides the add method of a TypeScript class to add a new node to a data structure
120
+ * and update the count.
121
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
122
+ * `keyOrNodeOrEntryOrRawElement` parameter can accept a value of type `R`, which can be any type. It
123
+ * can also accept a value of type `KeyOrNodeOrEntry<K, V, NODE>`, which represents a key, node,
124
+ * entry, or raw element
111
125
  * @param {V} [value] - The `value` parameter represents the value associated with the key in the
112
- * binary tree node. It is an optional parameter, meaning it can be omitted when calling the `add`
113
- * method.
126
+ * data structure. It is an optional parameter, so it can be omitted if not needed.
114
127
  * @param [count=1] - The `count` parameter represents the number of times the key-value pair should
115
- * be added to the binary tree. By default, it is set to 1, meaning that the key-value pair will be
116
- * added once. However, you can specify a different value for `count` if you want to add
117
- * @returns The method is returning either the newly inserted node or `undefined` if the insertion
118
- * was not successful.
128
+ * be added to the data structure. By default, it is set to 1, meaning that the key-value pair will
129
+ * be added once. However, you can specify a different value for `count` if you want to add
130
+ * @returns a boolean value.
119
131
  */
120
- add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V, count?: number): boolean;
132
+ add(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>, value?: V, count?: number): boolean;
121
133
  /**
122
134
  * Time Complexity: O(log n)
123
135
  * Space Complexity: O(1)
@@ -126,19 +138,19 @@ export declare class AVLTreeMultiMap<K = any, V = any, NODE extends AVLTreeMulti
126
138
  * Time Complexity: O(log n)
127
139
  * Space Complexity: O(1)
128
140
  *
129
- * The `delete` function in TypeScript is used to remove a node from a binary tree, taking into
130
- * account the count of the node and balancing the tree if necessary.
131
- * @param identifier - The identifier is the value or key that is used to identify the node that
132
- * needs to be deleted from the binary tree. It can be of any type that is returned by the callback
141
+ * The `delete` function in a binary tree data structure deletes a node based on its identifier and
142
+ * returns the deleted node along with the parent node that needs to be balanced.
143
+ * @param identifier - The identifier parameter is the value used to identify the node that needs to
144
+ * be deleted from the binary tree. It can be of any type and is the return type of the callback
133
145
  * function.
134
- * @param {C} callback - The `callback` parameter is a function that is used to determine if a node
135
- * should be deleted. It is optional and defaults to a default callback function. The `callback`
136
- * function takes one parameter, which is the identifier of the node, and returns a value that is
137
- * used to identify the node to
146
+ * @param {C} callback - The `callback` parameter is a function that is used to determine the
147
+ * equality of nodes in the binary tree. It is optional and has a default value of
148
+ * `this._DEFAULT_CALLBACK`. The `callback` function takes a single argument, which is the identifier
149
+ * of a node, and returns a value that
138
150
  * @param [ignoreCount=false] - A boolean flag indicating whether to ignore the count of the node
139
151
  * being deleted. If set to true, the count of the node will not be considered and the node will be
140
- * deleted regardless of its count. If set to false (default), the count of the node will be
141
- * decremented by 1 and
152
+ * deleted regardless of its count. If set to false (default), the count of the node will be taken
153
+ * into account and the node
142
154
  * @returns an array of `BinaryTreeDeleteResult<NODE>`.
143
155
  */
144
156
  delete<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback?: C, ignoreCount?: boolean): BinaryTreeDeleteResult<NODE>[];
@@ -150,7 +162,8 @@ export declare class AVLTreeMultiMap<K = any, V = any, NODE extends AVLTreeMulti
150
162
  * Time Complexity: O(1)
151
163
  * Space Complexity: O(1)
152
164
  *
153
- * The clear() function clears the contents of a data structure and sets the count to zero.
165
+ * The "clear" function overrides the parent class's "clear" function and also resets the count to
166
+ * zero.
154
167
  */
155
168
  clear(): void;
156
169
  /**
@@ -160,13 +173,14 @@ export declare class AVLTreeMultiMap<K = any, V = any, NODE extends AVLTreeMulti
160
173
  /**
161
174
  * Time Complexity: O(n log n)
162
175
  * Space Complexity: O(log n)
163
- *
164
176
  * The `perfectlyBalance` function takes a sorted array of nodes and builds a balanced binary search
165
177
  * tree using either a recursive or iterative approach.
166
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
167
- * type of iteration to use when building the balanced binary search tree. It can have two possible
168
- * values:
169
- * @returns a boolean value.
178
+ * @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
179
+ * specifies the type of iteration to use when building the balanced binary search tree. It has a
180
+ * default value of `this.iterationType`, which means it will use the iteration type currently set in
181
+ * the object.
182
+ * @returns The function `perfectlyBalance` returns a boolean value. It returns `true` if the
183
+ * balancing operation is successful, and `false` if there are no nodes to balance.
170
184
  */
171
185
  perfectlyBalance(iterationType?: IterationType): boolean;
172
186
  /**
@@ -177,27 +191,42 @@ export declare class AVLTreeMultiMap<K = any, V = any, NODE extends AVLTreeMulti
177
191
  * Time complexity: O(n)
178
192
  * Space complexity: O(n)
179
193
  *
180
- * The `clone` function creates a deep copy of a tree object.
194
+ * The function overrides the clone method to create a deep copy of a tree object.
181
195
  * @returns The `clone()` method is returning a cloned instance of the `TREE` object.
182
196
  */
183
197
  clone(): TREE;
184
198
  /**
185
- * The `_swapProperties` function swaps the key, value, count, and height properties between two nodes.
186
- * @param {K | NODE | undefined} srcNode - The `srcNode` parameter represents the source node from
187
- * which the values will be swapped. It can be of type `K`, `NODE`, or `undefined`.
188
- * @param {K | NODE | undefined} destNode - The `destNode` parameter represents the destination
189
- * node where the values from the source node will be swapped to.
190
- * @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined`
191
- * if either `srcNode` or `destNode` is undefined.
199
+ * Time Complexity: O(1)
200
+ * Space Complexity: O(1)
192
201
  */
193
- protected _swapProperties(srcNode: BSTNKeyOrNode<K, NODE>, destNode: BSTNKeyOrNode<K, NODE>): NODE | undefined;
194
202
  /**
203
+ * Time Complexity: O(1)
204
+ * Space Complexity: O(1)
205
+ *
206
+ * The `_swapProperties` function swaps the properties (key, value, count, height) between two nodes
207
+ * in a binary search tree.
208
+ * @param {R | BSTNKeyOrNode<K, NODE>} srcNode - The `srcNode` parameter represents the source node
209
+ * that will be swapped with the `destNode`.
210
+ * @param {R | BSTNKeyOrNode<K, NODE>} destNode - The `destNode` parameter represents the destination
211
+ * node where the properties will be swapped with the source node.
212
+ * @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
213
+ * If either `srcNode` or `destNode` is undefined, it returns `undefined`.
214
+ */
215
+ protected _swapProperties(srcNode: R | BSTNKeyOrNode<K, NODE>, destNode: R | BSTNKeyOrNode<K, NODE>): NODE | undefined;
216
+ /**
217
+ * Time Complexity: O(1)
218
+ * Space Complexity: O(1)
219
+ */
220
+ /**
221
+ * Time Complexity: O(1)
222
+ * Space Complexity: O(1)
223
+ *
195
224
  * The function replaces an old node with a new node and updates the count property of the new node.
196
- * @param {NODE} oldNode - The `oldNode` parameter is of type `NODE` and represents the node that
197
- * needs to be replaced in a data structure.
198
- * @param {NODE} newNode - The `newNode` parameter is an object of type `NODE`.
225
+ * @param {NODE} oldNode - The oldNode parameter represents the node that needs to be replaced in the
226
+ * data structure. It is of type NODE.
227
+ * @param {NODE} newNode - The `newNode` parameter is an instance of the `NODE` class.
199
228
  * @returns The method is returning the result of calling the `_replaceNode` method from the
200
- * superclass, after updating the `count` property of the `newNode` object.
229
+ * superclass, which is of type `NODE`.
201
230
  */
202
231
  protected _replaceNode(oldNode: NODE, newNode: NODE): NODE;
203
232
  }