data-structure-typed 1.52.5 → 1.52.7

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 (181) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +33 -30
  3. package/benchmark/report.html +13 -13
  4. package/benchmark/report.json +156 -156
  5. package/dist/cjs/constants/index.d.ts +4 -0
  6. package/dist/cjs/constants/index.js +9 -0
  7. package/dist/cjs/constants/index.js.map +1 -0
  8. package/dist/cjs/data-structures/base/iterable-element-base.d.ts +8 -1
  9. package/dist/cjs/data-structures/base/iterable-element-base.js +10 -1
  10. package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -1
  11. package/dist/cjs/data-structures/base/iterable-entry-base.d.ts +8 -1
  12. package/dist/cjs/data-structures/base/iterable-entry-base.js +10 -10
  13. package/dist/cjs/data-structures/base/iterable-entry-base.js.map +1 -1
  14. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +31 -32
  15. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +43 -44
  16. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  17. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +23 -24
  18. package/dist/cjs/data-structures/binary-tree/avl-tree.js +71 -64
  19. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  20. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js +2 -2
  21. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +534 -402
  22. package/dist/cjs/data-structures/binary-tree/binary-tree.js +669 -598
  23. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  24. package/dist/cjs/data-structures/binary-tree/bst.d.ts +72 -65
  25. package/dist/cjs/data-structures/binary-tree/bst.js +115 -113
  26. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  27. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +21 -24
  28. package/dist/cjs/data-structures/binary-tree/rb-tree.js +40 -39
  29. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  30. package/dist/cjs/data-structures/binary-tree/segment-tree.d.ts +2 -2
  31. package/dist/cjs/data-structures/binary-tree/segment-tree.js +2 -2
  32. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +28 -31
  33. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +44 -43
  34. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  35. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +2 -2
  36. package/dist/cjs/data-structures/graph/abstract-graph.js +7 -4
  37. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  38. package/dist/cjs/data-structures/graph/directed-graph.d.ts +2 -2
  39. package/dist/cjs/data-structures/graph/directed-graph.js +4 -2
  40. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  41. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +2 -2
  42. package/dist/cjs/data-structures/hash/hash-map.d.ts +2 -2
  43. package/dist/cjs/data-structures/hash/hash-map.js +1 -1
  44. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  45. package/dist/cjs/data-structures/heap/heap.js +3 -3
  46. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  47. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +2 -2
  48. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +7 -7
  49. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  50. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  51. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +6 -6
  52. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  53. package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
  54. package/dist/cjs/data-structures/matrix/matrix.d.ts +2 -2
  55. package/dist/cjs/data-structures/matrix/navigator.d.ts +2 -2
  56. package/dist/cjs/data-structures/matrix/navigator.js +4 -2
  57. package/dist/cjs/data-structures/matrix/navigator.js.map +1 -1
  58. package/dist/cjs/data-structures/queue/deque.d.ts +3 -3
  59. package/dist/cjs/data-structures/queue/deque.js +29 -29
  60. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  61. package/dist/cjs/data-structures/queue/queue.d.ts +1 -1
  62. package/dist/cjs/data-structures/stack/stack.d.ts +2 -2
  63. package/dist/cjs/data-structures/tree/tree.js +2 -0
  64. package/dist/cjs/data-structures/tree/tree.js.map +1 -1
  65. package/dist/cjs/data-structures/trie/trie.d.ts +2 -2
  66. package/dist/cjs/data-structures/trie/trie.js +1 -1
  67. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  68. package/dist/cjs/index.d.ts +1 -0
  69. package/dist/cjs/index.js +1 -0
  70. package/dist/cjs/index.js.map +1 -1
  71. package/dist/cjs/interfaces/binary-tree.d.ts +2 -2
  72. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +2 -4
  73. package/dist/cjs/types/data-structures/binary-tree/binary-tree.js +0 -6
  74. package/dist/cjs/types/data-structures/binary-tree/binary-tree.js.map +1 -1
  75. package/dist/mjs/constants/index.d.ts +4 -0
  76. package/dist/mjs/constants/index.js +5 -0
  77. package/dist/mjs/data-structures/base/iterable-element-base.d.ts +8 -1
  78. package/dist/mjs/data-structures/base/iterable-element-base.js +10 -1
  79. package/dist/mjs/data-structures/base/iterable-entry-base.d.ts +8 -1
  80. package/dist/mjs/data-structures/base/iterable-entry-base.js +10 -10
  81. package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +31 -32
  82. package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +44 -44
  83. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +23 -24
  84. package/dist/mjs/data-structures/binary-tree/avl-tree.js +72 -64
  85. package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.js +2 -2
  86. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +534 -402
  87. package/dist/mjs/data-structures/binary-tree/binary-tree.js +668 -592
  88. package/dist/mjs/data-structures/binary-tree/bst.d.ts +72 -65
  89. package/dist/mjs/data-structures/binary-tree/bst.js +116 -112
  90. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +21 -24
  91. package/dist/mjs/data-structures/binary-tree/rb-tree.js +41 -38
  92. package/dist/mjs/data-structures/binary-tree/segment-tree.d.ts +2 -2
  93. package/dist/mjs/data-structures/binary-tree/segment-tree.js +2 -2
  94. package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +28 -31
  95. package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +45 -42
  96. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +2 -2
  97. package/dist/mjs/data-structures/graph/abstract-graph.js +7 -4
  98. package/dist/mjs/data-structures/graph/directed-graph.d.ts +2 -2
  99. package/dist/mjs/data-structures/graph/directed-graph.js +4 -2
  100. package/dist/mjs/data-structures/graph/undirected-graph.d.ts +2 -2
  101. package/dist/mjs/data-structures/hash/hash-map.d.ts +2 -2
  102. package/dist/mjs/data-structures/hash/hash-map.js +1 -1
  103. package/dist/mjs/data-structures/heap/heap.js +3 -3
  104. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +2 -2
  105. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +7 -7
  106. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  107. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +6 -6
  108. package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
  109. package/dist/mjs/data-structures/matrix/matrix.d.ts +2 -2
  110. package/dist/mjs/data-structures/matrix/navigator.d.ts +2 -2
  111. package/dist/mjs/data-structures/matrix/navigator.js +4 -2
  112. package/dist/mjs/data-structures/queue/deque.d.ts +3 -3
  113. package/dist/mjs/data-structures/queue/deque.js +29 -29
  114. package/dist/mjs/data-structures/queue/queue.d.ts +1 -1
  115. package/dist/mjs/data-structures/stack/stack.d.ts +2 -2
  116. package/dist/mjs/data-structures/tree/tree.js +2 -0
  117. package/dist/mjs/data-structures/trie/trie.d.ts +2 -2
  118. package/dist/mjs/data-structures/trie/trie.js +1 -1
  119. package/dist/mjs/index.d.ts +1 -0
  120. package/dist/mjs/index.js +1 -0
  121. package/dist/mjs/interfaces/binary-tree.d.ts +2 -2
  122. package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +2 -4
  123. package/dist/mjs/types/data-structures/binary-tree/binary-tree.js +1 -5
  124. package/dist/umd/data-structure-typed.js +1344 -1614
  125. package/dist/umd/data-structure-typed.min.js +10 -3
  126. package/dist/umd/data-structure-typed.min.js.map +1 -1
  127. package/eslint.config.mjs +69 -0
  128. package/package.json +30 -28
  129. package/src/constants/index.ts +4 -0
  130. package/src/data-structures/base/iterable-element-base.ts +11 -1
  131. package/src/data-structures/base/iterable-entry-base.ts +11 -19
  132. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +47 -50
  133. package/src/data-structures/binary-tree/avl-tree.ts +69 -71
  134. package/src/data-structures/binary-tree/binary-indexed-tree.ts +2 -2
  135. package/src/data-structures/binary-tree/binary-tree.ts +698 -726
  136. package/src/data-structures/binary-tree/bst.ts +123 -129
  137. package/src/data-structures/binary-tree/rb-tree.ts +44 -46
  138. package/src/data-structures/binary-tree/segment-tree.ts +2 -2
  139. package/src/data-structures/binary-tree/tree-multi-map.ts +48 -49
  140. package/src/data-structures/graph/abstract-graph.ts +6 -6
  141. package/src/data-structures/graph/directed-graph.ts +4 -4
  142. package/src/data-structures/graph/undirected-graph.ts +2 -2
  143. package/src/data-structures/hash/hash-map.ts +3 -3
  144. package/src/data-structures/heap/heap.ts +3 -3
  145. package/src/data-structures/linked-list/doubly-linked-list.ts +9 -9
  146. package/src/data-structures/linked-list/singly-linked-list.ts +8 -8
  147. package/src/data-structures/linked-list/skip-linked-list.ts +2 -2
  148. package/src/data-structures/matrix/matrix.ts +2 -2
  149. package/src/data-structures/matrix/navigator.ts +4 -4
  150. package/src/data-structures/queue/deque.ts +31 -31
  151. package/src/data-structures/queue/queue.ts +1 -1
  152. package/src/data-structures/stack/stack.ts +2 -2
  153. package/src/data-structures/trie/trie.ts +3 -3
  154. package/src/index.ts +1 -0
  155. package/src/interfaces/binary-tree.ts +3 -3
  156. package/src/types/data-structures/binary-tree/binary-tree.ts +3 -5
  157. package/test/config.ts +1 -7
  158. package/test/integration/all-in-one.test.ts +2 -2
  159. package/test/integration/avl-tree.test.ts +3 -3
  160. package/test/integration/bst.test.ts +19 -18
  161. package/test/integration/heap.test.js +6 -1
  162. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +39 -39
  163. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +2 -2
  164. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +140 -112
  165. package/test/unit/data-structures/binary-tree/bst.test.ts +41 -13
  166. package/test/unit/data-structures/binary-tree/overall.test.ts +0 -6
  167. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +6 -6
  168. package/test/unit/data-structures/binary-tree/segment-tree.test.ts +88 -34
  169. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +42 -42
  170. package/test/unit/data-structures/graph/abstract-graph.test.ts +1 -1
  171. package/test/unit/data-structures/graph/directed-graph.test.ts +4 -4
  172. package/test/unit/data-structures/graph/undirected-graph.test.ts +14 -2
  173. package/test/unit/data-structures/hash/hash-map.test.ts +1 -1
  174. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +1 -1
  175. package/test/unit/data-structures/matrix/navigator.test.ts +2 -2
  176. package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +1 -1
  177. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +4 -4
  178. package/test/unit/data-structures/stack/stack.test.ts +6 -0
  179. package/test/unit/unrestricted-interconversion.test.ts +24 -24
  180. package/test/utils/big-o.ts +5 -4
  181. package/.eslintrc.js +0 -64
@@ -34,7 +34,7 @@ export class RedBlackTreeNode extends BSTNode {
34
34
  export class RedBlackTree extends BST {
35
35
  /**
36
36
  * This is the constructor function for a Red-Black Tree data structure in TypeScript.
37
- * @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
37
+ * @param keysOrNodesOrEntriesOrRaws - The `keysOrNodesOrEntriesOrRaws` parameter is an
38
38
  * iterable object that can contain either keys, nodes, entries, or raw elements. It is used to
39
39
  * initialize the RBTree with the provided elements.
40
40
  * @param [options] - The `options` parameter is an optional object that can be passed to the
@@ -42,11 +42,11 @@ export class RedBlackTree extends BST {
42
42
  * configuring the behavior of the Red-Black Tree. The specific properties and their meanings would
43
43
  * depend on the implementation
44
44
  */
45
- constructor(keysOrNodesOrEntriesOrRawElements = [], options) {
45
+ constructor(keysOrNodesOrEntriesOrRaws = [], options) {
46
46
  super([], options);
47
47
  this._root = this.NIL;
48
- if (keysOrNodesOrEntriesOrRawElements) {
49
- this.addMany(keysOrNodesOrEntriesOrRawElements);
48
+ if (keysOrNodesOrEntriesOrRaws) {
49
+ this.addMany(keysOrNodesOrEntriesOrRaws);
50
50
  }
51
51
  }
52
52
  _root;
@@ -83,6 +83,8 @@ export class RedBlackTree extends BST {
83
83
  createTree(options) {
84
84
  return new RedBlackTree([], {
85
85
  iterationType: this.iterationType,
86
+ comparator: this._comparator,
87
+ toEntryFn: this._toEntryFn,
86
88
  ...options
87
89
  });
88
90
  }
@@ -91,13 +93,13 @@ export class RedBlackTree extends BST {
91
93
  * Space Complexity: O(1)
92
94
  *
93
95
  * The function checks if the input is an instance of the RedBlackTreeNode class.
94
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
95
- * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
96
- * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
96
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
97
+ * `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
98
+ * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRaw` is
97
99
  * an instance of the `RedBlackTreeNode` class.
98
100
  */
99
- isNode(keyOrNodeOrEntryOrRawElement) {
100
- return keyOrNodeOrEntryOrRawElement instanceof RedBlackTreeNode;
101
+ isNode(keyOrNodeOrEntryOrRaw) {
102
+ return keyOrNodeOrEntryOrRaw instanceof RedBlackTreeNode;
101
103
  }
102
104
  // /**
103
105
  // * Time Complexity: O(1)
@@ -110,27 +112,27 @@ export class RedBlackTree extends BST {
110
112
  // *
111
113
  // * The function `keyValueOrEntryOrRawElementToNode` takes a key, value, or entry and returns a node if it is
112
114
  // * valid, otherwise it returns undefined.
113
- // * @param {BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The key, value, or entry to convert.
114
- // * @param {V} [value] - The value associated with the key (if `keyOrNodeOrEntryOrRawElement` is a key).
115
+ // * @param {BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRaw - The key, value, or entry to convert.
116
+ // * @param {V} [value] - The value associated with the key (if `keyOrNodeOrEntryOrRaw` is a key).
115
117
  // * @returns {NODE | undefined} - The corresponding Red-Black Tree node, or `undefined` if conversion fails.
116
118
  // */
117
- // override keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V): NODE | undefined {
119
+ // override keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R, value?: V): NODE | undefined {
118
120
  //
119
- // if (keyOrNodeOrEntryOrRawElement === null || keyOrNodeOrEntryOrRawElement === undefined) return;
120
- // if (this.isNode(keyOrNodeOrEntryOrRawElement)) return keyOrNodeOrEntryOrRawElement;
121
+ // if (keyOrNodeOrEntryOrRaw === null || keyOrNodeOrEntryOrRaw === undefined) return;
122
+ // if (this.isNode(keyOrNodeOrEntryOrRaw)) return keyOrNodeOrEntryOrRaw;
121
123
  //
122
- // if (this.toEntryFn) {
123
- // const [key, entryValue] = this.toEntryFn(keyOrNodeOrEntryOrRawElement as R);
124
+ // if (this._toEntryFn) {
125
+ // const [key, entryValue] = this._toEntryFn(keyOrNodeOrEntryOrRaw as R);
124
126
  // if (this.isKey(key)) return this.createNode(key, entryValue ?? value, 'RED');
125
127
  // }
126
128
  //
127
- // if (this.isEntry(keyOrNodeOrEntryOrRawElement)) {
128
- // const [key, value] = keyOrNodeOrEntryOrRawElement;
129
+ // if (this.isEntry(keyOrNodeOrEntryOrRaw)) {
130
+ // const [key, value] = keyOrNodeOrEntryOrRaw;
129
131
  // if (key === undefined || key === null) return;
130
132
  // else return this.createNode(key, value, 'RED');
131
133
  // }
132
134
  //
133
- // if (this.isKey(keyOrNodeOrEntryOrRawElement)) return this.createNode(keyOrNodeOrEntryOrRawElement, value, 'RED');
135
+ // if (this.isKey(keyOrNodeOrEntryOrRaw)) return this.createNode(keyOrNodeOrEntryOrRaw, value, 'RED');
134
136
  //
135
137
  // return ;
136
138
  // }
@@ -151,8 +153,8 @@ export class RedBlackTree extends BST {
151
153
  *
152
154
  * The function adds a new node to a binary search tree and returns true if the node was successfully
153
155
  * added.
154
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
155
- * `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
156
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
157
+ * `keyOrNodeOrEntryOrRaw` can accept a value of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
156
158
  * @param {V} [value] - The `value` parameter is an optional value that you want to associate with
157
159
  * the key in the data structure. It represents the value that you want to add or update in the data
158
160
  * structure.
@@ -160,8 +162,8 @@ export class RedBlackTree extends BST {
160
162
  * the method returns true. If the node already exists and its value is updated, the method also
161
163
  * returns true. If the node cannot be added or updated, the method returns false.
162
164
  */
163
- add(keyOrNodeOrEntryOrRawElement, value) {
164
- const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value);
165
+ add(keyOrNodeOrEntryOrRaw, value) {
166
+ const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw, value);
165
167
  if (!this.isRealNode(newNode))
166
168
  return false;
167
169
  const insertStatus = this._insert(newNode);
@@ -183,24 +185,25 @@ export class RedBlackTree extends BST {
183
185
  * Time Complexity: O(log n)
184
186
  * Space Complexity: O(1)
185
187
  *
186
- * The function overrides the delete method of a binary tree data structure, allowing for the
187
- * deletion of a node and maintaining the balance of the tree.
188
- * @param {ReturnType<C> | null | undefined} identifier - The `identifier` parameter is the value
189
- * that identifies the node to be deleted from the binary tree. It can be of any type that is
190
- * returned by the callback function `C`. It can also be `null` or `undefined` if there is no node to
191
- * delete.
192
- * @param {C} callback - The `callback` parameter is a function that is used to determine the
193
- * equality of nodes in the binary tree. It is optional and has a default value of
194
- * `this._DEFAULT_CALLBACK`. The type of the `callback` parameter is `C`, which is a generic type
195
- * that extends the `BTNCallback
196
- * @returns an array of BinaryTreeDeleteResult<NODE> objects.
188
+ * The function overrides the delete method in a binary tree data structure to remove a node based on
189
+ * a given predicate and maintain the binary search tree properties.
190
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
191
+ * parameter in the `override delete` method is used to specify the condition or key based on which a
192
+ * node should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate
193
+ * function that determines which node(s) should be deleted.
194
+ * @returns The `override delete` method is returning an array of `BinaryTreeDeleteResult<NODE>`
195
+ * objects. Each object in the array contains information about the deleted node and whether
196
+ * balancing is needed.
197
197
  */
198
- delete(identifier, callback = this._DEFAULT_CALLBACK) {
199
- if (identifier === null)
198
+ delete(predicate) {
199
+ if (predicate === null)
200
200
  return [];
201
201
  const results = [];
202
- callback = this._ensureCallback(identifier, callback);
203
- const nodeToDelete = this.isRealNode(identifier) ? identifier : this.getNode(identifier, callback);
202
+ let nodeToDelete;
203
+ if (this._isPredicated(predicate))
204
+ nodeToDelete = this.getNode(predicate);
205
+ else
206
+ nodeToDelete = this.isRealNode(predicate) ? predicate : this.getNode(predicate);
204
207
  if (!nodeToDelete) {
205
208
  return results;
206
209
  }
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * data-structure-typed
3
3
  *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
8
  import type { SegmentTreeNodeVal } from '../../types';
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * data-structure-typed
3
3
  *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
8
  export class SegmentTreeNode {
@@ -1,12 +1,11 @@
1
1
  /**
2
2
  * data-structure-typed
3
3
  *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, BTNKeyOrNodeOrEntry, IterationType, RBTNColor, TreeMultiMapNested, TreeMultiMapNodeNested, TreeMultiMapOptions } from '../../types';
9
- import { BTNEntry } from '../../types';
8
+ import type { BinaryTreeDeleteResult, BSTNKeyOrNode, BTNKeyOrNodeOrEntry, BTNPredicate, IterationType, RBTNColor, TreeMultiMapNested, TreeMultiMapNodeNested, TreeMultiMapOptions, BTNEntry } from '../../types';
10
9
  import { IBinaryTree } from '../../interfaces';
11
10
  import { RedBlackTree, RedBlackTreeNode } from './rb-tree';
12
11
  export declare class TreeMultiMapNode<K = any, V = any, NODE extends TreeMultiMapNode<K, V, NODE> = TreeMultiMapNodeNested<K, V>> extends RedBlackTreeNode<K, V, NODE> {
@@ -39,14 +38,14 @@ export declare class TreeMultiMapNode<K = any, V = any, NODE extends TreeMultiMa
39
38
  export declare class TreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE extends TreeMultiMapNode<K, V, NODE> = TreeMultiMapNode<K, V, TreeMultiMapNodeNested<K, V>>, TREE extends TreeMultiMap<K, V, R, NODE, TREE> = TreeMultiMap<K, V, R, NODE, TreeMultiMapNested<K, V, R, NODE>>> extends RedBlackTree<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
40
39
  /**
41
40
  * The constructor function initializes a TreeMultiMap object with optional initial data.
42
- * @param keysOrNodesOrEntriesOrRawElements - The parameter `keysOrNodesOrEntriesOrRawElements` is an
41
+ * @param keysOrNodesOrEntriesOrRaws - The parameter `keysOrNodesOrEntriesOrRaws` is an
43
42
  * iterable that can contain keys, nodes, entries, or raw elements. It is used to initialize the
44
43
  * TreeMultiMap with initial data.
45
44
  * @param [options] - The `options` parameter is an optional object that can be used to customize the
46
45
  * behavior of the `TreeMultiMap` constructor. It can include properties such as `compareKeys` and
47
46
  * `compareValues`, which are functions used to compare keys and values respectively.
48
47
  */
49
- constructor(keysOrNodesOrEntriesOrRawElements?: Iterable<BTNKeyOrNodeOrEntry<K, V, NODE>>, options?: TreeMultiMapOptions<K, V, R>);
48
+ constructor(keysOrNodesOrEntriesOrRaws?: Iterable<BTNKeyOrNodeOrEntry<K, V, NODE>>, options?: TreeMultiMapOptions<K, V, R>);
50
49
  protected _count: number;
51
50
  /**
52
51
  * The function calculates the sum of the count property of all nodes in a tree structure.
@@ -88,8 +87,8 @@ export declare class TreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE ext
88
87
  /**
89
88
  * The function `keyValueOrEntryOrRawElementToNode` takes in a key, value, and count and returns a
90
89
  * node based on the input.
91
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
92
- * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
90
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
91
+ * `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
93
92
  * @param {V} [value] - The `value` parameter is an optional value that represents the value
94
93
  * associated with the key in the node. It is used when creating a new node or updating the value of
95
94
  * an existing node.
@@ -97,23 +96,23 @@ export declare class TreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE ext
97
96
  * times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
98
97
  * @returns either a NODE object or undefined.
99
98
  */
100
- keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V, count?: number): NODE | undefined;
99
+ keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R, value?: V, count?: number): NODE | undefined;
101
100
  /**
102
101
  * The function checks if the input is an instance of the TreeMultiMapNode class.
103
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
104
- * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
105
- * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
102
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
103
+ * `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
104
+ * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRaw` is
106
105
  * an instance of the `TreeMultiMapNode` class.
107
106
  */
108
- isNode(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntryOrRawElement is NODE;
107
+ isNode(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): keyOrNodeOrEntryOrRaw is NODE;
109
108
  /**
110
109
  * Time Complexity: O(log n)
111
110
  * Space Complexity: O(1)
112
111
  *
113
112
  * The function overrides the add method of a class and adds a new node to a data structure, updating
114
113
  * the count and returning a boolean indicating success.
115
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
116
- * `keyOrNodeOrEntryOrRawElement` parameter can accept one of the following types:
114
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The
115
+ * `keyOrNodeOrEntryOrRaw` parameter can accept one of the following types:
117
116
  * @param {V} [value] - The `value` parameter represents the value associated with the key in the
118
117
  * data structure. It is an optional parameter, so it can be omitted if not needed.
119
118
  * @param [count=1] - The `count` parameter represents the number of times the key-value pair should
@@ -122,26 +121,24 @@ export declare class TreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE ext
122
121
  * @returns The method is returning a boolean value. It returns true if the addition of the new node
123
122
  * was successful, and false otherwise.
124
123
  */
125
- add(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V, count?: number): boolean;
124
+ add(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R, value?: V, count?: number): boolean;
126
125
  /**
127
126
  * Time Complexity: O(log n)
128
127
  * Space Complexity: O(1)
129
128
  *
130
- * The function `delete` is used to remove a node from a binary tree and fix the tree if necessary.
131
- * @param {ReturnType<C> | null | undefined} identifier - The `identifier` parameter is the value or
132
- * key that is used to identify the node that needs to be deleted from the binary tree. It can be of
133
- * any type that is returned by the callback function `C`. It can also be `null` or `undefined` if
134
- * the node to be deleted
135
- * @param {C} callback - The `callback` parameter is a function that is used to determine the
136
- * equality of nodes in the binary tree. It is optional and has a default value of
137
- * `this._DEFAULT_CALLBACK`. The `callback` function is used to compare nodes when searching for a
138
- * specific node or when performing other operations on the
139
- * @param [ignoreCount=false] - A boolean flag indicating whether to ignore the count of the node
140
- * being deleted. If set to true, the count of the node will not be taken into account when deleting
141
- * it. If set to false, the count of the node will be decremented by 1 before deleting it.
142
- * @returns an array of BinaryTreeDeleteResult<NODE> objects.
143
- */
144
- delete<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | null | undefined, callback?: C, ignoreCount?: boolean): BinaryTreeDeleteResult<NODE>[];
129
+ * The function `delete` in TypeScript overrides the deletion operation in a binary tree data
130
+ * structure, handling cases where nodes have children and maintaining balance in the tree.
131
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
132
+ * parameter in the `delete` method is used to specify the condition or key based on which a node
133
+ * should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate
134
+ * function.
135
+ * @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
136
+ * boolean flag that determines whether to ignore the count of nodes when performing deletion. If
137
+ * `ignoreCount` is set to `true`, the method will delete the node regardless of its count. If
138
+ * `ignoreCount` is `false
139
+ * @returns The `override delete` method returns an array of `BinaryTreeDeleteResult<NODE>` objects.
140
+ */
141
+ delete(predicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>, ignoreCount?: boolean): BinaryTreeDeleteResult<NODE>[];
145
142
  /**
146
143
  * Time Complexity: O(1)
147
144
  * Space Complexity: O(1)
@@ -36,17 +36,17 @@ export class TreeMultiMapNode extends RedBlackTreeNode {
36
36
  export class TreeMultiMap extends RedBlackTree {
37
37
  /**
38
38
  * The constructor function initializes a TreeMultiMap object with optional initial data.
39
- * @param keysOrNodesOrEntriesOrRawElements - The parameter `keysOrNodesOrEntriesOrRawElements` is an
39
+ * @param keysOrNodesOrEntriesOrRaws - The parameter `keysOrNodesOrEntriesOrRaws` is an
40
40
  * iterable that can contain keys, nodes, entries, or raw elements. It is used to initialize the
41
41
  * TreeMultiMap with initial data.
42
42
  * @param [options] - The `options` parameter is an optional object that can be used to customize the
43
43
  * behavior of the `TreeMultiMap` constructor. It can include properties such as `compareKeys` and
44
44
  * `compareValues`, which are functions used to compare keys and values respectively.
45
45
  */
46
- constructor(keysOrNodesOrEntriesOrRawElements = [], options) {
46
+ constructor(keysOrNodesOrEntriesOrRaws = [], options) {
47
47
  super([], options);
48
- if (keysOrNodesOrEntriesOrRawElements)
49
- this.addMany(keysOrNodesOrEntriesOrRawElements);
48
+ if (keysOrNodesOrEntriesOrRaws)
49
+ this.addMany(keysOrNodesOrEntriesOrRaws);
50
50
  }
51
51
  _count = 0;
52
52
  // TODO the _count is not accurate after nodes count modified
@@ -97,14 +97,16 @@ export class TreeMultiMap extends RedBlackTree {
97
97
  createTree(options) {
98
98
  return new TreeMultiMap([], {
99
99
  iterationType: this.iterationType,
100
+ comparator: this._comparator,
101
+ toEntryFn: this._toEntryFn,
100
102
  ...options
101
103
  });
102
104
  }
103
105
  /**
104
106
  * The function `keyValueOrEntryOrRawElementToNode` takes in a key, value, and count and returns a
105
107
  * node based on the input.
106
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
107
- * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
108
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
109
+ * `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
108
110
  * @param {V} [value] - The `value` parameter is an optional value that represents the value
109
111
  * associated with the key in the node. It is used when creating a new node or updating the value of
110
112
  * an existing node.
@@ -112,36 +114,36 @@ export class TreeMultiMap extends RedBlackTree {
112
114
  * times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
113
115
  * @returns either a NODE object or undefined.
114
116
  */
115
- keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value, count = 1) {
116
- if (keyOrNodeOrEntryOrRawElement === undefined || keyOrNodeOrEntryOrRawElement === null)
117
+ keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw, value, count = 1) {
118
+ if (keyOrNodeOrEntryOrRaw === undefined || keyOrNodeOrEntryOrRaw === null)
117
119
  return;
118
- if (this.isNode(keyOrNodeOrEntryOrRawElement))
119
- return keyOrNodeOrEntryOrRawElement;
120
- if (this.isEntry(keyOrNodeOrEntryOrRawElement)) {
121
- const [key, entryValue] = keyOrNodeOrEntryOrRawElement;
120
+ if (this.isNode(keyOrNodeOrEntryOrRaw))
121
+ return keyOrNodeOrEntryOrRaw;
122
+ if (this.isEntry(keyOrNodeOrEntryOrRaw)) {
123
+ const [key, entryValue] = keyOrNodeOrEntryOrRaw;
122
124
  if (key === undefined || key === null)
123
125
  return;
124
126
  if (this.isKey(key))
125
127
  return this.createNode(key, value ?? entryValue, 'BLACK', count);
126
128
  }
127
- if (this.toEntryFn) {
128
- const [key, entryValue] = this.toEntryFn(keyOrNodeOrEntryOrRawElement);
129
+ if (this._toEntryFn) {
130
+ const [key, entryValue] = this._toEntryFn(keyOrNodeOrEntryOrRaw);
129
131
  if (this.isKey(key))
130
132
  return this.createNode(key, value ?? entryValue, 'BLACK', count);
131
133
  }
132
- if (this.isKey(keyOrNodeOrEntryOrRawElement))
133
- return this.createNode(keyOrNodeOrEntryOrRawElement, value, 'BLACK', count);
134
+ if (this.isKey(keyOrNodeOrEntryOrRaw))
135
+ return this.createNode(keyOrNodeOrEntryOrRaw, value, 'BLACK', count);
134
136
  return;
135
137
  }
136
138
  /**
137
139
  * The function checks if the input is an instance of the TreeMultiMapNode class.
138
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
139
- * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
140
- * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
140
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
141
+ * `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
142
+ * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRaw` is
141
143
  * an instance of the `TreeMultiMapNode` class.
142
144
  */
143
- isNode(keyOrNodeOrEntryOrRawElement) {
144
- return keyOrNodeOrEntryOrRawElement instanceof TreeMultiMapNode;
145
+ isNode(keyOrNodeOrEntryOrRaw) {
146
+ return keyOrNodeOrEntryOrRaw instanceof TreeMultiMapNode;
145
147
  }
146
148
  /**
147
149
  * Time Complexity: O(log n)
@@ -149,8 +151,8 @@ export class TreeMultiMap extends RedBlackTree {
149
151
  *
150
152
  * The function overrides the add method of a class and adds a new node to a data structure, updating
151
153
  * the count and returning a boolean indicating success.
152
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
153
- * `keyOrNodeOrEntryOrRawElement` parameter can accept one of the following types:
154
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The
155
+ * `keyOrNodeOrEntryOrRaw` parameter can accept one of the following types:
154
156
  * @param {V} [value] - The `value` parameter represents the value associated with the key in the
155
157
  * data structure. It is an optional parameter, so it can be omitted if not needed.
156
158
  * @param [count=1] - The `count` parameter represents the number of times the key-value pair should
@@ -159,8 +161,8 @@ export class TreeMultiMap extends RedBlackTree {
159
161
  * @returns The method is returning a boolean value. It returns true if the addition of the new node
160
162
  * was successful, and false otherwise.
161
163
  */
162
- add(keyOrNodeOrEntryOrRawElement, value, count = 1) {
163
- const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value, count);
164
+ add(keyOrNodeOrEntryOrRaw, value, count = 1) {
165
+ const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw, value, count);
164
166
  const orgCount = newNode?.count || 0;
165
167
  const isSuccessAdded = super.add(newNode);
166
168
  if (isSuccessAdded) {
@@ -175,26 +177,27 @@ export class TreeMultiMap extends RedBlackTree {
175
177
  * Time Complexity: O(log n)
176
178
  * Space Complexity: O(1)
177
179
  *
178
- * The function `delete` is used to remove a node from a binary tree and fix the tree if necessary.
179
- * @param {ReturnType<C> | null | undefined} identifier - The `identifier` parameter is the value or
180
- * key that is used to identify the node that needs to be deleted from the binary tree. It can be of
181
- * any type that is returned by the callback function `C`. It can also be `null` or `undefined` if
182
- * the node to be deleted
183
- * @param {C} callback - The `callback` parameter is a function that is used to determine the
184
- * equality of nodes in the binary tree. It is optional and has a default value of
185
- * `this._DEFAULT_CALLBACK`. The `callback` function is used to compare nodes when searching for a
186
- * specific node or when performing other operations on the
187
- * @param [ignoreCount=false] - A boolean flag indicating whether to ignore the count of the node
188
- * being deleted. If set to true, the count of the node will not be taken into account when deleting
189
- * it. If set to false, the count of the node will be decremented by 1 before deleting it.
190
- * @returns an array of BinaryTreeDeleteResult<NODE> objects.
180
+ * The function `delete` in TypeScript overrides the deletion operation in a binary tree data
181
+ * structure, handling cases where nodes have children and maintaining balance in the tree.
182
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
183
+ * parameter in the `delete` method is used to specify the condition or key based on which a node
184
+ * should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate
185
+ * function.
186
+ * @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
187
+ * boolean flag that determines whether to ignore the count of nodes when performing deletion. If
188
+ * `ignoreCount` is set to `true`, the method will delete the node regardless of its count. If
189
+ * `ignoreCount` is `false
190
+ * @returns The `override delete` method returns an array of `BinaryTreeDeleteResult<NODE>` objects.
191
191
  */
192
- delete(identifier, callback = this._DEFAULT_CALLBACK, ignoreCount = false) {
193
- if (identifier === null)
192
+ delete(predicate, ignoreCount = false) {
193
+ if (predicate === null)
194
194
  return [];
195
195
  const results = [];
196
- callback = this._ensureCallback(identifier, callback);
197
- const nodeToDelete = this.isRealNode(identifier) ? identifier : this.getNode(identifier, callback);
196
+ let nodeToDelete;
197
+ if (this._isPredicated(predicate))
198
+ nodeToDelete = this.getNode(predicate);
199
+ else
200
+ nodeToDelete = this.isRealNode(predicate) ? predicate : this.getNode(predicate);
198
201
  if (!nodeToDelete) {
199
202
  return results;
200
203
  }
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * data-structure-typed
3
3
  *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
8
  import type { DijkstraResult, EntryCallback, VertexKey } from '../../types';
@@ -459,7 +459,7 @@ export class AbstractGraph extends IterableEntryBase {
459
459
  }
460
460
  }
461
461
  }
462
- getMinDist &&
462
+ if (getMinDist)
463
463
  distMap.forEach((d, v) => {
464
464
  if (v !== srcVertex) {
465
465
  if (d < minDist) {
@@ -469,7 +469,8 @@ export class AbstractGraph extends IterableEntryBase {
469
469
  }
470
470
  }
471
471
  });
472
- genPaths && getPaths(minDest);
472
+ if (genPaths)
473
+ getPaths(minDest);
473
474
  return { distMap, preMap, seen, paths, minDist, minPath };
474
475
  }
475
476
  /**
@@ -641,7 +642,8 @@ export class AbstractGraph extends IterableEntryBase {
641
642
  if (sWeight !== undefined && dWeight !== undefined) {
642
643
  if (distMap.get(s) !== Infinity && sWeight + weight < dWeight) {
643
644
  distMap.set(d, sWeight + weight);
644
- genPath && preMap.set(d, s);
645
+ if (genPath)
646
+ preMap.set(d, s);
645
647
  }
646
648
  }
647
649
  }
@@ -765,7 +767,8 @@ export class AbstractGraph extends IterableEntryBase {
765
767
  visited.add(vertex);
766
768
  currentPath.push(vertex.key);
767
769
  for (const neighbor of this.getNeighbors(vertex)) {
768
- neighbor && dfs(neighbor, currentPath, visited);
770
+ if (neighbor)
771
+ dfs(neighbor, currentPath, visited);
769
772
  }
770
773
  visited.delete(vertex);
771
774
  currentPath.pop();
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * data-structure-typed
3
3
  *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
8
  import type { VertexKey } from '../../types';
@@ -217,8 +217,10 @@ export class DirectedGraph extends AbstractGraph {
217
217
  if (v1 && v2) {
218
218
  const v1ToV2 = this.deleteEdgeSrcToDest(v1, v2);
219
219
  const v2ToV1 = this.deleteEdgeSrcToDest(v2, v1);
220
- v1ToV2 && removed.push(v1ToV2);
221
- v2ToV1 && removed.push(v2ToV1);
220
+ if (v1ToV2)
221
+ removed.push(v1ToV2);
222
+ if (v2ToV1)
223
+ removed.push(v2ToV1);
222
224
  }
223
225
  return removed;
224
226
  }
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * data-structure-typed
3
3
  *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
8
  import type { VertexKey } from '../../types';
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * data-structure-typed
3
3
  *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
8
  import type { EntryCallback, HashMapLinkedNode, HashMapOptions, HashMapStoreItem, LinkedHashMapOptions } from '../../types';
@@ -86,7 +86,7 @@ export class HashMap extends IterableEntryBase {
86
86
  * @returns A boolean value indicating whether the size of the object is 0 or not.
87
87
  */
88
88
  isEmpty() {
89
- return this.size === 0;
89
+ return this._size === 0;
90
90
  }
91
91
  /**
92
92
  * The clear() function resets the state of an object by clearing its internal store, object map, and
@@ -577,7 +577,7 @@ export class FibonacciHeap {
577
577
  * @returns The top element or undefined if the heap is empty.
578
578
  */
579
579
  pop() {
580
- if (this.size === 0)
580
+ if (this._size === 0)
581
581
  return undefined;
582
582
  const z = this.min;
583
583
  if (z.child) {
@@ -710,7 +710,7 @@ export class FibonacciHeap {
710
710
  * @protected
711
711
  */
712
712
  _consolidate() {
713
- const A = new Array(this.size);
713
+ const A = new Array(this._size);
714
714
  const elements = this.consumeLinkedList(this.root);
715
715
  let x, y, d, t;
716
716
  for (const node of elements) {
@@ -729,7 +729,7 @@ export class FibonacciHeap {
729
729
  }
730
730
  A[d] = x;
731
731
  }
732
- for (let i = 0; i < this.size; i++) {
732
+ for (let i = 0; i < this._size; i++) {
733
733
  if (A[i] && this.comparator(A[i].element, this.min.element) <= 0) {
734
734
  this._min = A[i];
735
735
  }
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * data-structure-typed
3
3
  *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
8
  import type { DoublyLinkedListOptions, ElementCallback } from '../../types';