data-structure-typed 1.49.0 → 1.49.2

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 (195) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +16 -16
  3. package/README_zh-CN.md +2 -2
  4. package/benchmark/report.html +46 -1
  5. package/benchmark/report.json +457 -22
  6. package/dist/cjs/data-structures/base/iterable-base.d.ts +11 -0
  7. package/dist/cjs/data-structures/base/iterable-base.js +21 -0
  8. package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
  9. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +10 -12
  10. package/dist/cjs/data-structures/binary-tree/avl-tree.js +3 -4
  11. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  12. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +58 -58
  13. package/dist/cjs/data-structures/binary-tree/binary-tree.js +6 -6
  14. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  15. package/dist/cjs/data-structures/binary-tree/bst.d.ts +15 -15
  16. package/dist/cjs/data-structures/binary-tree/bst.js +3 -3
  17. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  18. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +11 -11
  19. package/dist/cjs/data-structures/binary-tree/rb-tree.js +5 -6
  20. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  21. package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +14 -14
  22. package/dist/cjs/data-structures/binary-tree/tree-multimap.js +3 -3
  23. package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
  24. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +9 -3
  25. package/dist/cjs/data-structures/graph/abstract-graph.js +27 -31
  26. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  27. package/dist/cjs/data-structures/graph/directed-graph.d.ts +8 -1
  28. package/dist/cjs/data-structures/graph/directed-graph.js +1 -8
  29. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  30. package/dist/cjs/data-structures/graph/map-graph.d.ts +1 -1
  31. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +8 -1
  32. package/dist/cjs/data-structures/graph/undirected-graph.js +1 -8
  33. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  34. package/dist/cjs/data-structures/hash/hash-map.d.ts +22 -10
  35. package/dist/cjs/data-structures/hash/hash-map.js +28 -16
  36. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  37. package/dist/cjs/data-structures/hash/hash-table.d.ts +2 -2
  38. package/dist/cjs/data-structures/hash/hash-table.js.map +1 -1
  39. package/dist/cjs/data-structures/heap/heap.d.ts +20 -38
  40. package/dist/cjs/data-structures/heap/heap.js +22 -42
  41. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  42. package/dist/cjs/data-structures/heap/max-heap.d.ts +11 -1
  43. package/dist/cjs/data-structures/heap/max-heap.js +10 -7
  44. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  45. package/dist/cjs/data-structures/heap/min-heap.d.ts +11 -1
  46. package/dist/cjs/data-structures/heap/min-heap.js +10 -7
  47. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  48. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +95 -95
  49. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +132 -136
  50. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  51. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +18 -23
  52. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +42 -49
  53. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  54. package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
  55. package/dist/cjs/data-structures/linked-list/skip-linked-list.js +2 -2
  56. package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
  57. package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +1 -1
  58. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +0 -7
  59. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  60. package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +1 -1
  61. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +0 -7
  62. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  63. package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +9 -1
  64. package/dist/cjs/data-structures/priority-queue/priority-queue.js +8 -7
  65. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  66. package/dist/cjs/data-structures/queue/deque.d.ts +76 -80
  67. package/dist/cjs/data-structures/queue/deque.js +106 -122
  68. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  69. package/dist/cjs/data-structures/queue/queue.d.ts +30 -16
  70. package/dist/cjs/data-structures/queue/queue.js +31 -24
  71. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  72. package/dist/cjs/data-structures/stack/stack.d.ts +17 -8
  73. package/dist/cjs/data-structures/stack/stack.js +9 -9
  74. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  75. package/dist/cjs/data-structures/trie/trie.d.ts +14 -5
  76. package/dist/cjs/data-structures/trie/trie.js +13 -13
  77. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  78. package/dist/cjs/interfaces/binary-tree.d.ts +4 -4
  79. package/dist/cjs/types/common.d.ts +32 -8
  80. package/dist/cjs/types/common.js +22 -1
  81. package/dist/cjs/types/common.js.map +1 -1
  82. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -24
  83. package/dist/cjs/types/data-structures/binary-tree/binary-tree.js +0 -22
  84. package/dist/cjs/types/data-structures/binary-tree/binary-tree.js.map +1 -1
  85. package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +1 -1
  86. package/dist/cjs/types/data-structures/binary-tree/tree-multimap.d.ts +1 -1
  87. package/dist/mjs/data-structures/base/iterable-base.d.ts +11 -0
  88. package/dist/mjs/data-structures/base/iterable-base.js +21 -0
  89. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +10 -12
  90. package/dist/mjs/data-structures/binary-tree/avl-tree.js +3 -4
  91. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +58 -58
  92. package/dist/mjs/data-structures/binary-tree/binary-tree.js +6 -6
  93. package/dist/mjs/data-structures/binary-tree/bst.d.ts +15 -15
  94. package/dist/mjs/data-structures/binary-tree/bst.js +3 -3
  95. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +11 -11
  96. package/dist/mjs/data-structures/binary-tree/rb-tree.js +5 -6
  97. package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +14 -14
  98. package/dist/mjs/data-structures/binary-tree/tree-multimap.js +3 -3
  99. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +9 -3
  100. package/dist/mjs/data-structures/graph/abstract-graph.js +27 -31
  101. package/dist/mjs/data-structures/graph/directed-graph.d.ts +8 -1
  102. package/dist/mjs/data-structures/graph/directed-graph.js +1 -8
  103. package/dist/mjs/data-structures/graph/map-graph.d.ts +1 -1
  104. package/dist/mjs/data-structures/graph/undirected-graph.d.ts +8 -1
  105. package/dist/mjs/data-structures/graph/undirected-graph.js +1 -8
  106. package/dist/mjs/data-structures/hash/hash-map.d.ts +22 -10
  107. package/dist/mjs/data-structures/hash/hash-map.js +27 -15
  108. package/dist/mjs/data-structures/hash/hash-table.d.ts +2 -2
  109. package/dist/mjs/data-structures/heap/heap.d.ts +20 -38
  110. package/dist/mjs/data-structures/heap/heap.js +23 -43
  111. package/dist/mjs/data-structures/heap/max-heap.d.ts +11 -1
  112. package/dist/mjs/data-structures/heap/max-heap.js +9 -6
  113. package/dist/mjs/data-structures/heap/min-heap.d.ts +11 -1
  114. package/dist/mjs/data-structures/heap/min-heap.js +9 -6
  115. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +95 -95
  116. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +132 -136
  117. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +18 -23
  118. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +43 -50
  119. package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
  120. package/dist/mjs/data-structures/linked-list/skip-linked-list.js +2 -2
  121. package/dist/mjs/data-structures/priority-queue/max-priority-queue.d.ts +1 -1
  122. package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +0 -7
  123. package/dist/mjs/data-structures/priority-queue/min-priority-queue.d.ts +1 -1
  124. package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +0 -7
  125. package/dist/mjs/data-structures/priority-queue/priority-queue.d.ts +9 -1
  126. package/dist/mjs/data-structures/priority-queue/priority-queue.js +7 -6
  127. package/dist/mjs/data-structures/queue/deque.d.ts +76 -80
  128. package/dist/mjs/data-structures/queue/deque.js +106 -122
  129. package/dist/mjs/data-structures/queue/queue.d.ts +30 -16
  130. package/dist/mjs/data-structures/queue/queue.js +31 -24
  131. package/dist/mjs/data-structures/stack/stack.d.ts +17 -8
  132. package/dist/mjs/data-structures/stack/stack.js +10 -10
  133. package/dist/mjs/data-structures/trie/trie.d.ts +14 -5
  134. package/dist/mjs/data-structures/trie/trie.js +14 -14
  135. package/dist/mjs/interfaces/binary-tree.d.ts +4 -4
  136. package/dist/mjs/types/common.d.ts +32 -8
  137. package/dist/mjs/types/common.js +21 -0
  138. package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -24
  139. package/dist/mjs/types/data-structures/binary-tree/binary-tree.js +1 -21
  140. package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +1 -1
  141. package/dist/mjs/types/data-structures/binary-tree/tree-multimap.d.ts +1 -1
  142. package/dist/umd/data-structure-typed.js +533 -558
  143. package/dist/umd/data-structure-typed.min.js +2 -2
  144. package/dist/umd/data-structure-typed.min.js.map +1 -1
  145. package/package.json +1 -1
  146. package/src/data-structures/base/iterable-base.ts +24 -0
  147. package/src/data-structures/binary-tree/avl-tree.ts +14 -14
  148. package/src/data-structures/binary-tree/binary-tree.ts +74 -77
  149. package/src/data-structures/binary-tree/bst.ts +18 -17
  150. package/src/data-structures/binary-tree/rb-tree.ts +17 -18
  151. package/src/data-structures/binary-tree/tree-multimap.ts +22 -20
  152. package/src/data-structures/graph/abstract-graph.ts +35 -25
  153. package/src/data-structures/graph/directed-graph.ts +2 -2
  154. package/src/data-structures/graph/map-graph.ts +1 -1
  155. package/src/data-structures/graph/undirected-graph.ts +2 -2
  156. package/src/data-structures/hash/hash-map.ts +40 -24
  157. package/src/data-structures/hash/hash-table.ts +3 -3
  158. package/src/data-structures/heap/heap.ts +33 -60
  159. package/src/data-structures/heap/max-heap.ts +11 -2
  160. package/src/data-structures/heap/min-heap.ts +11 -2
  161. package/src/data-structures/linked-list/doubly-linked-list.ts +147 -145
  162. package/src/data-structures/linked-list/singly-linked-list.ts +52 -52
  163. package/src/data-structures/linked-list/skip-linked-list.ts +2 -2
  164. package/src/data-structures/priority-queue/max-priority-queue.ts +1 -1
  165. package/src/data-structures/priority-queue/min-priority-queue.ts +1 -1
  166. package/src/data-structures/priority-queue/priority-queue.ts +9 -2
  167. package/src/data-structures/queue/deque.ts +129 -144
  168. package/src/data-structures/queue/queue.ts +37 -26
  169. package/src/data-structures/stack/stack.ts +20 -14
  170. package/src/data-structures/trie/trie.ts +18 -13
  171. package/src/interfaces/binary-tree.ts +5 -5
  172. package/src/types/common.ts +37 -12
  173. package/src/types/data-structures/binary-tree/avl-tree.ts +0 -1
  174. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -26
  175. package/src/types/data-structures/binary-tree/bst.ts +0 -1
  176. package/src/types/data-structures/binary-tree/rb-tree.ts +1 -1
  177. package/src/types/data-structures/binary-tree/tree-multimap.ts +1 -1
  178. package/test/performance/data-structures/comparison/comparison.test.ts +6 -6
  179. package/test/performance/data-structures/heap/heap.test.ts +2 -2
  180. package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +2 -2
  181. package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +2 -2
  182. package/test/performance/data-structures/priority-queue/priority-queue.test.ts +2 -2
  183. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +2 -2
  184. package/test/unit/data-structures/graph/directed-graph.test.ts +21 -1
  185. package/test/unit/data-structures/graph/undirected-graph.test.ts +39 -1
  186. package/test/unit/data-structures/hash/hash-map.test.ts +2 -2
  187. package/test/unit/data-structures/heap/heap.test.ts +1 -1
  188. package/test/unit/data-structures/heap/min-heap.test.ts +1 -1
  189. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +30 -30
  190. package/test/unit/data-structures/linked-list/linked-list.test.ts +1 -1
  191. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +21 -21
  192. package/test/unit/data-structures/linked-list/skip-list.test.ts +2 -2
  193. package/test/unit/data-structures/queue/deque.test.ts +5 -5
  194. package/test/unit/data-structures/queue/queue.test.ts +4 -4
  195. package/test/unit/data-structures/trie/trie.test.ts +1 -1
@@ -71,7 +71,7 @@ export class BinaryTree extends IterableEntryBase {
71
71
  iterationType = IterationType.ITERATIVE;
72
72
  /**
73
73
  * The constructor function initializes a binary tree object with optional elements and options.
74
- * @param [elements] - An optional iterable of BTNodeExemplar objects. These objects represent the
74
+ * @param [elements] - An optional iterable of BTNExemplar objects. These objects represent the
75
75
  * elements to be added to the binary tree.
76
76
  * @param [options] - The `options` parameter is an optional object that can contain additional
77
77
  * configuration options for the binary tree. In this case, it is of type
@@ -126,7 +126,7 @@ export class BinaryTree extends IterableEntryBase {
126
126
  }
127
127
  /**
128
128
  * The function "isNode" checks if an exemplar is an instance of the BinaryTreeNode class.
129
- * @param exemplar - The `exemplar` parameter is a variable of type `BTNodeExemplar<K, V,N>`.
129
+ * @param exemplar - The `exemplar` parameter is a variable of type `BTNExemplar<K, V,N>`.
130
130
  * @returns a boolean value indicating whether the exemplar is an instance of the class N.
131
131
  */
132
132
  isNode(exemplar) {
@@ -134,7 +134,7 @@ export class BinaryTree extends IterableEntryBase {
134
134
  }
135
135
  /**
136
136
  * The function `exemplarToNode` converts an exemplar object into a node object.
137
- * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`.
137
+ * @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`.
138
138
  * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
139
139
  * `exemplarToNode` function. It represents the value associated with the exemplar node. If no value
140
140
  * is provided, it will be `undefined`.
@@ -172,7 +172,7 @@ export class BinaryTree extends IterableEntryBase {
172
172
  }
173
173
  /**
174
174
  * The function checks if a given value is an entry in a binary tree node.
175
- * @param kne - BTNodeExemplar<K, V,N> - A generic type representing a node in a binary tree. It has
175
+ * @param kne - BTNExemplar<K, V,N> - A generic type representing a node in a binary tree. It has
176
176
  * two type parameters V and N, representing the value and node type respectively.
177
177
  * @returns a boolean value.
178
178
  */
@@ -250,7 +250,7 @@ export class BinaryTree extends IterableEntryBase {
250
250
  *
251
251
  * The `addMany` function takes in a collection of nodes and an optional collection of values, and
252
252
  * adds each node with its corresponding value to the data structure.
253
- * @param nodes - An iterable collection of BTNodeExemplar objects.
253
+ * @param nodes - An iterable collection of BTNExemplar objects.
254
254
  * @param [values] - An optional iterable of values that will be assigned to each node being added.
255
255
  * @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
256
256
  */
@@ -294,7 +294,7 @@ export class BinaryTree extends IterableEntryBase {
294
294
  * @param {C} callback - The `callback` parameter is a function that is used to determine the
295
295
  * identifier of the node to be deleted. It is optional and has a default value of
296
296
  * `this._defaultOneParamCallback`. The `callback` function should return the identifier of the node.
297
- * @returns an array of `BiTreeDeleteResult<N>`.
297
+ * @returns an array of `BinaryTreeDeleteResult<N>`.
298
298
  */
299
299
  delete(identifier, callback = this._defaultOneParamCallback) {
300
300
  const deletedResult = [];
@@ -5,8 +5,8 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { BSTNested, BSTNodeKeyOrNode, BSTNodeNested, BSTOptions, BTNCallback, BTNodeExemplar } from '../../types';
9
- import { BSTVariant, BTNodeKeyOrNode, CP, IterationType } from '../../types';
8
+ import type { BSTNested, BSTNKeyOrNode, BSTNodeNested, BSTOptions, BTNCallback, BTNExemplar, BTNKeyOrNode } from '../../types';
9
+ import { BSTVariant, CP, IterationType } from '../../types';
10
10
  import { BinaryTree, BinaryTreeNode } from './binary-tree';
11
11
  import { IBinaryTree } from '../../interfaces';
12
12
  export declare class BSTNode<K = any, V = any, N extends BSTNode<K, V, N> = BSTNodeNested<K, V>> extends BinaryTreeNode<K, V, N> {
@@ -46,12 +46,12 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
46
46
  /**
47
47
  * This is the constructor function for a binary search tree class in TypeScript, which initializes
48
48
  * the tree with optional elements and options.
49
- * @param [elements] - An optional iterable of BTNodeExemplar objects that will be added to the
49
+ * @param [elements] - An optional iterable of BTNExemplar objects that will be added to the
50
50
  * binary search tree.
51
51
  * @param [options] - The `options` parameter is an optional object that can contain additional
52
52
  * configuration options for the binary search tree. It can have the following properties:
53
53
  */
54
- constructor(elements?: Iterable<BTNodeExemplar<K, V, N>>, options?: Partial<BSTOptions<K>>);
54
+ constructor(elements?: Iterable<BTNExemplar<K, V, N>>, options?: Partial<BSTOptions<K>>);
55
55
  protected _root?: N;
56
56
  get root(): N | undefined;
57
57
  protected _variant: BSTVariant;
@@ -75,19 +75,19 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
75
75
  createTree(options?: Partial<BSTOptions<K>>): TREE;
76
76
  /**
77
77
  * The function checks if an exemplar is an instance of BSTNode.
78
- * @param exemplar - The `exemplar` parameter is a variable of type `BTNodeExemplar<K, V, N>`.
78
+ * @param exemplar - The `exemplar` parameter is a variable of type `BTNExemplar<K, V, N>`.
79
79
  * @returns a boolean value indicating whether the exemplar is an instance of the BSTNode class.
80
80
  */
81
- isNode(exemplar: BTNodeExemplar<K, V, N>): exemplar is N;
81
+ isNode(exemplar: BTNExemplar<K, V, N>): exemplar is N;
82
82
  /**
83
83
  * The function `exemplarToNode` takes an exemplar and returns a node if the exemplar is valid,
84
84
  * otherwise it returns undefined.
85
- * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`, where:
85
+ * @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`, where:
86
86
  * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
87
87
  * `exemplarToNode` function. It represents the value associated with the exemplar node.
88
88
  * @returns a node of type N or undefined.
89
89
  */
90
- exemplarToNode(exemplar: BTNodeExemplar<K, V, N>, value?: V): N | undefined;
90
+ exemplarToNode(exemplar: BTNExemplar<K, V, N>, value?: V): N | undefined;
91
91
  /**
92
92
  * Time Complexity: O(log n) - Average case for a balanced tree. In the worst case (unbalanced tree), it can be O(n).
93
93
  * Space Complexity: O(1) - Constant space is used.
@@ -104,7 +104,7 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
104
104
  * @returns The method `add` returns either the newly added node (`newNode`) or `undefined` if the
105
105
  * node was not added.
106
106
  */
107
- add(keyOrNodeOrEntry: BTNodeExemplar<K, V, N>, value?: V): N | undefined;
107
+ add(keyOrNodeOrEntry: BTNExemplar<K, V, N>, value?: V): N | undefined;
108
108
  /**
109
109
  * Time Complexity: O(k log n) - Adding each element individually in a balanced tree.
110
110
  * Space Complexity: O(k) - Additional space is required for the sorted array.
@@ -129,7 +129,7 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
129
129
  * `this.iterationType`, which suggests that it is a property of the current object.
130
130
  * @returns The function `addMany` returns an array of nodes (`N`) or `undefined` values.
131
131
  */
132
- addMany(keysOrNodesOrEntries: Iterable<BTNodeExemplar<K, V, N>>, values?: Iterable<V | undefined>, isBalanceAdd?: boolean, iterationType?: IterationType): (N | undefined)[];
132
+ addMany(keysOrNodesOrEntries: Iterable<BTNExemplar<K, V, N>>, values?: Iterable<V | undefined>, isBalanceAdd?: boolean, iterationType?: IterationType): (N | undefined)[];
133
133
  /**
134
134
  * Time Complexity: O(n log n) - Adding each element individually in a balanced tree.
135
135
  * Space Complexity: O(n) - Additional space is required for the sorted array.
@@ -149,7 +149,7 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
149
149
  * the key of the leftmost node if the comparison result is greater than, and the key of the
150
150
  * rightmost node otherwise. If no node is found, it returns 0.
151
151
  */
152
- lastKey(beginRoot?: BSTNodeKeyOrNode<K, N>): K | undefined;
152
+ lastKey(beginRoot?: BSTNKeyOrNode<K, N>): K | undefined;
153
153
  /**
154
154
  * Time Complexity: O(log n) - Average case for a balanced tree.
155
155
  * Space Complexity: O(1) - Constant space is used.
@@ -175,7 +175,7 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
175
175
  * data type.
176
176
  * @returns a boolean value indicating whether the potentialKey is of type number or not.
177
177
  */
178
- isNotNodeInstance(potentialKey: BTNodeKeyOrNode<K, N>): potentialKey is K;
178
+ isNotNodeInstance(potentialKey: BTNKeyOrNode<K, N>): potentialKey is K;
179
179
  /**
180
180
  * Time Complexity: O(log n) - Average case for a balanced tree.
181
181
  * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
@@ -189,7 +189,7 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
189
189
  * type of iteration to be performed. It has a default value of `IterationType.ITERATIVE`.
190
190
  * @returns either a node object (N) or undefined.
191
191
  */
192
- ensureNode(key: BSTNodeKeyOrNode<K, N>, iterationType?: IterationType): N | undefined;
192
+ ensureNode(key: BSTNKeyOrNode<K, N>, iterationType?: IterationType): N | undefined;
193
193
  /**
194
194
  * Time Complexity: O(log n) - Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key.
195
195
  * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
@@ -213,7 +213,7 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
213
213
  * performed on the binary tree. It can have two possible values:
214
214
  * @returns The method returns an array of nodes (`N[]`).
215
215
  */
216
- getNodes<C extends BTNCallback<N>>(identifier: ReturnType<C> | undefined, callback?: C, onlyOne?: boolean, beginRoot?: BSTNodeKeyOrNode<K, N>, iterationType?: IterationType): N[];
216
+ getNodes<C extends BTNCallback<N>>(identifier: ReturnType<C> | undefined, callback?: C, onlyOne?: boolean, beginRoot?: BSTNKeyOrNode<K, N>, iterationType?: IterationType): N[];
217
217
  /**
218
218
  * Time Complexity: O(log n) - Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key.
219
219
  * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
@@ -239,7 +239,7 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
239
239
  * @returns The function `lesserOrGreaterTraverse` returns an array of values of type
240
240
  * `ReturnType<C>`, which is the return type of the callback function passed as an argument.
241
241
  */
242
- lesserOrGreaterTraverse<C extends BTNCallback<N>>(callback?: C, lesserOrGreater?: CP, targetNode?: BSTNodeKeyOrNode<K, N>, iterationType?: IterationType): ReturnType<C>[];
242
+ lesserOrGreaterTraverse<C extends BTNCallback<N>>(callback?: C, lesserOrGreater?: CP, targetNode?: BSTNKeyOrNode<K, N>, iterationType?: IterationType): ReturnType<C>[];
243
243
  /**
244
244
  * Time Complexity: O(log n) - Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key.
245
245
  * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
@@ -57,7 +57,7 @@ export class BST extends BinaryTree {
57
57
  /**
58
58
  * This is the constructor function for a binary search tree class in TypeScript, which initializes
59
59
  * the tree with optional elements and options.
60
- * @param [elements] - An optional iterable of BTNodeExemplar objects that will be added to the
60
+ * @param [elements] - An optional iterable of BTNExemplar objects that will be added to the
61
61
  * binary search tree.
62
62
  * @param [options] - The `options` parameter is an optional object that can contain additional
63
63
  * configuration options for the binary search tree. It can have the following properties:
@@ -108,7 +108,7 @@ export class BST extends BinaryTree {
108
108
  }
109
109
  /**
110
110
  * The function checks if an exemplar is an instance of BSTNode.
111
- * @param exemplar - The `exemplar` parameter is a variable of type `BTNodeExemplar<K, V, N>`.
111
+ * @param exemplar - The `exemplar` parameter is a variable of type `BTNExemplar<K, V, N>`.
112
112
  * @returns a boolean value indicating whether the exemplar is an instance of the BSTNode class.
113
113
  */
114
114
  isNode(exemplar) {
@@ -117,7 +117,7 @@ export class BST extends BinaryTree {
117
117
  /**
118
118
  * The function `exemplarToNode` takes an exemplar and returns a node if the exemplar is valid,
119
119
  * otherwise it returns undefined.
120
- * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`, where:
120
+ * @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`, where:
121
121
  * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
122
122
  * `exemplarToNode` function. It represents the value associated with the exemplar node.
123
123
  * @returns a node of type N or undefined.
@@ -5,7 +5,7 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import { BiTreeDeleteResult, BTNCallback, BTNodeExemplar, BTNodeKeyOrNode, IterationType, RBTNColor, RBTreeOptions, RedBlackTreeNested, RedBlackTreeNodeNested } from '../../types';
8
+ import { BinaryTreeDeleteResult, BTNCallback, BTNExemplar, BTNKeyOrNode, IterationType, 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> {
@@ -24,7 +24,7 @@ export declare class RedBlackTree<K = any, V = any, N extends RedBlackTreeNode<K
24
24
  /**
25
25
  * This is the constructor function for a Red-Black Tree data structure in TypeScript, which
26
26
  * initializes the tree with optional elements and options.
27
- * @param [elements] - The `elements` parameter is an optional iterable of `BTNodeExemplar<K, V, N>`
27
+ * @param [elements] - The `elements` parameter is an optional iterable of `BTNExemplar<K, V, N>`
28
28
  * objects. It represents the initial elements 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
30
  * elements to the
@@ -32,7 +32,7 @@ export declare class RedBlackTree<K = any, V = any, N extends RedBlackTreeNode<K
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<BTNodeExemplar<K, V, N>>, options?: Partial<RBTreeOptions<K>>);
35
+ constructor(elements?: Iterable<BTNExemplar<K, V, N>>, options?: Partial<RBTreeOptions<K>>);
36
36
  protected _root: N;
37
37
  get root(): N;
38
38
  protected _size: number;
@@ -60,27 +60,27 @@ export declare class RedBlackTree<K = any, V = any, N extends RedBlackTreeNode<K
60
60
  createTree(options?: RBTreeOptions<K>): TREE;
61
61
  /**
62
62
  * The function checks if an exemplar is an instance of the RedBlackTreeNode class.
63
- * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`.
63
+ * @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`.
64
64
  * @returns a boolean value indicating whether the exemplar is an instance of the RedBlackTreeNode
65
65
  * class.
66
66
  */
67
- isNode(exemplar: BTNodeExemplar<K, V, N>): exemplar is N;
67
+ isNode(exemplar: BTNExemplar<K, V, N>): exemplar is N;
68
68
  /**
69
69
  * The function "isNotNodeInstance" checks if a potential key is a K.
70
70
  * @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
71
71
  * data type.
72
72
  * @returns a boolean value indicating whether the potentialKey is of type number or not.
73
73
  */
74
- isNotNodeInstance(potentialKey: BTNodeKeyOrNode<K, N>): potentialKey is K;
74
+ isNotNodeInstance(potentialKey: BTNKeyOrNode<K, N>): potentialKey is K;
75
75
  /**
76
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 `BTNodeExemplar<K, V, N>`, where:
77
+ * @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`, where:
78
78
  * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
79
79
  * `exemplarToNode` function. It represents the value associated with the exemplar node. If a value
80
80
  * is provided, it will be used when creating the new node. If no value is provided, the new node
81
81
  * @returns a node of type N or undefined.
82
82
  */
83
- exemplarToNode(exemplar: BTNodeExemplar<K, V, N>, value?: V): N | undefined;
83
+ exemplarToNode(exemplar: BTNExemplar<K, V, N>, value?: V): N | undefined;
84
84
  /**
85
85
  * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
86
86
  * Space Complexity: O(1)
@@ -97,7 +97,7 @@ export declare class RedBlackTree<K = any, V = any, N extends RedBlackTreeNode<K
97
97
  * being added to the binary search tree.
98
98
  * @returns The method `add` returns either the newly added node (`N`) or `undefined`.
99
99
  */
100
- add(keyOrNodeOrEntry: BTNodeExemplar<K, V, N>, value?: V): N | undefined;
100
+ add(keyOrNodeOrEntry: BTNExemplar<K, V, N>, value?: V): N | undefined;
101
101
  /**
102
102
  * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
103
103
  * Space Complexity: O(1)
@@ -115,9 +115,9 @@ export declare class RedBlackTree<K = any, V = any, N extends RedBlackTreeNode<K
115
115
  * @param {C} callback - The `callback` parameter is a function that takes a node of type `N` and
116
116
  * returns a value of type `ReturnType<C>`. It is used to determine if a node should be deleted based
117
117
  * on its identifier. The `callback` function is optional and defaults to `this._defaultOneParam
118
- * @returns an array of `BiTreeDeleteResult<N>`.
118
+ * @returns an array of `BinaryTreeDeleteResult<N>`.
119
119
  */
120
- delete<C extends BTNCallback<N>>(identifier: ReturnType<C> | null | undefined, callback?: C): BiTreeDeleteResult<N>[];
120
+ delete<C extends BTNCallback<N>>(identifier: ReturnType<C> | null | undefined, callback?: C): BinaryTreeDeleteResult<N>[];
121
121
  /**
122
122
  * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
123
123
  * Space Complexity: O(1)
@@ -7,7 +7,6 @@
7
7
  */
8
8
  import { RBTNColor } from '../../types';
9
9
  import { BST, BSTNode } from './bst';
10
- import { BinaryTreeNode } from './binary-tree';
11
10
  export class RedBlackTreeNode extends BSTNode {
12
11
  color;
13
12
  constructor(key, value, color = RBTNColor.BLACK) {
@@ -27,7 +26,7 @@ export class RedBlackTree extends BST {
27
26
  /**
28
27
  * This is the constructor function for a Red-Black Tree data structure in TypeScript, which
29
28
  * initializes the tree with optional elements and options.
30
- * @param [elements] - The `elements` parameter is an optional iterable of `BTNodeExemplar<K, V, N>`
29
+ * @param [elements] - The `elements` parameter is an optional iterable of `BTNExemplar<K, V, N>`
31
30
  * objects. It represents the initial elements that will be added to the RBTree during its
32
31
  * construction. If this parameter is provided, the `addMany` method is called to add all the
33
32
  * elements to the
@@ -79,7 +78,7 @@ export class RedBlackTree extends BST {
79
78
  }
80
79
  /**
81
80
  * The function checks if an exemplar is an instance of the RedBlackTreeNode class.
82
- * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`.
81
+ * @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`.
83
82
  * @returns a boolean value indicating whether the exemplar is an instance of the RedBlackTreeNode
84
83
  * class.
85
84
  */
@@ -97,7 +96,7 @@ export class RedBlackTree extends BST {
97
96
  }
98
97
  /**
99
98
  * The function `exemplarToNode` takes an exemplar and converts it into a node object if possible.
100
- * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`, where:
99
+ * @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`, where:
101
100
  * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
102
101
  * `exemplarToNode` function. It represents the value associated with the exemplar node. If a value
103
102
  * is provided, it will be used when creating the new node. If no value is provided, the new node
@@ -208,7 +207,7 @@ export class RedBlackTree extends BST {
208
207
  * @param {C} callback - The `callback` parameter is a function that takes a node of type `N` and
209
208
  * returns a value of type `ReturnType<C>`. It is used to determine if a node should be deleted based
210
209
  * on its identifier. The `callback` function is optional and defaults to `this._defaultOneParam
211
- * @returns an array of `BiTreeDeleteResult<N>`.
210
+ * @returns an array of `BinaryTreeDeleteResult<N>`.
212
211
  */
213
212
  delete(identifier, callback = this._defaultOneParamCallback) {
214
213
  const ans = [];
@@ -303,7 +302,7 @@ export class RedBlackTree extends BST {
303
302
  * @returns a value of type `N`, `null`, or `undefined`.
304
303
  */
305
304
  getNode(identifier, callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType) {
306
- if (identifier instanceof BinaryTreeNode)
305
+ if (identifier instanceof RedBlackTreeNode)
307
306
  callback = (node => node);
308
307
  beginRoot = this.ensureNode(beginRoot);
309
308
  return this.getNodes(identifier, callback, true, beginRoot, iterationType)[0] ?? undefined;
@@ -5,8 +5,8 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { BSTNodeKeyOrNode, BTNodeExemplar, TreeMultimapNodeNested, TreeMultimapOptions } from '../../types';
9
- import { BiTreeDeleteResult, BTNCallback, BTNodeKeyOrNode, IterationType, TreeMultimapNested } from '../../types';
8
+ import type { BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, BTNExemplar, BTNKeyOrNode, TreeMultimapNested, TreeMultimapNodeNested, TreeMultimapOptions } from '../../types';
9
+ import { IterationType } from '../../types';
10
10
  import { IBinaryTree } from '../../interfaces';
11
11
  import { AVLTree, AVLTreeNode } from './avl-tree';
12
12
  export declare class TreeMultimapNode<K = any, V = any, N extends TreeMultimapNode<K, V, N> = TreeMultimapNodeNested<K, V>> extends AVLTreeNode<K, V, N> {
@@ -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<BTNodeExemplar<K, V, N>>, options?: Partial<TreeMultimapOptions<K>>);
30
+ constructor(elements?: Iterable<BTNExemplar<K, V, N>>, options?: Partial<TreeMultimapOptions<K>>);
31
31
  private _count;
32
32
  get count(): number;
33
33
  /**
@@ -43,21 +43,21 @@ export declare class TreeMultimap<K = any, V = any, N extends TreeMultimapNode<K
43
43
  createTree(options?: TreeMultimapOptions<K>): TREE;
44
44
  /**
45
45
  * The function checks if an exemplar is an instance of the TreeMultimapNode class.
46
- * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`.
46
+ * @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`.
47
47
  * @returns a boolean value indicating whether the exemplar is an instance of the TreeMultimapNode
48
48
  * class.
49
49
  */
50
- isNode(exemplar: BTNodeExemplar<K, V, N>): exemplar is N;
50
+ isNode(exemplar: BTNExemplar<K, V, N>): exemplar is N;
51
51
  /**
52
52
  * The function "isNotNodeInstance" checks if a potential key is a K.
53
53
  * @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
54
54
  * data type.
55
55
  * @returns a boolean value indicating whether the potentialKey is of type number or not.
56
56
  */
57
- isNotNodeInstance(potentialKey: BTNodeKeyOrNode<K, N>): potentialKey is K;
57
+ isNotNodeInstance(potentialKey: BTNKeyOrNode<K, N>): potentialKey is K;
58
58
  /**
59
59
  * The function `exemplarToNode` converts an exemplar object into a node object.
60
- * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`, which means it
60
+ * @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`, which means it
61
61
  * can be one of the following:
62
62
  * @param {V} [value] - The `value` parameter is an optional argument that represents the value
63
63
  * associated with the node. It is of type `V`, which can be any data type. If no value is provided,
@@ -66,7 +66,7 @@ export declare class TreeMultimap<K = any, V = any, N extends TreeMultimapNode<K
66
66
  * times the value should be added to the node. If not provided, it defaults to 1.
67
67
  * @returns a node of type `N` or `undefined`.
68
68
  */
69
- exemplarToNode(exemplar: BTNodeExemplar<K, V, N>, value?: V, count?: number): N | undefined;
69
+ exemplarToNode(exemplar: BTNExemplar<K, V, N>, value?: V, count?: number): N | undefined;
70
70
  /**
71
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
72
  * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
@@ -87,7 +87,7 @@ export declare class TreeMultimap<K = any, V = any, N extends TreeMultimapNode<K
87
87
  * @returns The method is returning either the newly inserted node or `undefined` if the insertion
88
88
  * was not successful.
89
89
  */
90
- add(keyOrNodeOrEntry: BTNodeExemplar<K, V, N>, value?: V, count?: number): N | undefined;
90
+ add(keyOrNodeOrEntry: BTNExemplar<K, V, N>, value?: V, count?: number): N | undefined;
91
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
93
  * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
@@ -102,7 +102,7 @@ export declare class TreeMultimap<K = any, V = any, N extends TreeMultimapNode<K
102
102
  * either keys, nodes, or entries.
103
103
  * @returns The method is returning an array of type `N | undefined`.
104
104
  */
105
- addMany(keysOrNodesOrEntries: Iterable<BTNodeExemplar<K, V, N>>): (N | undefined)[];
105
+ addMany(keysOrNodesOrEntries: Iterable<BTNExemplar<K, V, N>>): (N | undefined)[];
106
106
  /**
107
107
  * Time Complexity: O(1) - constant time, as it performs basic pointer assignments.
108
108
  * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
@@ -140,9 +140,9 @@ export declare class TreeMultimap<K = any, V = any, N extends TreeMultimapNode<K
140
140
  * being deleted. If set to true, the count of the node will not be considered and the node will be
141
141
  * deleted regardless of its count. If set to false (default), the count of the node will be
142
142
  * decremented by 1 and
143
- * @returns an array of `BiTreeDeleteResult<N>`.
143
+ * @returns an array of `BinaryTreeDeleteResult<N>`.
144
144
  */
145
- delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback?: C, ignoreCount?: boolean): BiTreeDeleteResult<N>[];
145
+ delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback?: C, ignoreCount?: boolean): BinaryTreeDeleteResult<N>[];
146
146
  /**
147
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
148
  * Space Complexity: O(n) - linear space, as it creates an array to store the sorted nodes.
@@ -178,7 +178,7 @@ export declare class TreeMultimap<K = any, V = any, N extends TreeMultimapNode<K
178
178
  * @returns The method `_addTo` returns either the `parent.left` or `parent.right` node that was
179
179
  * added, or `undefined` if no node was added.
180
180
  */
181
- protected _addTo(newNode: N | undefined, parent: BSTNodeKeyOrNode<K, N>): N | undefined;
181
+ protected _addTo(newNode: N | undefined, parent: BSTNKeyOrNode<K, N>): N | undefined;
182
182
  /**
183
183
  * The `_swapProperties` function swaps the key, value, count, and height properties between two nodes.
184
184
  * @param {K | N | undefined} srcNode - The `srcNode` parameter represents the source node from
@@ -188,6 +188,6 @@ export declare class TreeMultimap<K = any, V = any, N extends TreeMultimapNode<K
188
188
  * @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined`
189
189
  * if either `srcNode` or `destNode` is undefined.
190
190
  */
191
- protected _swapProperties(srcNode: BSTNodeKeyOrNode<K, N>, destNode: BSTNodeKeyOrNode<K, N>): N | undefined;
191
+ protected _swapProperties(srcNode: BSTNKeyOrNode<K, N>, destNode: BSTNKeyOrNode<K, N>): N | undefined;
192
192
  protected _replaceNode(oldNode: N, newNode: N): N;
193
193
  }
@@ -53,7 +53,7 @@ export class TreeMultimap extends AVLTree {
53
53
  }
54
54
  /**
55
55
  * The function checks if an exemplar is an instance of the TreeMultimapNode class.
56
- * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`.
56
+ * @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`.
57
57
  * @returns a boolean value indicating whether the exemplar is an instance of the TreeMultimapNode
58
58
  * class.
59
59
  */
@@ -71,7 +71,7 @@ export class TreeMultimap extends AVLTree {
71
71
  }
72
72
  /**
73
73
  * The function `exemplarToNode` converts an exemplar object into a node object.
74
- * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`, which means it
74
+ * @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`, which means it
75
75
  * can be one of the following:
76
76
  * @param {V} [value] - The `value` parameter is an optional argument that represents the value
77
77
  * associated with the node. It is of type `V`, which can be any data type. If no value is provided,
@@ -225,7 +225,7 @@ export class TreeMultimap extends AVLTree {
225
225
  * being deleted. If set to true, the count of the node will not be considered and the node will be
226
226
  * deleted regardless of its count. If set to false (default), the count of the node will be
227
227
  * decremented by 1 and
228
- * @returns an array of `BiTreeDeleteResult<N>`.
228
+ * @returns an array of `BinaryTreeDeleteResult<N>`.
229
229
  */
230
230
  delete(identifier, callback = this._defaultOneParamCallback, ignoreCount = false) {
231
231
  const deletedResult = [];
@@ -1,7 +1,13 @@
1
- import type { DijkstraResult, VertexKey } from '../../types';
2
- import { EntryCallback } from "../../types";
3
- import { IGraph } from '../../interfaces';
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
7
+ */
8
+ import type { DijkstraResult, EntryCallback, VertexKey } from '../../types';
4
9
  import { IterableEntryBase } from "../base";
10
+ import { IGraph } from '../../interfaces';
5
11
  export declare abstract class AbstractVertex<V = any> {
6
12
  key: VertexKey;
7
13
  value: V | undefined;
@@ -1,14 +1,7 @@
1
- /**
2
- * data-structure-typed
3
- *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
- * @license MIT License
7
- */
8
1
  import { uuidV4 } from '../../utils';
9
- import { PriorityQueue } from '../priority-queue';
10
- import { Queue } from '../queue';
11
2
  import { IterableEntryBase } from "../base";
3
+ import { Heap } from '../heap';
4
+ import { Queue } from '../queue';
12
5
  export class AbstractVertex {
13
6
  key;
14
7
  value;
@@ -438,13 +431,7 @@ export class AbstractGraph extends IterableEntryBase {
438
431
  * shortest paths from the source vertex to all other vertexMap in the graph. If `genPaths
439
432
  * @returns The function `dijkstraWithoutHeap` returns an object of type `DijkstraResult<VO>`.
440
433
  */
441
- dijkstraWithoutHeap(src, dest, getMinDist, genPaths) {
442
- if (getMinDist === undefined)
443
- getMinDist = false;
444
- if (genPaths === undefined)
445
- genPaths = false;
446
- if (dest === undefined)
447
- dest = undefined;
434
+ dijkstraWithoutHeap(src, dest = undefined, getMinDist = false, genPaths = false) {
448
435
  let minDist = Infinity;
449
436
  let minDest = undefined;
450
437
  let minPath = [];
@@ -573,13 +560,7 @@ export class AbstractGraph extends IterableEntryBase {
573
560
  * shortest paths from the source vertex to all other vertexMap in the graph. If `genPaths
574
561
  * @returns The function `dijkstra` returns an object of type `DijkstraResult<VO>`.
575
562
  */
576
- dijkstra(src, dest, getMinDist, genPaths) {
577
- if (getMinDist === undefined)
578
- getMinDist = false;
579
- if (genPaths === undefined)
580
- genPaths = false;
581
- if (dest === undefined)
582
- dest = undefined;
563
+ dijkstra(src, dest = undefined, getMinDist = false, genPaths = false) {
583
564
  let minDist = Infinity;
584
565
  let minDest = undefined;
585
566
  let minPath = [];
@@ -597,7 +578,7 @@ export class AbstractGraph extends IterableEntryBase {
597
578
  if (vertexOrKey instanceof AbstractVertex)
598
579
  distMap.set(vertexOrKey, Infinity);
599
580
  }
600
- const heap = new PriorityQueue([], { comparator: (a, b) => a.key - b.key });
581
+ const heap = new Heap([], { comparator: (a, b) => a.key - b.key });
601
582
  heap.add({ key: 0, value: srcVertex });
602
583
  distMap.set(srcVertex, 0);
603
584
  preMap.set(srcVertex, undefined);
@@ -964,13 +945,28 @@ export class AbstractGraph extends IterableEntryBase {
964
945
  }
965
946
  const cycles = new Map();
966
947
  if (needCycles) {
967
- let SCCs = new Map();
968
- if (SCCs.size < 1) {
969
- SCCs = getSCCs();
970
- }
971
- SCCs.forEach((SCC, low) => {
972
- if (SCC.length > 1) {
973
- cycles.set(low, SCC);
948
+ const visitedMap = new Map();
949
+ const stack = [];
950
+ const findCyclesDFS = (cur, parent) => {
951
+ visitedMap.set(cur, true);
952
+ stack.push(cur);
953
+ const neighbors = this.getNeighbors(cur);
954
+ for (const neighbor of neighbors) {
955
+ if (!visitedMap.get(neighbor)) {
956
+ findCyclesDFS(neighbor, cur);
957
+ }
958
+ else if (stack.includes(neighbor) && neighbor !== parent) {
959
+ const cycleStartIndex = stack.indexOf(neighbor);
960
+ const cycle = stack.slice(cycleStartIndex);
961
+ const cycleLow = Math.min(...cycle.map(v => dfnMap.get(v) || Infinity));
962
+ cycles.set(cycleLow, cycle);
963
+ }
964
+ }
965
+ stack.pop();
966
+ };
967
+ vertexMap.forEach(v => {
968
+ if (!visitedMap.get(v)) {
969
+ findCyclesDFS(v, undefined);
974
970
  }
975
971
  });
976
972
  }
@@ -1,5 +1,12 @@
1
- import { AbstractEdge, AbstractGraph, AbstractVertex } from './abstract-graph';
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
7
+ */
2
8
  import type { VertexKey } from '../../types';
9
+ import { AbstractEdge, AbstractGraph, AbstractVertex } from './abstract-graph';
3
10
  import { IGraph } from '../../interfaces';
4
11
  export declare class DirectedVertex<V = any> extends AbstractVertex<V> {
5
12
  /**
@@ -1,12 +1,5 @@
1
- /**
2
- * data-structure-typed
3
- *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
- * @license MIT License
7
- */
8
- import { arrayRemove } from '../../utils';
9
1
  import { AbstractEdge, AbstractGraph, AbstractVertex } from './abstract-graph';
2
+ import { arrayRemove } from '../../utils';
10
3
  export class DirectedVertex extends AbstractVertex {
11
4
  /**
12
5
  * The constructor function initializes a vertex with an optional value.
@@ -1,4 +1,4 @@
1
- import { MapGraphCoordinate, VertexKey } from '../../types';
1
+ import type { MapGraphCoordinate, VertexKey } from '../../types';
2
2
  import { DirectedEdge, DirectedGraph, DirectedVertex } from './directed-graph';
3
3
  export declare class MapVertex<V = any> extends DirectedVertex<V> {
4
4
  lat: number;
@@ -1,6 +1,13 @@
1
- import { AbstractEdge, AbstractGraph, AbstractVertex } from './abstract-graph';
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
7
+ */
2
8
  import type { VertexKey } from '../../types';
3
9
  import { IGraph } from '../../interfaces';
10
+ import { AbstractEdge, AbstractGraph, AbstractVertex } from './abstract-graph';
4
11
  export declare class UndirectedVertex<V = any> extends AbstractVertex<V> {
5
12
  /**
6
13
  * The constructor function initializes a vertex with an optional value.
@@ -1,12 +1,5 @@
1
- /**
2
- * data-structure-typed
3
- *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
- * @license MIT License
7
- */
8
- import { arrayRemove } from '../../utils';
9
1
  import { AbstractEdge, AbstractGraph, AbstractVertex } from './abstract-graph';
2
+ import { arrayRemove } from '../../utils';
10
3
  export class UndirectedVertex extends AbstractVertex {
11
4
  /**
12
5
  * The constructor function initializes a vertex with an optional value.