data-structure-typed 1.49.4 → 1.49.6

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 (186) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +15 -26
  3. package/README_zh-CN.md +1 -1
  4. package/benchmark/report.html +14 -23
  5. package/benchmark/report.json +163 -256
  6. package/dist/cjs/data-structures/base/iterable-base.d.ts +1 -1
  7. package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
  8. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +53 -48
  9. package/dist/cjs/data-structures/binary-tree/avl-tree.js +55 -49
  10. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  11. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +154 -143
  12. package/dist/cjs/data-structures/binary-tree/binary-tree.js +211 -198
  13. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  14. package/dist/cjs/data-structures/binary-tree/bst.d.ts +83 -71
  15. package/dist/cjs/data-structures/binary-tree/bst.js +113 -89
  16. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  17. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +37 -35
  18. package/dist/cjs/data-structures/binary-tree/rb-tree.js +62 -59
  19. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  20. package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +46 -55
  21. package/dist/cjs/data-structures/binary-tree/tree-multimap.js +59 -94
  22. package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
  23. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +1 -1
  24. package/dist/cjs/data-structures/graph/abstract-graph.js +3 -2
  25. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  26. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  27. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  28. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  29. package/dist/cjs/data-structures/hash/hash-map.d.ts +1 -1
  30. package/dist/cjs/data-structures/hash/hash-map.js +2 -2
  31. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  32. package/dist/cjs/data-structures/heap/heap.js +2 -3
  33. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  34. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  35. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  36. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  37. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  38. package/dist/cjs/data-structures/matrix/index.d.ts +0 -2
  39. package/dist/cjs/data-structures/matrix/index.js +0 -2
  40. package/dist/cjs/data-structures/matrix/index.js.map +1 -1
  41. package/dist/cjs/data-structures/matrix/matrix.d.ts +128 -10
  42. package/dist/cjs/data-structures/matrix/matrix.js +400 -15
  43. package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
  44. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  45. package/dist/cjs/data-structures/queue/deque.d.ts +2 -2
  46. package/dist/cjs/data-structures/queue/deque.js +5 -7
  47. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  48. package/dist/cjs/data-structures/queue/queue.d.ts +1 -1
  49. package/dist/cjs/interfaces/binary-tree.d.ts +3 -3
  50. package/dist/cjs/types/common.d.ts +3 -3
  51. package/dist/cjs/types/common.js +2 -2
  52. package/dist/cjs/types/common.js.map +1 -1
  53. package/dist/cjs/types/data-structures/base/base.d.ts +1 -1
  54. package/dist/cjs/types/data-structures/heap/heap.d.ts +1 -1
  55. package/dist/cjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  56. package/dist/cjs/utils/utils.d.ts +1 -0
  57. package/dist/cjs/utils/utils.js +6 -1
  58. package/dist/cjs/utils/utils.js.map +1 -1
  59. package/dist/mjs/data-structures/base/iterable-base.d.ts +1 -1
  60. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +53 -48
  61. package/dist/mjs/data-structures/binary-tree/avl-tree.js +57 -50
  62. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +154 -143
  63. package/dist/mjs/data-structures/binary-tree/binary-tree.js +212 -199
  64. package/dist/mjs/data-structures/binary-tree/bst.d.ts +83 -71
  65. package/dist/mjs/data-structures/binary-tree/bst.js +115 -90
  66. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +37 -35
  67. package/dist/mjs/data-structures/binary-tree/rb-tree.js +64 -60
  68. package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +46 -55
  69. package/dist/mjs/data-structures/binary-tree/tree-multimap.js +61 -95
  70. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +1 -1
  71. package/dist/mjs/data-structures/graph/abstract-graph.js +4 -3
  72. package/dist/mjs/data-structures/hash/hash-map.d.ts +1 -1
  73. package/dist/mjs/data-structures/hash/hash-map.js +2 -2
  74. package/dist/mjs/data-structures/heap/heap.js +2 -3
  75. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  76. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +1 -1
  77. package/dist/mjs/data-structures/matrix/index.d.ts +0 -2
  78. package/dist/mjs/data-structures/matrix/index.js +0 -2
  79. package/dist/mjs/data-structures/matrix/matrix.d.ts +128 -10
  80. package/dist/mjs/data-structures/matrix/matrix.js +399 -16
  81. package/dist/mjs/data-structures/queue/deque.d.ts +2 -2
  82. package/dist/mjs/data-structures/queue/deque.js +7 -9
  83. package/dist/mjs/data-structures/queue/queue.d.ts +1 -1
  84. package/dist/mjs/data-structures/queue/queue.js +1 -1
  85. package/dist/mjs/interfaces/binary-tree.d.ts +3 -3
  86. package/dist/mjs/types/common.d.ts +3 -3
  87. package/dist/mjs/types/common.js +2 -2
  88. package/dist/mjs/types/data-structures/base/base.d.ts +1 -1
  89. package/dist/mjs/types/data-structures/heap/heap.d.ts +1 -1
  90. package/dist/mjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  91. package/dist/mjs/utils/utils.d.ts +1 -0
  92. package/dist/mjs/utils/utils.js +4 -0
  93. package/dist/umd/data-structure-typed.js +853 -943
  94. package/dist/umd/data-structure-typed.min.js +2 -2
  95. package/dist/umd/data-structure-typed.min.js.map +1 -1
  96. package/package.json +4 -3
  97. package/src/data-structures/base/index.ts +1 -1
  98. package/src/data-structures/base/iterable-base.ts +7 -10
  99. package/src/data-structures/binary-tree/avl-tree.ts +73 -61
  100. package/src/data-structures/binary-tree/binary-tree.ts +301 -270
  101. package/src/data-structures/binary-tree/bst.ts +139 -115
  102. package/src/data-structures/binary-tree/rb-tree.ts +81 -73
  103. package/src/data-structures/binary-tree/tree-multimap.ts +72 -103
  104. package/src/data-structures/graph/abstract-graph.ts +13 -11
  105. package/src/data-structures/graph/directed-graph.ts +1 -3
  106. package/src/data-structures/graph/map-graph.ts +6 -1
  107. package/src/data-structures/graph/undirected-graph.ts +3 -6
  108. package/src/data-structures/hash/hash-map.ts +18 -16
  109. package/src/data-structures/heap/heap.ts +7 -10
  110. package/src/data-structures/heap/max-heap.ts +2 -1
  111. package/src/data-structures/heap/min-heap.ts +2 -1
  112. package/src/data-structures/linked-list/singly-linked-list.ts +2 -3
  113. package/src/data-structures/matrix/index.ts +0 -2
  114. package/src/data-structures/matrix/matrix.ts +442 -13
  115. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -10
  116. package/src/data-structures/queue/deque.ts +18 -39
  117. package/src/data-structures/queue/queue.ts +1 -1
  118. package/src/interfaces/binary-tree.ts +9 -4
  119. package/src/types/common.ts +5 -5
  120. package/src/types/data-structures/base/base.ts +14 -3
  121. package/src/types/data-structures/base/index.ts +1 -1
  122. package/src/types/data-structures/graph/abstract-graph.ts +4 -2
  123. package/src/types/data-structures/hash/hash-map.ts +3 -3
  124. package/src/types/data-structures/heap/heap.ts +2 -2
  125. package/src/types/data-structures/priority-queue/priority-queue.ts +2 -2
  126. package/src/utils/utils.ts +7 -1
  127. package/test/integration/avl-tree.test.ts +18 -1
  128. package/test/integration/bst.test.ts +2 -2
  129. package/test/performance/data-structures/binary-tree/avl-tree.test.ts +4 -12
  130. package/test/performance/data-structures/binary-tree/binary-tree-overall.test.ts +37 -0
  131. package/test/performance/data-structures/binary-tree/binary-tree.test.ts +6 -16
  132. package/test/performance/data-structures/binary-tree/bst.test.ts +5 -13
  133. package/test/performance/data-structures/binary-tree/rb-tree.test.ts +6 -16
  134. package/test/performance/data-structures/comparison/comparison.test.ts +19 -47
  135. package/test/performance/data-structures/graph/directed-graph.test.ts +3 -14
  136. package/test/performance/data-structures/hash/hash-map.test.ts +14 -38
  137. package/test/performance/data-structures/heap/heap.test.ts +5 -18
  138. package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +0 -2
  139. package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +0 -2
  140. package/test/performance/data-structures/priority-queue/max-priority-queue.test.ts +2 -4
  141. package/test/performance/data-structures/priority-queue/priority-queue.test.ts +4 -14
  142. package/test/performance/data-structures/queue/deque.test.ts +6 -7
  143. package/test/performance/data-structures/queue/queue.test.ts +13 -29
  144. package/test/performance/data-structures/stack/stack.test.ts +6 -18
  145. package/test/performance/data-structures/trie/trie.test.ts +2 -6
  146. package/test/performance/reportor.ts +14 -15
  147. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +14 -3
  148. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +65 -29
  149. package/test/unit/data-structures/binary-tree/bst.test.ts +69 -27
  150. package/test/unit/data-structures/binary-tree/overall.test.ts +16 -18
  151. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +17 -6
  152. package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +37 -21
  153. package/test/unit/data-structures/graph/directed-graph.test.ts +104 -45
  154. package/test/unit/data-structures/graph/undirected-graph.test.ts +57 -40
  155. package/test/unit/data-structures/hash/hash-map.test.ts +48 -28
  156. package/test/unit/data-structures/hash/hash-table.test.ts +0 -4
  157. package/test/unit/data-structures/heap/heap.test.ts +0 -1
  158. package/test/unit/data-structures/heap/min-heap.test.ts +6 -5
  159. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +10 -11
  160. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +3 -4
  161. package/test/unit/data-structures/matrix/matrix.test.ts +345 -52
  162. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +1 -1
  163. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +0 -1
  164. package/test/unit/data-structures/queue/deque.test.ts +0 -6
  165. package/test/unit/data-structures/queue/queue.test.ts +1 -1
  166. package/test/unit/data-structures/stack/stack.test.ts +3 -4
  167. package/test/unit/unrestricted-interconversion.test.ts +50 -44
  168. package/test/utils/performanc.ts +1 -1
  169. package/typedoc.json +30 -0
  170. package/dist/cjs/data-structures/matrix/matrix2d.d.ts +0 -107
  171. package/dist/cjs/data-structures/matrix/matrix2d.js +0 -200
  172. package/dist/cjs/data-structures/matrix/matrix2d.js.map +0 -1
  173. package/dist/cjs/data-structures/matrix/vector2d.d.ts +0 -200
  174. package/dist/cjs/data-structures/matrix/vector2d.js +0 -291
  175. package/dist/cjs/data-structures/matrix/vector2d.js.map +0 -1
  176. package/dist/mjs/data-structures/matrix/matrix2d.d.ts +0 -107
  177. package/dist/mjs/data-structures/matrix/matrix2d.js +0 -196
  178. package/dist/mjs/data-structures/matrix/vector2d.d.ts +0 -200
  179. package/dist/mjs/data-structures/matrix/vector2d.js +0 -289
  180. package/src/data-structures/matrix/matrix2d.ts +0 -211
  181. package/src/data-structures/matrix/vector2d.ts +0 -315
  182. package/test/performance/data-structures/binary-tree/overall.test.ts +0 -0
  183. package/test/performance/data-structures/matrix/matrix2d.test.ts +0 -0
  184. package/test/performance/data-structures/matrix/vector2d.test.ts +0 -0
  185. package/test/unit/data-structures/matrix/matrix2d.test.ts +0 -345
  186. package/test/unit/data-structures/matrix/vector2d.test.ts +0 -171
@@ -5,7 +5,7 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import { BinaryTreeDeleteResult, BTNCallback, BTNExemplar, BTNKeyOrNode, IterationType, RBTNColor, RBTreeOptions, RedBlackTreeNested, RedBlackTreeNodeNested } from '../../types';
8
+ import { BinaryTreeDeleteResult, BTNCallback, IterationType, KeyOrNodeOrEntry, RBTNColor, RBTreeOptions, RedBlackTreeNested, RedBlackTreeNodeNested } from '../../types';
9
9
  import { BST, BSTNode } from './bst';
10
10
  import { IBinaryTree } from '../../interfaces';
11
11
  export declare class RedBlackTreeNode<K = any, V = any, N extends RedBlackTreeNode<K, V, N> = RedBlackTreeNodeNested<K, V>> extends BSTNode<K, V, N> {
@@ -23,16 +23,16 @@ export declare class RedBlackTree<K = any, V = any, N extends RedBlackTreeNode<K
23
23
  Sentinel: N;
24
24
  /**
25
25
  * This is the constructor function for a Red-Black Tree data structure in TypeScript, which
26
- * initializes the tree with optional elements and options.
27
- * @param [elements] - The `elements` parameter is an optional iterable of `BTNExemplar<K, V, N>`
28
- * objects. It represents the initial elements that will be added to the RBTree during its
26
+ * initializes the tree with optional nodes and options.
27
+ * @param [nodes] - The `nodes` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, N>`
28
+ * objects. It represents the initial nodes that will be added to the RBTree during its
29
29
  * construction. If this parameter is provided, the `addMany` method is called to add all the
30
- * elements to the
30
+ * nodes to the
31
31
  * @param [options] - The `options` parameter is an optional object that allows you to customize the
32
32
  * behavior of the RBTree. It is of type `Partial<RBTreeOptions>`, which means that you can provide
33
33
  * only a subset of the properties defined in the `RBTreeOptions` interface.
34
34
  */
35
- constructor(elements?: Iterable<BTNExemplar<K, V, N>>, options?: Partial<RBTreeOptions<K>>);
35
+ constructor(nodes?: Iterable<KeyOrNodeOrEntry<K, V, N>>, options?: Partial<RBTreeOptions<K>>);
36
36
  protected _root: N;
37
37
  get root(): N;
38
38
  protected _size: number;
@@ -59,34 +59,40 @@ export declare class RedBlackTree<K = any, V = any, N extends RedBlackTreeNode<K
59
59
  */
60
60
  createTree(options?: RBTreeOptions<K>): TREE;
61
61
  /**
62
- * The function checks if an exemplar is an instance of the RedBlackTreeNode class.
63
- * @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`.
64
- * @returns a boolean value indicating whether the exemplar is an instance of the RedBlackTreeNode
62
+ * The function `exemplarToNode` takes an keyOrNodeOrEntry and converts it into a node object if possible.
63
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`, where:
64
+ * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
65
+ * `exemplarToNode` function. It represents the value associated with the keyOrNodeOrEntry node. If a value
66
+ * is provided, it will be used when creating the new node. If no value is provided, the new node
67
+ * @returns a node of type N or undefined.
68
+ */
69
+ exemplarToNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V): N | undefined;
70
+ /**
71
+ * The function checks if an keyOrNodeOrEntry is an instance of the RedBlackTreeNode class.
72
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`.
73
+ * @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the RedBlackTreeNode
65
74
  * class.
66
75
  */
67
- isNode(exemplar: BTNExemplar<K, V, N>): exemplar is N;
76
+ isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>): keyOrNodeOrEntry is N;
77
+ /**
78
+ * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
79
+ * Space Complexity: O(1)
80
+ */
81
+ isRealNode(node: N | undefined): node is N;
68
82
  /**
69
83
  * The function "isNotNodeInstance" checks if a potential key is a K.
70
84
  * @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
71
85
  * data type.
72
86
  * @returns a boolean value indicating whether the potentialKey is of type number or not.
73
87
  */
74
- isNotNodeInstance(potentialKey: BTNKeyOrNode<K, N>): potentialKey is K;
88
+ isNotNodeInstance(potentialKey: KeyOrNodeOrEntry<K, V, N>): potentialKey is K;
75
89
  /**
76
- * The function `exemplarToNode` takes an exemplar and converts it into a node object if possible.
77
- * @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`, where:
78
- * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
79
- * `exemplarToNode` function. It represents the value associated with the exemplar node. If a value
80
- * is provided, it will be used when creating the new node. If no value is provided, the new node
81
- * @returns a node of type N or undefined.
82
- */
83
- exemplarToNode(exemplar: BTNExemplar<K, V, N>, value?: V): N | undefined;
84
- /**
85
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
90
+ * Time Complexity: O(log n)
86
91
  * Space Complexity: O(1)
92
+ * on average (where n is the number of nodes in the tree)
87
93
  */
88
94
  /**
89
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
95
+ * Time Complexity: O(log n)
90
96
  * Space Complexity: O(1)
91
97
  *
92
98
  * The `add` function adds a new node to a binary search tree and performs necessary rotations and
@@ -97,13 +103,14 @@ export declare class RedBlackTree<K = any, V = any, N extends RedBlackTreeNode<K
97
103
  * being added to the binary search tree.
98
104
  * @returns The method `add` returns either the newly added node (`N`) or `undefined`.
99
105
  */
100
- add(keyOrNodeOrEntry: BTNExemplar<K, V, N>, value?: V): N | undefined;
106
+ add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V): boolean;
101
107
  /**
102
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
108
+ * Time Complexity: O(log n)
103
109
  * Space Complexity: O(1)
110
+ * on average (where n is the number of nodes in the tree)
104
111
  */
105
112
  /**
106
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
113
+ * Time Complexity: O(log n)
107
114
  * Space Complexity: O(1)
108
115
  *
109
116
  * The `delete` function removes a node from a binary tree based on a given identifier and updates
@@ -118,11 +125,6 @@ export declare class RedBlackTree<K = any, V = any, N extends RedBlackTreeNode<K
118
125
  * @returns an array of `BinaryTreeDeleteResult<N>`.
119
126
  */
120
127
  delete<C extends BTNCallback<N>>(identifier: ReturnType<C> | null | undefined, callback?: C): BinaryTreeDeleteResult<N>[];
121
- /**
122
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
123
- * Space Complexity: O(1)
124
- */
125
- isRealNode(node: N | undefined): node is N;
126
128
  getNode<C extends BTNCallback<N, K>>(identifier: K, callback?: C, beginRoot?: N | undefined, iterationType?: IterationType): N | undefined;
127
129
  getNode<C extends BTNCallback<N, N>>(identifier: N | undefined, callback?: C, beginRoot?: N | undefined, iterationType?: IterationType): N | undefined;
128
130
  getNode<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?: N | undefined, iterationType?: IterationType): N | undefined;
@@ -141,7 +143,7 @@ export declare class RedBlackTree<K = any, V = any, N extends RedBlackTreeNode<K
141
143
  */
142
144
  getPredecessor(x: N): N;
143
145
  /**
144
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
146
+ * Time Complexity: O(1)
145
147
  * Space Complexity: O(1)
146
148
  */
147
149
  clear(): void;
@@ -172,11 +174,11 @@ export declare class RedBlackTree<K = any, V = any, N extends RedBlackTreeNode<K
172
174
  */
173
175
  protected _rightRotate(x: N): void;
174
176
  /**
175
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
177
+ * Time Complexity: O(log n)
176
178
  * Space Complexity: O(1)
177
179
  */
178
180
  /**
179
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
181
+ * Time Complexity: O(log n)
180
182
  * Space Complexity: O(1)
181
183
  *
182
184
  * The function `_fixDelete` is used to fix the red-black tree after a node deletion.
@@ -197,11 +199,11 @@ export declare class RedBlackTree<K = any, V = any, N extends RedBlackTreeNode<K
197
199
  */
198
200
  protected _rbTransplant(u: N, v: N): void;
199
201
  /**
200
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
202
+ * Time Complexity: O(log n)
201
203
  * Space Complexity: O(1)
202
204
  */
203
205
  /**
204
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
206
+ * Time Complexity: O(log n)
205
207
  * Space Complexity: O(1)
206
208
  *
207
209
  * The `_fixInsert` function is used to fix the red-black tree after an insertion operation.
@@ -25,20 +25,20 @@ export class RedBlackTree extends BST {
25
25
  Sentinel = new RedBlackTreeNode(NaN);
26
26
  /**
27
27
  * This is the constructor function for a Red-Black Tree data structure in TypeScript, which
28
- * initializes the tree with optional elements and options.
29
- * @param [elements] - The `elements` parameter is an optional iterable of `BTNExemplar<K, V, N>`
30
- * objects. It represents the initial elements that will be added to the RBTree during its
28
+ * initializes the tree with optional nodes and options.
29
+ * @param [nodes] - The `nodes` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, N>`
30
+ * objects. It represents the initial nodes that will be added to the RBTree during its
31
31
  * construction. If this parameter is provided, the `addMany` method is called to add all the
32
- * elements to the
32
+ * nodes to the
33
33
  * @param [options] - The `options` parameter is an optional object that allows you to customize the
34
34
  * behavior of the RBTree. It is of type `Partial<RBTreeOptions>`, which means that you can provide
35
35
  * only a subset of the properties defined in the `RBTreeOptions` interface.
36
36
  */
37
- constructor(elements, options) {
37
+ constructor(nodes, options) {
38
38
  super([], options);
39
39
  this._root = this.Sentinel;
40
- if (elements)
41
- super.addMany(elements);
40
+ if (nodes)
41
+ super.addMany(nodes);
42
42
  }
43
43
  _root;
44
44
  get root() {
@@ -73,45 +73,28 @@ export class RedBlackTree extends BST {
73
73
  createTree(options) {
74
74
  return new RedBlackTree([], {
75
75
  iterationType: this.iterationType,
76
- variant: this.variant, ...options
76
+ variant: this.variant,
77
+ ...options
77
78
  });
78
79
  }
79
80
  /**
80
- * The function checks if an exemplar is an instance of the RedBlackTreeNode class.
81
- * @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`.
82
- * @returns a boolean value indicating whether the exemplar is an instance of the RedBlackTreeNode
83
- * class.
84
- */
85
- isNode(exemplar) {
86
- return exemplar instanceof RedBlackTreeNode;
87
- }
88
- /**
89
- * The function "isNotNodeInstance" checks if a potential key is a K.
90
- * @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
91
- * data type.
92
- * @returns a boolean value indicating whether the potentialKey is of type number or not.
93
- */
94
- isNotNodeInstance(potentialKey) {
95
- return !(potentialKey instanceof RedBlackTreeNode);
96
- }
97
- /**
98
- * The function `exemplarToNode` takes an exemplar and converts it into a node object if possible.
99
- * @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`, where:
81
+ * The function `exemplarToNode` takes an keyOrNodeOrEntry and converts it into a node object if possible.
82
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`, where:
100
83
  * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
101
- * `exemplarToNode` function. It represents the value associated with the exemplar node. If a value
84
+ * `exemplarToNode` function. It represents the value associated with the keyOrNodeOrEntry node. If a value
102
85
  * is provided, it will be used when creating the new node. If no value is provided, the new node
103
86
  * @returns a node of type N or undefined.
104
87
  */
105
- exemplarToNode(exemplar, value) {
88
+ exemplarToNode(keyOrNodeOrEntry, value) {
106
89
  let node;
107
- if (exemplar === null || exemplar === undefined) {
90
+ if (keyOrNodeOrEntry === null || keyOrNodeOrEntry === undefined) {
108
91
  return;
109
92
  }
110
- else if (this.isNode(exemplar)) {
111
- node = exemplar;
93
+ else if (this.isNode(keyOrNodeOrEntry)) {
94
+ node = keyOrNodeOrEntry;
112
95
  }
113
- else if (this.isEntry(exemplar)) {
114
- const [key, value] = exemplar;
96
+ else if (this.isEntry(keyOrNodeOrEntry)) {
97
+ const [key, value] = keyOrNodeOrEntry;
115
98
  if (key === undefined || key === null) {
116
99
  return;
117
100
  }
@@ -119,20 +102,48 @@ export class RedBlackTree extends BST {
119
102
  node = this.createNode(key, value, RBTNColor.RED);
120
103
  }
121
104
  }
122
- else if (this.isNotNodeInstance(exemplar)) {
123
- node = this.createNode(exemplar, value, RBTNColor.RED);
105
+ else if (this.isNotNodeInstance(keyOrNodeOrEntry)) {
106
+ node = this.createNode(keyOrNodeOrEntry, value, RBTNColor.RED);
124
107
  }
125
108
  else {
126
109
  return;
127
110
  }
128
111
  return node;
129
112
  }
113
+ /**
114
+ * The function checks if an keyOrNodeOrEntry is an instance of the RedBlackTreeNode class.
115
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`.
116
+ * @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the RedBlackTreeNode
117
+ * class.
118
+ */
119
+ isNode(keyOrNodeOrEntry) {
120
+ return keyOrNodeOrEntry instanceof RedBlackTreeNode;
121
+ }
130
122
  /**
131
123
  * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
132
124
  * Space Complexity: O(1)
133
125
  */
126
+ isRealNode(node) {
127
+ if (node === this.Sentinel || node === undefined)
128
+ return false;
129
+ return node instanceof RedBlackTreeNode;
130
+ }
134
131
  /**
135
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
132
+ * The function "isNotNodeInstance" checks if a potential key is a K.
133
+ * @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
134
+ * data type.
135
+ * @returns a boolean value indicating whether the potentialKey is of type number or not.
136
+ */
137
+ isNotNodeInstance(potentialKey) {
138
+ return !(potentialKey instanceof RedBlackTreeNode);
139
+ }
140
+ /**
141
+ * Time Complexity: O(log n)
142
+ * Space Complexity: O(1)
143
+ * on average (where n is the number of nodes in the tree)
144
+ */
145
+ /**
146
+ * Time Complexity: O(log n)
136
147
  * Space Complexity: O(1)
137
148
  *
138
149
  * The `add` function adds a new node to a binary search tree and performs necessary rotations and
@@ -146,7 +157,7 @@ export class RedBlackTree extends BST {
146
157
  add(keyOrNodeOrEntry, value) {
147
158
  const newNode = this.exemplarToNode(keyOrNodeOrEntry, value);
148
159
  if (newNode === undefined)
149
- return;
160
+ return false;
150
161
  newNode.left = this.Sentinel;
151
162
  newNode.right = this.Sentinel;
152
163
  let y = undefined;
@@ -164,7 +175,7 @@ export class RedBlackTree extends BST {
164
175
  if (newNode !== x) {
165
176
  this._replaceNode(x, newNode);
166
177
  }
167
- return;
178
+ return false;
168
179
  }
169
180
  }
170
181
  }
@@ -181,21 +192,23 @@ export class RedBlackTree extends BST {
181
192
  if (newNode.parent === undefined) {
182
193
  newNode.color = RBTNColor.BLACK;
183
194
  this._size++;
184
- return;
195
+ return false;
185
196
  }
186
197
  if (newNode.parent.parent === undefined) {
187
198
  this._size++;
188
- return;
199
+ return false;
189
200
  }
190
201
  this._fixInsert(newNode);
191
202
  this._size++;
203
+ return true;
192
204
  }
193
205
  /**
194
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
206
+ * Time Complexity: O(log n)
195
207
  * Space Complexity: O(1)
208
+ * on average (where n is the number of nodes in the tree)
196
209
  */
197
210
  /**
198
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
211
+ * Time Complexity: O(log n)
199
212
  * Space Complexity: O(1)
200
213
  *
201
214
  * The `delete` function removes a node from a binary tree based on a given identifier and updates
@@ -268,20 +281,11 @@ export class RedBlackTree extends BST {
268
281
  return ans;
269
282
  }
270
283
  /**
271
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
272
- * Space Complexity: O(1)
273
- */
274
- isRealNode(node) {
275
- if (node === this.Sentinel || node === undefined)
276
- return false;
277
- return node instanceof RedBlackTreeNode;
278
- }
279
- /**
280
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
284
+ * Time Complexity: O(log n)
281
285
  * Space Complexity: O(1)
282
286
  */
283
287
  /**
284
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
288
+ * Time Complexity: O(log n)
285
289
  * Space Complexity: O(1)
286
290
  *
287
291
  * The function `getNode` retrieves a single node from a binary tree based on a given identifier and
@@ -332,7 +336,7 @@ export class RedBlackTree extends BST {
332
336
  return y;
333
337
  }
334
338
  /**
335
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
339
+ * Time Complexity: O(1)
336
340
  * Space Complexity: O(1)
337
341
  */
338
342
  clear() {
@@ -413,11 +417,11 @@ export class RedBlackTree extends BST {
413
417
  }
414
418
  }
415
419
  /**
416
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
420
+ * Time Complexity: O(log n)
417
421
  * Space Complexity: O(1)
418
422
  */
419
423
  /**
420
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
424
+ * Time Complexity: O(log n)
421
425
  * Space Complexity: O(1)
422
426
  *
423
427
  * The function `_fixDelete` is used to fix the red-black tree after a node deletion.
@@ -512,11 +516,11 @@ export class RedBlackTree extends BST {
512
516
  v.parent = u.parent;
513
517
  }
514
518
  /**
515
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
519
+ * Time Complexity: O(log n)
516
520
  * Space Complexity: O(1)
517
521
  */
518
522
  /**
519
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
523
+ * Time Complexity: O(log n)
520
524
  * Space Complexity: O(1)
521
525
  *
522
526
  * The `_fixInsert` function is used to fix the red-black tree after an insertion operation.
@@ -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, BSTNKeyOrNode, BTNCallback, BTNExemplar, BTNKeyOrNode, TreeMultimapNested, TreeMultimapNodeNested, TreeMultimapOptions } from '../../types';
8
+ import type { BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, KeyOrNodeOrEntry, TreeMultimapNested, TreeMultimapNodeNested, TreeMultimapOptions } from '../../types';
9
9
  import { IterationType } from '../../types';
10
10
  import { IBinaryTree } from '../../interfaces';
11
11
  import { AVLTree, AVLTreeNode } from './avl-tree';
@@ -27,7 +27,7 @@ export declare class TreeMultimapNode<K = any, V = any, N extends TreeMultimapNo
27
27
  * 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.
28
28
  */
29
29
  export declare class TreeMultimap<K = any, V = any, N extends TreeMultimapNode<K, V, N> = TreeMultimapNode<K, V, TreeMultimapNodeNested<K, V>>, TREE extends TreeMultimap<K, V, N, TREE> = TreeMultimap<K, V, N, TreeMultimapNested<K, V, N>>> extends AVLTree<K, V, N, TREE> implements IBinaryTree<K, V, N, TREE> {
30
- constructor(elements?: Iterable<BTNExemplar<K, V, N>>, options?: Partial<TreeMultimapOptions<K>>);
30
+ constructor(nodes?: Iterable<KeyOrNodeOrEntry<K, V, N>>, options?: Partial<TreeMultimapOptions<K>>);
31
31
  private _count;
32
32
  get count(): number;
33
33
  /**
@@ -42,22 +42,8 @@ export declare class TreeMultimap<K = any, V = any, N extends TreeMultimapNode<K
42
42
  createNode(key: K, value?: V, count?: number): N;
43
43
  createTree(options?: TreeMultimapOptions<K>): TREE;
44
44
  /**
45
- * The function checks if an exemplar is an instance of the TreeMultimapNode class.
46
- * @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`.
47
- * @returns a boolean value indicating whether the exemplar is an instance of the TreeMultimapNode
48
- * class.
49
- */
50
- isNode(exemplar: BTNExemplar<K, V, N>): exemplar is N;
51
- /**
52
- * The function "isNotNodeInstance" checks if a potential key is a K.
53
- * @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
54
- * data type.
55
- * @returns a boolean value indicating whether the potentialKey is of type number or not.
56
- */
57
- isNotNodeInstance(potentialKey: BTNKeyOrNode<K, N>): potentialKey is K;
58
- /**
59
- * The function `exemplarToNode` converts an exemplar object into a node object.
60
- * @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`, which means it
45
+ * The function `exemplarToNode` converts an keyOrNodeOrEntry object into a node object.
46
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`, which means it
61
47
  * can be one of the following:
62
48
  * @param {V} [value] - The `value` parameter is an optional argument that represents the value
63
49
  * associated with the node. It is of type `V`, which can be any data type. If no value is provided,
@@ -66,14 +52,29 @@ export declare class TreeMultimap<K = any, V = any, N extends TreeMultimapNode<K
66
52
  * times the value should be added to the node. If not provided, it defaults to 1.
67
53
  * @returns a node of type `N` or `undefined`.
68
54
  */
69
- exemplarToNode(exemplar: BTNExemplar<K, V, N>, value?: V, count?: number): N | undefined;
55
+ exemplarToNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V, count?: number): N | undefined;
70
56
  /**
71
- * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (AVLTree) has logarithmic time complexity.
72
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
57
+ * The function checks if an keyOrNodeOrEntry is an instance of the TreeMultimapNode class.
58
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`.
59
+ * @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the TreeMultimapNode
60
+ * class.
73
61
  */
62
+ isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>): keyOrNodeOrEntry is N;
74
63
  /**
75
- * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (AVLTree) has logarithmic time complexity.
76
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
64
+ * The function "isNotNodeInstance" checks if a potential key is a K.
65
+ * @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
66
+ * data type.
67
+ * @returns a boolean value indicating whether the potentialKey is of type number or not.
68
+ */
69
+ isNotNodeInstance(potentialKey: KeyOrNodeOrEntry<K, V, N>): potentialKey is K;
70
+ /**
71
+ * Time Complexity: O(log n)
72
+ * Space Complexity: O(1)
73
+ * logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (AVLTree) has logarithmic time complexity. constant space, as it doesn't use additional data structures that scale with input size.
74
+ */
75
+ /**
76
+ * Time Complexity: O(log n)
77
+ * Space Complexity: O(1)
77
78
  *
78
79
  * The function overrides the add method of a binary tree node and adds a new node to the tree.
79
80
  * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be either a key, a node, or an
@@ -87,14 +88,15 @@ export declare class TreeMultimap<K = any, V = any, N extends TreeMultimapNode<K
87
88
  * @returns The method is returning either the newly inserted node or `undefined` if the insertion
88
89
  * was not successful.
89
90
  */
90
- add(keyOrNodeOrEntry: BTNExemplar<K, V, N>, value?: V, count?: number): N | undefined;
91
+ add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V, count?: number): boolean;
91
92
  /**
92
- * Time Complexity: O(k log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (AVLTree) has logarithmic time complexity.
93
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
93
+ * Time Complexity: O(k log n)
94
+ * Space Complexity: O(1)
95
+ * logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (AVLTree) has logarithmic time complexity. constant space, as it doesn't use additional data structures that scale with input size.
94
96
  */
95
97
  /**
96
- * Time Complexity: O(k log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (AVLTree) has logarithmic time complexity.
97
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
98
+ * Time Complexity: O(k log n)
99
+ * Space Complexity: O(1)
98
100
  *
99
101
  * The function overrides the addMany method to add multiple keys, nodes, or entries to a data
100
102
  * structure.
@@ -102,14 +104,15 @@ export declare class TreeMultimap<K = any, V = any, N extends TreeMultimapNode<K
102
104
  * either keys, nodes, or entries.
103
105
  * @returns The method is returning an array of type `N | undefined`.
104
106
  */
105
- addMany(keysOrNodesOrEntries: Iterable<BTNExemplar<K, V, N>>): (N | undefined)[];
107
+ addMany(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, N>>): boolean[];
106
108
  /**
107
- * Time Complexity: O(1) - constant time, as it performs basic pointer assignments.
108
- * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
109
+ * Time Complexity: O(n log n)
110
+ * Space Complexity: O(n)
111
+ * logarithmic time for each insertion, where "n" is the number of nodes in the tree. This is because the method calls the add method for each node. linear space, as it creates an array to store the sorted nodes.
109
112
  */
110
113
  /**
111
- * Time Complexity: O(n log n) - logarithmic time for each insertion, where "n" is the number of nodes in the tree. This is because the method calls the add method for each node.
112
- * Space Complexity: O(n) - linear space, as it creates an array to store the sorted nodes.
114
+ * Time Complexity: O(n log n)
115
+ * Space Complexity: O(n)
113
116
  *
114
117
  * The `perfectlyBalance` function takes a sorted array of nodes and builds a balanced binary search
115
118
  * tree using either a recursive or iterative approach.
@@ -120,12 +123,13 @@ export declare class TreeMultimap<K = any, V = any, N extends TreeMultimapNode<K
120
123
  */
121
124
  perfectlyBalance(iterationType?: IterationType): boolean;
122
125
  /**
123
- * Time Complexity: O(k log n) - logarithmic time for each insertion, where "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted. This is because the method iterates through the keys and calls the add method for each.
124
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
126
+ * Time Complexity: O(k log n)
127
+ * Space Complexity: O(1)
128
+ * logarithmic time for each insertion, where "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted. This is because the method iterates through the keys and calls the add method for each. constant space, as it doesn't use additional data structures that scale with input size.
125
129
  */
126
130
  /**
127
- * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The delete method of the superclass (AVLTree) has logarithmic time complexity.
128
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
131
+ * Time Complexity: O(k log n)
132
+ * Space Complexity: O(1)
129
133
  *
130
134
  * The `delete` function in TypeScript is used to remove a node from a binary tree, taking into
131
135
  * account the count of the node and balancing the tree if necessary.
@@ -144,10 +148,13 @@ export declare class TreeMultimap<K = any, V = any, N extends TreeMultimapNode<K
144
148
  */
145
149
  delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback?: C, ignoreCount?: boolean): BinaryTreeDeleteResult<N>[];
146
150
  /**
147
- * Time Complexity: O(n log n) - logarithmic time for each insertion, where "n" is the number of nodes in the tree. This is because the method calls the add method for each node.
148
- * Space Complexity: O(n) - linear space, as it creates an array to store the sorted nodes.
151
+ * Time Complexity: O(1)
152
+ * Space Complexity: O(1)
149
153
  */
150
154
  /**
155
+ * Time Complexity: O(1)
156
+ * Space Complexity: O(1)
157
+ *
151
158
  * The clear() function clears the contents of a data structure and sets the count to zero.
152
159
  */
153
160
  clear(): void;
@@ -163,22 +170,6 @@ export declare class TreeMultimap<K = any, V = any, N extends TreeMultimapNode<K
163
170
  * @returns The `clone()` method is returning a cloned instance of the `TREE` object.
164
171
  */
165
172
  clone(): TREE;
166
- /**
167
- * Time Complexity: O(1) - constant time, as it performs basic pointer assignments.
168
- * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
169
- *
170
- * The function adds a new node to a binary tree, either as the left child or the right child of a
171
- * given parent node.
172
- * @param {N | undefined} newNode - The `newNode` parameter represents the node that needs to be
173
- * added to the binary tree. It can be of type `N` (which represents a node in the binary tree) or
174
- * `undefined` if there is no node to add.
175
- * @param {K | N | undefined} parent - The `parent` parameter represents the parent node to
176
- * which the new node will be added as a child. It can be either a node object (`N`) or a key value
177
- * (`K`).
178
- * @returns The method `_addTo` returns either the `parent.left` or `parent.right` node that was
179
- * added, or `undefined` if no node was added.
180
- */
181
- protected _addTo(newNode: N | undefined, parent: BSTNKeyOrNode<K, N>): N | undefined;
182
173
  /**
183
174
  * The `_swapProperties` function swaps the key, value, count, and height properties between two nodes.
184
175
  * @param {K | N | undefined} srcNode - The `srcNode` parameter represents the source node from