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
@@ -1,10 +1,20 @@
1
- import { IterableElementBase } from "../base";
2
- import { ElementCallback } from "../../types";
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 { ElementCallback } from '../../types';
9
+ import { IterableElementBase } from '../base';
3
10
 
4
11
  /**
5
- * @license MIT
6
- * @copyright Tyler Zeng <zrwusa@gmail.com>
7
- * @class
12
+ * 1. Last In, First Out (LIFO): The core characteristic of a stack is its last in, first out nature, meaning the last element added to the stack will be the first to be removed.
13
+ * 2. Uses: Stacks are commonly used for managing a series of tasks or elements that need to be processed in a last in, first out manner. They are widely used in various scenarios, such as in function calls in programming languages, evaluation of arithmetic expressions, and backtracking algorithms.
14
+ * 3. Performance: Stack operations are typically O(1) in time complexity, meaning that regardless of the stack's size, adding, removing, and viewing the top element are very fast operations.
15
+ * 4. Function Calls: In most modern programming languages, the records of function calls are managed through a stack. When a function is called, its record (including parameters, local variables, and return address) is 'pushed' into the stack. When the function returns, its record is 'popped' from the stack.
16
+ * 5. Expression Evaluation: Used for the evaluation of arithmetic or logical expressions, especially when dealing with parenthesis matching and operator precedence.
17
+ * 6. Backtracking Algorithms: In problems where multiple branches need to be explored but only one branch can be explored at a time, stacks can be used to save the state at each branching point.
8
18
  */
9
19
  export class Stack<E = any> extends IterableElementBase<E> {
10
20
  /**
@@ -94,9 +104,9 @@ export class Stack<E = any> extends IterableElementBase<E> {
94
104
  * @param {E} element - The parameter "element" is of type E, which means it can be any data type.
95
105
  * @returns The `push` method is returning the updated `Stack<E>` object.
96
106
  */
97
- push(element: E): Stack<E> {
107
+ push(element: E): boolean {
98
108
  this.elements.push(element);
99
- return this;
109
+ return true;
100
110
  }
101
111
 
102
112
  /**
@@ -113,9 +123,9 @@ export class Stack<E = any> extends IterableElementBase<E> {
113
123
  * array is empty, it returns `undefined`.
114
124
  */
115
125
  pop(): E | undefined {
116
- if (this.isEmpty()) return undefined;
126
+ if (this.isEmpty()) return;
117
127
 
118
- return this.elements.pop() || undefined;
128
+ return this.elements.pop();
119
129
  }
120
130
 
121
131
  /**
@@ -218,15 +228,11 @@ export class Stack<E = any> extends IterableElementBase<E> {
218
228
  return newStack;
219
229
  }
220
230
 
221
- print(): void {
222
- console.log([...this]);
223
- }
224
-
225
231
  /**
226
232
  * Custom iterator for the Stack class.
227
233
  * @returns An iterator object.
228
234
  */
229
- protected* _getIterator() {
235
+ protected* _getIterator(): IterableIterator<E> {
230
236
  for (let i = 0; i < this.elements.length; i++) {
231
237
  yield this.elements[i];
232
238
  }
@@ -5,9 +5,8 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
-
9
- import { IterableElementBase } from "../base";
10
- import { ElementCallback } from "../../types";
8
+ import type { ElementCallback } from '../../types';
9
+ import { IterableElementBase } from '../base';
11
10
 
12
11
  /**
13
12
  * TrieNode represents a node in the Trie data structure. It holds a character key, a map of children nodes,
@@ -26,7 +25,17 @@ export class TrieNode {
26
25
  }
27
26
 
28
27
  /**
29
- * Trie represents a Trie data structure. It provides basic Trie operations and additional methods.
28
+ * 1. Node Structure: Each node in a Trie represents a string (or a part of a string). The root node typically represents an empty string.
29
+ * 2. Child Node Relationship: Each node's children represent the strings that can be formed by adding one character to the string at the current node. For example, if a node represents the string 'ca', one of its children might represent 'cat'.
30
+ * 3. Fast Retrieval: Trie allows retrieval in O(m) time complexity, where m is the length of the string to be searched.
31
+ * 4. Space Efficiency: Trie can store a large number of strings very space-efficiently, especially when these strings share common prefixes.
32
+ * 5. Autocomplete and Prediction: Trie can be used for implementing autocomplete and word prediction features, as it can quickly find all strings with a common prefix.
33
+ * 6. Sorting: Trie can be used to sort a set of strings in alphabetical order.
34
+ * 7. String Retrieval: For example, searching for a specific string in a large set of strings.
35
+ * 8. Autocomplete: Providing recommended words or phrases as a user types.
36
+ * 9. Spell Check: Checking the spelling of words.
37
+ * 10. IP Routing: Used in certain types of IP routing algorithms.
38
+ * 11. Text Word Frequency Count: Counting and storing the frequency of words in a large amount of text data."
30
39
  */
31
40
  export class Trie extends IterableElementBase<string> {
32
41
  constructor(words?: string[], caseSensitive = true) {
@@ -129,7 +138,7 @@ export class Trie extends IterableElementBase<string> {
129
138
  * @param{string} word - The word to delete.
130
139
  * @returns {boolean} True if the word was successfully removed.
131
140
  */
132
- delete(word: string) {
141
+ delete(word: string): boolean {
133
142
  word = this._caseProcess(word);
134
143
  let isDeleted = false;
135
144
  const dfs = (cur: TrieNode, i: number): boolean => {
@@ -175,7 +184,7 @@ export class Trie extends IterableElementBase<string> {
175
184
  * Space Complexity: O(1) - Constant space.
176
185
  *
177
186
  */
178
- getHeight() {
187
+ getHeight(): number {
179
188
  const beginRoot = this.root;
180
189
  let maxDepth = 0;
181
190
  if (beginRoot) {
@@ -362,12 +371,12 @@ export class Trie extends IterableElementBase<string> {
362
371
  * specific object as the context for the `predicate` function. If `thisArg` is provided, it will be
363
372
  * @returns The `filter` method is returning an array of strings (`string[]`).
364
373
  */
365
- filter(predicate: ElementCallback<string, boolean>, thisArg?: any): string[] {
366
- const results: string[] = [];
374
+ filter(predicate: ElementCallback<string, boolean>, thisArg?: any): Trie {
375
+ const results: Trie = new Trie();
367
376
  let index = 0;
368
377
  for (const word of this) {
369
378
  if (predicate.call(thisArg, word, index, this)) {
370
- results.push(word);
379
+ results.add(word);
371
380
  }
372
381
  index++;
373
382
  }
@@ -402,10 +411,6 @@ export class Trie extends IterableElementBase<string> {
402
411
  return newTrie;
403
412
  }
404
413
 
405
- print() {
406
- console.log([...this]);
407
- }
408
-
409
414
  protected* _getIterator(): IterableIterator<string> {
410
415
  function* _dfs(node: TrieNode, path: string): IterableIterator<string> {
411
416
  if (node.isEnd) {
@@ -1,11 +1,11 @@
1
1
  import { BinaryTree, BinaryTreeNode } from '../data-structures';
2
2
  import {
3
+ BinaryTreeDeleteResult,
3
4
  BinaryTreeNested,
4
5
  BinaryTreeNodeNested,
5
6
  BinaryTreeOptions,
6
- BiTreeDeleteResult,
7
7
  BTNCallback,
8
- BTNodeExemplar,
8
+ BTNExemplar,
9
9
  } from '../types';
10
10
 
11
11
  export interface IBinaryTree<K = number, V = any, N extends BinaryTreeNode<K, V, N> = BinaryTreeNodeNested<K, V>, TREE extends BinaryTree<K, V, N, TREE> = BinaryTreeNested<K, V, N>> {
@@ -13,9 +13,9 @@ export interface IBinaryTree<K = number, V = any, N extends BinaryTreeNode<K, V,
13
13
 
14
14
  createTree(options?: Partial<BinaryTreeOptions<K>>): TREE;
15
15
 
16
- add(keyOrNodeOrEntry: BTNodeExemplar<K, V, N>, value?: V, count?: number): N | null | undefined;
16
+ add(keyOrNodeOrEntry: BTNExemplar<K, V, N>, value?: V, count?: number): N | null | undefined;
17
17
 
18
- addMany(nodes: Iterable<BTNodeExemplar<K, V, N>>, values?: Iterable<V | undefined>): (N | null | undefined)[];
18
+ addMany(nodes: Iterable<BTNExemplar<K, V, N>>, values?: Iterable<V | undefined>): (N | null | undefined)[];
19
19
 
20
- delete<C extends BTNCallback<N>>(identifier: ReturnType<C> | null, callback: C): BiTreeDeleteResult<N>[];
20
+ delete<C extends BTNCallback<N>>(identifier: ReturnType<C> | null, callback: C): BinaryTreeDeleteResult<N>[];
21
21
  }
@@ -1,20 +1,43 @@
1
- export type Comparator<K> = (a: K, b: K) => number;
2
-
3
1
  export enum BSTVariant {
4
2
  MIN = 'MIN',
5
3
  MAX = 'MAX',
6
4
  }
7
5
 
8
- export type DFSOrderPattern = 'pre' | 'in' | 'post';
9
-
10
- export type BTNCallback<N, D = any> = (node: N) => D;
11
-
12
6
  export enum CP {
13
7
  lt = 'lt',
14
8
  eq = 'eq',
15
9
  gt = 'gt'
16
10
  }
17
11
 
12
+ /**
13
+ * Enum representing different loop types.
14
+ *
15
+ * - `iterative`: Indicates the iterative loop type (with loops that use iterations).
16
+ * - `recursive`: Indicates the recursive loop type (with loops that call themselves).
17
+ */
18
+ export enum IterationType {
19
+ ITERATIVE = 'ITERATIVE',
20
+ RECURSIVE = 'RECURSIVE'
21
+ }
22
+
23
+ export enum FamilyPosition {
24
+ ROOT = 'ROOT',
25
+ LEFT = 'LEFT',
26
+ RIGHT = 'RIGHT',
27
+ ROOT_LEFT = 'ROOT_LEFT',
28
+ ROOT_RIGHT = 'ROOT_RIGHT',
29
+ ISOLATED = 'ISOLATED',
30
+ MAL_NODE = 'MAL_NODE'
31
+ }
32
+
33
+ export type Comparator<K> = (a: K, b: K) => number;
34
+
35
+ export type DFSOrderPattern = 'pre' | 'in' | 'post';
36
+
37
+ export type NodeDisplayLayout = [string[], number, number, number];
38
+
39
+ export type BTNCallback<N, D = any> = (node: N) => D;
40
+
18
41
  export interface IterableWithSize<T> extends Iterable<T> {
19
42
  size: number | ((...args: any[]) => number);
20
43
  }
@@ -27,14 +50,16 @@ export type IterableWithSizeOrLength<T> = IterableWithSize<T> | IterableWithLeng
27
50
 
28
51
  export type BinaryTreePrintOptions = { isShowUndefined?: boolean, isShowNull?: boolean, isShowRedBlackNIL?: boolean }
29
52
 
30
- export type BTNodeEntry<K, V> = [K | null | undefined, V | undefined];
31
-
32
- export type BTNodeKeyOrNode<K, N> = K | null | undefined | N;
53
+ export type BTNEntry<K, V> = [K | null | undefined, V | undefined];
33
54
 
34
- export type BTNodeExemplar<K, V, N> = BTNodeEntry<K, V> | BTNodeKeyOrNode<K, N>
55
+ export type BTNKeyOrNode<K, N> = K | null | undefined | N;
35
56
 
36
- export type BTNodePureExemplar<K, V, N> = [K, V | undefined] | BTNodePureKeyOrNode<K, N>
57
+ export type BTNExemplar<K, V, N> = BTNEntry<K, V> | BTNKeyOrNode<K, N>
37
58
 
38
59
  export type BTNodePureKeyOrNode<K, N> = K | N;
39
60
 
40
- export type BSTNodeKeyOrNode<K, N> = K | undefined | N;
61
+ export type BTNodePureExemplar<K, V, N> = [K, V | undefined] | BTNodePureKeyOrNode<K, N>;
62
+
63
+ export type BSTNKeyOrNode<K, N> = K | undefined | N;
64
+
65
+ export type BinaryTreeDeleteResult<N> = { deleted: N | null | undefined; needBalanced: N | null | undefined };
@@ -5,5 +5,4 @@ export type AVLTreeNodeNested<K, V> = AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTre
5
5
 
6
6
  export type AVLTreeNested<K, V, N extends AVLTreeNode<K, V, N>> = AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
7
7
 
8
-
9
8
  export type AVLTreeOptions<K> = BSTOptions<K> & {};
@@ -1,28 +1,5 @@
1
1
  import { BinaryTree, BinaryTreeNode } from '../../../data-structures';
2
-
3
- /**
4
- * Enum representing different loop types.
5
- *
6
- * - `iterative`: Indicates the iterative loop type (with loops that use iterations).
7
- * - `recursive`: Indicates the recursive loop type (with loops that call themselves).
8
- */
9
-
10
- export enum IterationType {
11
- ITERATIVE = 'ITERATIVE',
12
- RECURSIVE = 'RECURSIVE'
13
- }
14
-
15
- export enum FamilyPosition {
16
- ROOT = 'ROOT',
17
- LEFT = 'LEFT',
18
- RIGHT = 'RIGHT',
19
- ROOT_LEFT = 'ROOT_LEFT',
20
- ROOT_RIGHT = 'ROOT_RIGHT',
21
- ISOLATED = 'ISOLATED',
22
- MAL_NODE = 'MAL_NODE'
23
- }
24
-
25
- export type BiTreeDeleteResult<N> = { deleted: N | null | undefined; needBalanced: N | null | undefined };
2
+ import { IterationType } from "../../common";
26
3
 
27
4
  export type BinaryTreeNodeNested<K, V> = BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
28
5
 
@@ -32,5 +9,3 @@ export type BinaryTreeOptions<K> = {
32
9
  iterationType: IterationType,
33
10
  extractor: (key: K) => number
34
11
  }
35
-
36
- export type NodeDisplayLayout = [string[], number, number, number];
@@ -2,7 +2,6 @@ import { BST, BSTNode } from '../../../data-structures';
2
2
  import type { BinaryTreeOptions } from './binary-tree';
3
3
  import { BSTVariant } from "../../common";
4
4
 
5
- // prettier-ignore
6
5
  export type BSTNodeNested<K, V> = BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
7
6
 
8
7
  export type BSTNested<K, V, N extends BSTNode<K, V, N>> = BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@@ -1,5 +1,5 @@
1
1
  import { RedBlackTree, RedBlackTreeNode } from '../../../data-structures';
2
- import { BSTOptions } from "./bst";
2
+ import type { BSTOptions } from "./bst";
3
3
 
4
4
  export enum RBTNColor { RED = 1, BLACK = 0}
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { TreeMultimap, TreeMultimapNode } from '../../../data-structures';
2
- import { AVLTreeOptions } from './avl-tree';
2
+ import type { AVLTreeOptions } from './avl-tree';
3
3
 
4
4
  export type TreeMultimapNodeNested<K, V> = TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
5
5
 
@@ -47,23 +47,23 @@ if (isCompetitor) {
47
47
  }
48
48
 
49
49
  suite
50
- .add(`SRC PQ ${TEN_THOUSAND.toLocaleString()} add & pop`, () => {
50
+ .add(`SRC PQ ${TEN_THOUSAND.toLocaleString()} add & poll`, () => {
51
51
  const pq = new SRCPriorityQueue<number>([], { comparator: (a, b) => b - a });
52
52
 
53
53
  for (let i = 0; i < TEN_THOUSAND; i++) pq.add(i);
54
- for (let i = 0; i < TEN_THOUSAND; i++) pq.pop();
54
+ for (let i = 0; i < TEN_THOUSAND; i++) pq.poll();
55
55
  })
56
- .add(`CJS PQ ${TEN_THOUSAND.toLocaleString()} add & pop`, () => {
56
+ .add(`CJS PQ ${TEN_THOUSAND.toLocaleString()} add & poll`, () => {
57
57
  const pq = new CJSPriorityQueue<number>([], { comparator: (a, b) => b - a });
58
58
 
59
59
  for (let i = 0; i < TEN_THOUSAND; i++) pq.add(i);
60
- for (let i = 0; i < TEN_THOUSAND; i++) pq.pop();
60
+ for (let i = 0; i < TEN_THOUSAND; i++) pq.poll();
61
61
  })
62
- .add(`MJS PQ ${TEN_THOUSAND.toLocaleString()} add & pop`, () => {
62
+ .add(`MJS PQ ${TEN_THOUSAND.toLocaleString()} add & poll`, () => {
63
63
  const pq = new MJSPriorityQueue<number>([], { comparator: (a, b) => b - a });
64
64
 
65
65
  for (let i = 0; i < TEN_THOUSAND; i++) pq.add(i);
66
- for (let i = 0; i < TEN_THOUSAND; i++) pq.pop();
66
+ for (let i = 0; i < TEN_THOUSAND; i++) pq.poll();
67
67
  });
68
68
 
69
69
 
@@ -6,7 +6,7 @@ const suite = new Benchmark.Suite();
6
6
  const { HUNDRED_THOUSAND, TEN_THOUSAND } = magnitude;
7
7
 
8
8
  suite
9
- .add(`${HUNDRED_THOUSAND.toLocaleString()} add & pop`, () => {
9
+ .add(`${HUNDRED_THOUSAND.toLocaleString()} add & poll`, () => {
10
10
  const heap = new Heap<number>([], { comparator: (a, b) => b - a });
11
11
 
12
12
  for (let i = 0; i < HUNDRED_THOUSAND; i++) {
@@ -14,7 +14,7 @@ suite
14
14
  }
15
15
 
16
16
  for (let i = 0; i < HUNDRED_THOUSAND; i++) {
17
- heap.pop();
17
+ heap.poll();
18
18
  }
19
19
  })
20
20
  .add(`${HUNDRED_THOUSAND.toLocaleString()} add & dfs`, () => {
@@ -55,7 +55,7 @@ suite
55
55
  list.shift();
56
56
  }
57
57
  })
58
- .add(`${LINEAR.toLocaleString()} insertBefore`, () => {
58
+ .add(`${LINEAR.toLocaleString()} addBefore`, () => {
59
59
  const doublyList = new DoublyLinkedList<number>();
60
60
  let midNode: DoublyLinkedListNode | undefined;
61
61
  const midIndex = Math.floor(LINEAR / 2);
@@ -64,7 +64,7 @@ suite
64
64
  if (i === midIndex) {
65
65
  midNode = doublyList.getNode(i);
66
66
  } else if (i > midIndex && midNode) {
67
- doublyList.insertBefore(midNode, i);
67
+ doublyList.addBefore(midNode, i);
68
68
  }
69
69
  }
70
70
  });
@@ -28,7 +28,7 @@ suite
28
28
  list.pop();
29
29
  }
30
30
  })
31
- .add(`${TEN_THOUSAND.toLocaleString()} insertBefore`, () => {
31
+ .add(`${TEN_THOUSAND.toLocaleString()} addBefore`, () => {
32
32
  const singlyList = new SinglyLinkedList<number>();
33
33
  let midSinglyNode: SinglyLinkedListNode | undefined;
34
34
  const midIndex = Math.floor(TEN_THOUSAND / 2);
@@ -37,7 +37,7 @@ suite
37
37
  if (i === midIndex) {
38
38
  midSinglyNode = singlyList.getNode(i);
39
39
  } else if (i > midIndex && midSinglyNode) {
40
- singlyList.insertBefore(midSinglyNode.value, i);
40
+ singlyList.addBefore(midSinglyNode.value, i);
41
41
  }
42
42
  }
43
43
  });
@@ -7,7 +7,7 @@ import { isCompetitor } from '../../../config';
7
7
  const suite = new Benchmark.Suite();
8
8
  const { HUNDRED_THOUSAND } = magnitude;
9
9
 
10
- suite.add(`${HUNDRED_THOUSAND.toLocaleString()} add & pop`, () => {
10
+ suite.add(`${HUNDRED_THOUSAND.toLocaleString()} add & poll`, () => {
11
11
  const pq = new PriorityQueue<number>([], { comparator: (a, b) => b - a });
12
12
 
13
13
  for (let i = 0; i < HUNDRED_THOUSAND; i++) {
@@ -15,7 +15,7 @@ suite.add(`${HUNDRED_THOUSAND.toLocaleString()} add & pop`, () => {
15
15
  }
16
16
 
17
17
  for (let i = 0; i < HUNDRED_THOUSAND; i++) {
18
- pq.pop();
18
+ pq.poll();
19
19
  }
20
20
  });
21
21
  if (isCompetitor) {
@@ -1,8 +1,8 @@
1
1
  import { BinaryTree, BinaryTreeNode, FamilyPosition, IterationType } from '../../../../src';
2
2
  import { getRandomIntArray } from '../../../utils';
3
- import { isDebugTest } from '../../../config';
3
+ // import { isDebugTest } from '../../../config';
4
4
 
5
- const isDebug = isDebugTest;
5
+ // const isDebug = isDebugTest;
6
6
 
7
7
  describe('BinaryTreeNode', () => {
8
8
  it('should create an instance of BinaryTreeNode', () => {
@@ -588,7 +588,7 @@ describe('cycles, strongly connected components, bridges, articular points in Di
588
588
  const cutVertexes = graph.getCutVertexes();
589
589
  const dfnMap = graph.getDFNMap();
590
590
  const lowMap = graph.getLowMap();
591
- expect(cycles.size).toBe(1);
591
+ expect(cycles.size).toBe(2);
592
592
  expect(scCs.size).toBe(5);
593
593
  expect(bridges.length).toBe(4);
594
594
  expect(cutVertexes.length).toBe(4);
@@ -673,3 +673,23 @@ describe('DirectedGraph iterative Methods', () => {
673
673
  })
674
674
  });
675
675
 
676
+ describe('DirectedGraph getCycles', () => {
677
+ test('should getCycles return correct result', () => {
678
+ const graph = new DirectedGraph();
679
+ graph.addVertex('A');
680
+ graph.addVertex('B');
681
+ graph.addVertex('C');
682
+ graph.addVertex('D');
683
+ graph.addVertex('E');
684
+ graph.addEdge('A', 'B');
685
+ graph.addEdge('A', 'C');
686
+ graph.addEdge('B', 'D');
687
+ graph.addEdge('C', 'D');
688
+ graph.addEdge('D', 'E');
689
+ graph.addEdge('E', 'B');
690
+ const cycles = graph.getCycles();
691
+ expect(cycles.size).toBe(1);
692
+ expect(cycles.get(2)).toEqual( [{ "key": "B", "value": undefined }, { "key": "D", "value": undefined }, { "key": "E", "value": undefined }]);
693
+ })
694
+ })
695
+
@@ -237,10 +237,48 @@ describe('cycles, strongly connected components, bridges, articular points in Un
237
237
  const cutVertexes = graph.getCutVertexes();
238
238
  const dfnMap = graph.getDFNMap();
239
239
  const lowMap = graph.getLowMap();
240
- expect(cycles.size).toBe(1);
240
+ expect(cycles.size).toBe(2);
241
241
  expect(scCs.size).toBe(5);
242
242
  expect(bridges.length).toBe(4);
243
243
  expect(cutVertexes.length).toBe(4);
244
244
  expect(dfnMap.size).toBe(8);
245
245
  expect(lowMap.size).toBe(8);
246
246
  });
247
+
248
+ it("Should return Infinity if dest is not found", () => {
249
+
250
+ const graph = new UndirectedGraph<string>();
251
+
252
+ for (let i = 0; i < 3; ++i) {
253
+ graph.addVertex(graph.createVertex(i, `${i}`));
254
+ }
255
+
256
+ graph.addEdge(0, 1, 1);
257
+
258
+ const minCost02 = graph.getMinCostBetween(0, 2, true);
259
+ expect(minCost02).toBe(Infinity);
260
+
261
+ const minCost01 = graph.getMinCostBetween(0, 1, true);
262
+ expect(minCost01).toBe(1);
263
+ });
264
+
265
+ describe('UndirectedGraph getCycles', () => {
266
+ test('should getCycles return correct result', () => {
267
+ const graph = new UndirectedGraph();
268
+ graph.addVertex('A');
269
+ graph.addVertex('B');
270
+ graph.addVertex('C');
271
+ graph.addVertex('D');
272
+ graph.addVertex('E');
273
+ graph.addEdge('A', 'B');
274
+ graph.addEdge('A', 'C');
275
+ graph.addEdge('B', 'D');
276
+ graph.addEdge('C', 'D');
277
+ graph.addEdge('D', 'E');
278
+ graph.addEdge('E', 'B');
279
+ const cycles = graph.getCycles();
280
+ expect(cycles.size).toBe(2);
281
+ expect(cycles.get(1)).toEqual([{ "key": "A", "value": "A" }, { "key": "B", "value": "B" }, { "key": "D", "value": "D" }, { "key": "C", "value": "C" }]);
282
+ expect(cycles.get(2)).toEqual([{ "key": "B", "value": "B" }, { "key": "D", "value": "D" }, { "key": "E", "value": "E" }]);
283
+ })
284
+ })
@@ -453,7 +453,7 @@ describe('LinkedHashMap Test2', () => {
453
453
  expect(hashMap.last).toEqual([key, value]);
454
454
  expect(hashMap.reverseBegin().next().value).toEqual([key, value]);
455
455
  } else if (index <= 1000) {
456
- expect(hashMap.getAt(index)).toEqual([key, value]);
456
+ expect(hashMap.getAt(index)).toBe(value);
457
457
  }
458
458
  expect(hashMap.get(key)).toEqual(value);
459
459
  index++;
@@ -502,7 +502,7 @@ describe('LinkedHashMap Test2', () => {
502
502
  test('should get element at specific index', () => {
503
503
  hashMap.set('key1', 'value1');
504
504
  hashMap.set('key2', 'value2');
505
- expect(hashMap.getAt(1)).toEqual(['key2', 'value2']);
505
+ expect(hashMap.getAt(1)).toBe('value2');
506
506
  });
507
507
  });
508
508
 
@@ -5,7 +5,7 @@ import { logBigOMetricsWrap } from '../../../utils';
5
5
  describe('Heap Operation Test', () => {
6
6
  it('should numeric heap work well', function () {
7
7
  const minNumHeap = new MinHeap<number>();
8
- minNumHeap.add(1).add(6).add(2).add(0).add(5).add(9);
8
+ minNumHeap.add(1);minNumHeap.add(6);minNumHeap.add(2);minNumHeap.add(0);minNumHeap.add(5);minNumHeap.add(9);
9
9
  expect(minNumHeap.has(1)).toBe(true);
10
10
  expect(minNumHeap.has(2)).toBe(true);
11
11
  expect(minNumHeap.poll()).toBe(0);
@@ -55,7 +55,7 @@ describe('MinHeap', () => {
55
55
 
56
56
  it('should push & dfs', () => {
57
57
  for (let i = 0; i < n; i++) {
58
- minHeap.push(i);
58
+ minHeap.add(i);
59
59
  }
60
60
  expect(minHeap.dfs()[0]).toBe(0)
61
61
  expect(minHeap.dfs()[999]).toBe(4126)