data-structure-typed 1.15.2 → 1.17.0

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 (212) hide show
  1. package/README.md +24 -24
  2. package/dist/data-structures/heap/heap.d.ts +30 -15
  3. package/dist/data-structures/heap/heap.js +60 -15
  4. package/dist/data-structures/heap/max-heap.d.ts +3 -3
  5. package/dist/data-structures/heap/min-heap.d.ts +3 -3
  6. package/dist/data-structures/index.d.ts +1 -0
  7. package/dist/data-structures/index.js +1 -0
  8. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +195 -68
  9. package/dist/data-structures/linked-list/doubly-linked-list.js +456 -244
  10. package/dist/data-structures/linked-list/singly-linked-list.d.ts +126 -241
  11. package/dist/data-structures/linked-list/singly-linked-list.js +331 -628
  12. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +4 -5
  13. package/dist/data-structures/priority-queue/max-priority-queue.js +30 -6
  14. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +4 -5
  15. package/dist/data-structures/priority-queue/min-priority-queue.js +31 -6
  16. package/dist/data-structures/priority-queue/priority-queue.d.ts +13 -2
  17. package/dist/data-structures/priority-queue/priority-queue.js +28 -22
  18. package/dist/data-structures/tree/index.d.ts +1 -0
  19. package/dist/data-structures/tree/index.js +17 -0
  20. package/dist/data-structures/tree/tree.d.ts +9 -0
  21. package/dist/data-structures/tree/tree.js +52 -0
  22. package/dist/data-structures/types/binary-tree.d.ts +0 -5
  23. package/dist/data-structures/types/heap.d.ts +0 -4
  24. package/dist/utils/types/utils.d.ts +1 -0
  25. package/docs/.nojekyll +1 -0
  26. package/docs/assets/highlight.css +92 -0
  27. package/docs/assets/main.js +58 -0
  28. package/docs/assets/search.js +1 -0
  29. package/docs/assets/style.css +1367 -0
  30. package/docs/classes/AVLTree.html +2191 -0
  31. package/docs/classes/AVLTreeNode.html +573 -0
  32. package/docs/classes/AaTree.html +149 -0
  33. package/docs/classes/AbstractEdge.html +268 -0
  34. package/docs/classes/AbstractGraph.html +926 -0
  35. package/docs/classes/AbstractVertex.html +214 -0
  36. package/docs/classes/ArrayDeque.html +416 -0
  37. package/docs/classes/BST.html +2037 -0
  38. package/docs/classes/BSTNode.html +569 -0
  39. package/docs/classes/BTree.html +149 -0
  40. package/docs/classes/BinaryIndexedTree.html +288 -0
  41. package/docs/classes/BinaryTree.html +1826 -0
  42. package/docs/classes/BinaryTreeNode.html +532 -0
  43. package/docs/classes/Character.html +197 -0
  44. package/docs/classes/CoordinateMap.html +468 -0
  45. package/docs/classes/CoordinateSet.html +429 -0
  46. package/docs/classes/Deque.html +897 -0
  47. package/docs/classes/DirectedEdge.html +353 -0
  48. package/docs/classes/DirectedGraph.html +1242 -0
  49. package/docs/classes/DirectedVertex.html +225 -0
  50. package/docs/classes/DoublyLinkedList.html +891 -0
  51. package/docs/classes/DoublyLinkedListNode.html +274 -0
  52. package/docs/classes/Heap.html +481 -0
  53. package/docs/classes/HeapItem.html +232 -0
  54. package/docs/classes/Matrix2D.html +479 -0
  55. package/docs/classes/MatrixNTI2D.html +217 -0
  56. package/docs/classes/MaxHeap.html +499 -0
  57. package/docs/classes/MaxPriorityQueue.html +808 -0
  58. package/docs/classes/MinHeap.html +500 -0
  59. package/docs/classes/MinPriorityQueue.html +810 -0
  60. package/docs/classes/Navigator.html +290 -0
  61. package/docs/classes/ObjectDeque.html +422 -0
  62. package/docs/classes/PriorityQueue.html +732 -0
  63. package/docs/classes/Queue.html +369 -0
  64. package/docs/classes/RBTree.html +149 -0
  65. package/docs/classes/SegmentTree.html +344 -0
  66. package/docs/classes/SegmentTreeNode.html +417 -0
  67. package/docs/classes/SinglyLinkedList.html +718 -0
  68. package/docs/classes/SinglyLinkedListNode.html +247 -0
  69. package/docs/classes/SplayTree.html +149 -0
  70. package/docs/classes/Stack.html +345 -0
  71. package/docs/classes/TreeMultiSet.html +2035 -0
  72. package/docs/classes/TreeNode.html +235 -0
  73. package/docs/classes/Trie.html +349 -0
  74. package/docs/classes/TrieNode.html +257 -0
  75. package/docs/classes/TwoThreeTree.html +149 -0
  76. package/docs/classes/UndirectedEdge.html +312 -0
  77. package/docs/classes/UndirectedGraph.html +1079 -0
  78. package/docs/classes/UndirectedVertex.html +225 -0
  79. package/docs/classes/Vector2D.html +782 -0
  80. package/docs/enums/CP.html +158 -0
  81. package/docs/enums/FamilyPosition.html +158 -0
  82. package/docs/enums/LoopType.html +159 -0
  83. package/docs/index.html +493 -0
  84. package/docs/interfaces/AVLTreeDeleted.html +160 -0
  85. package/docs/interfaces/HeapOptions.html +166 -0
  86. package/docs/interfaces/IDirectedGraph.html +242 -0
  87. package/docs/interfaces/IGraph.html +426 -0
  88. package/docs/interfaces/NavigatorParams.html +196 -0
  89. package/docs/interfaces/PriorityQueueOptions.html +167 -0
  90. package/docs/modules.html +216 -0
  91. package/docs/types/BSTComparator.html +139 -0
  92. package/docs/types/BSTDeletedResult.html +136 -0
  93. package/docs/types/BinaryTreeDeleted.html +136 -0
  94. package/docs/types/BinaryTreeNodeId.html +124 -0
  95. package/docs/types/BinaryTreeNodePropertyName.html +124 -0
  96. package/docs/types/DFSOrderPattern.html +124 -0
  97. package/docs/types/DijkstraResult.html +144 -0
  98. package/docs/types/Direction.html +124 -0
  99. package/docs/types/DoublyLinkedListGetBy.html +124 -0
  100. package/docs/types/NodeOrPropertyName.html +124 -0
  101. package/docs/types/PriorityQueueComparator.html +144 -0
  102. package/docs/types/PriorityQueueDFSOrderPattern.html +124 -0
  103. package/docs/types/ResultByProperty.html +129 -0
  104. package/docs/types/ResultsByProperty.html +129 -0
  105. package/docs/types/SegmentTreeNodeVal.html +124 -0
  106. package/docs/types/SpecifyOptional.html +131 -0
  107. package/docs/types/Thunk.html +132 -0
  108. package/docs/types/ToThunkFn.html +132 -0
  109. package/docs/types/TopologicalStatus.html +124 -0
  110. package/docs/types/TreeMultiSetDeletedResult.html +136 -0
  111. package/docs/types/TrlAsyncFn.html +137 -0
  112. package/docs/types/TrlFn.html +137 -0
  113. package/docs/types/Turning.html +124 -0
  114. package/docs/types/VertexId.html +124 -0
  115. package/{tests/unit/data-structures/binary-tree → notes}/bst.test.ts +37 -50
  116. package/notes/note.md +23 -0
  117. package/package.json +1 -3
  118. package/.idea/data-structure-typed.iml +0 -14
  119. package/.idea/modules.xml +0 -8
  120. package/.idea/vcs.xml +0 -6
  121. package/src/assets/complexities-diff.jpg +0 -0
  122. package/src/assets/data-structure-complexities.jpg +0 -0
  123. package/src/assets/logo.png +0 -0
  124. package/src/assets/overview-diagram-of-data-structures.png +0 -0
  125. package/src/data-structures/binary-tree/aa-tree.ts +0 -3
  126. package/src/data-structures/binary-tree/avl-tree.ts +0 -293
  127. package/src/data-structures/binary-tree/b-tree.ts +0 -3
  128. package/src/data-structures/binary-tree/binary-indexed-tree.ts +0 -69
  129. package/src/data-structures/binary-tree/binary-tree.ts +0 -1492
  130. package/src/data-structures/binary-tree/bst.ts +0 -497
  131. package/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
  132. package/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
  133. package/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
  134. package/src/data-structures/binary-tree/index.ts +0 -11
  135. package/src/data-structures/binary-tree/rb-tree.ts +0 -3
  136. package/src/data-structures/binary-tree/segment-tree.ts +0 -267
  137. package/src/data-structures/binary-tree/splay-tree.ts +0 -3
  138. package/src/data-structures/binary-tree/tree-multiset.ts +0 -53
  139. package/src/data-structures/binary-tree/two-three-tree.ts +0 -3
  140. package/src/data-structures/diagrams/README.md +0 -5
  141. package/src/data-structures/graph/abstract-graph.ts +0 -958
  142. package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
  143. package/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
  144. package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
  145. package/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
  146. package/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
  147. package/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
  148. package/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
  149. package/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
  150. package/src/data-structures/graph/diagrams/mst.jpg +0 -0
  151. package/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
  152. package/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
  153. package/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
  154. package/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
  155. package/src/data-structures/graph/diagrams/tarjan.webp +0 -0
  156. package/src/data-structures/graph/directed-graph.ts +0 -429
  157. package/src/data-structures/graph/index.ts +0 -3
  158. package/src/data-structures/graph/undirected-graph.ts +0 -259
  159. package/src/data-structures/hash/coordinate-map.ts +0 -74
  160. package/src/data-structures/hash/coordinate-set.ts +0 -63
  161. package/src/data-structures/hash/hash-table.ts +0 -1
  162. package/src/data-structures/hash/index.ts +0 -6
  163. package/src/data-structures/hash/pair.ts +0 -1
  164. package/src/data-structures/hash/tree-map.ts +0 -1
  165. package/src/data-structures/hash/tree-set.ts +0 -1
  166. package/src/data-structures/heap/heap.ts +0 -162
  167. package/src/data-structures/heap/index.ts +0 -3
  168. package/src/data-structures/heap/max-heap.ts +0 -31
  169. package/src/data-structures/heap/min-heap.ts +0 -34
  170. package/src/data-structures/index.ts +0 -13
  171. package/src/data-structures/linked-list/doubly-linked-list.ts +0 -365
  172. package/src/data-structures/linked-list/index.ts +0 -2
  173. package/src/data-structures/linked-list/singly-linked-list.ts +0 -757
  174. package/src/data-structures/linked-list/skip-linked-list.ts +0 -1
  175. package/src/data-structures/matrix/index.ts +0 -4
  176. package/src/data-structures/matrix/matrix.ts +0 -27
  177. package/src/data-structures/matrix/matrix2d.ts +0 -208
  178. package/src/data-structures/matrix/navigator.ts +0 -122
  179. package/src/data-structures/matrix/vector2d.ts +0 -316
  180. package/src/data-structures/priority-queue/index.ts +0 -3
  181. package/src/data-structures/priority-queue/max-priority-queue.ts +0 -24
  182. package/src/data-structures/priority-queue/min-priority-queue.ts +0 -24
  183. package/src/data-structures/priority-queue/priority-queue.ts +0 -349
  184. package/src/data-structures/queue/deque.ts +0 -251
  185. package/src/data-structures/queue/index.ts +0 -2
  186. package/src/data-structures/queue/queue.ts +0 -120
  187. package/src/data-structures/stack/index.ts +0 -1
  188. package/src/data-structures/stack/stack.ts +0 -98
  189. package/src/data-structures/trie/index.ts +0 -1
  190. package/src/data-structures/trie/trie.ts +0 -225
  191. package/src/data-structures/types/abstract-graph.ts +0 -51
  192. package/src/data-structures/types/avl-tree.ts +0 -6
  193. package/src/data-structures/types/binary-tree.ts +0 -15
  194. package/src/data-structures/types/bst.ts +0 -5
  195. package/src/data-structures/types/directed-graph.ts +0 -18
  196. package/src/data-structures/types/doubly-linked-list.ts +0 -1
  197. package/src/data-structures/types/heap.ts +0 -8
  198. package/src/data-structures/types/index.ts +0 -13
  199. package/src/data-structures/types/navigator.ts +0 -13
  200. package/src/data-structures/types/priority-queue.ts +0 -9
  201. package/src/data-structures/types/segment-tree.ts +0 -1
  202. package/src/data-structures/types/singly-linked-list.ts +0 -1
  203. package/src/data-structures/types/tree-multiset.ts +0 -3
  204. package/src/index.ts +0 -1
  205. package/src/utils/index.ts +0 -2
  206. package/src/utils/types/index.ts +0 -1
  207. package/src/utils/types/utils.ts +0 -4
  208. package/src/utils/utils.ts +0 -78
  209. package/tests/unit/data-structures/graph/abstract-graph.ts +0 -0
  210. package/tests/unit/data-structures/graph/directed-graph.test.ts +0 -492
  211. package/tests/unit/data-structures/graph/index.ts +0 -3
  212. package/tests/unit/data-structures/graph/undirected-graph.ts +0 -0
package/README.md CHANGED
@@ -15,6 +15,12 @@ Hash, Coordinate Set, Coordinate Map, Heap, Priority Queue, Max Priority Queue,
15
15
 
16
16
  # How
17
17
 
18
+ [API Docs](https://data-structure-typed-docs.vercel.app)
19
+
20
+ [Live Examples](https://data-structure-typed-examples.vercel.app)
21
+
22
+ <a href="https://data-structure-typed-examples.vercel.app" target="_blank">Live Examples</a>
23
+
18
24
  ## install
19
25
 
20
26
  ### yarn
@@ -130,12 +136,6 @@ npm install data-structure-typed
130
136
  expect(bfsNodes[2].id).toBe(16);
131
137
  ```
132
138
 
133
- ## Live Examples
134
-
135
- [//]: # ([Live Examples]&#40;https://data-structure-typed-examples.vercel.app&#41;)
136
-
137
- <a href="https://data-structure-typed-examples.vercel.app" target="_blank">Live Examples</a>
138
-
139
139
  ### Directed Graph simple snippet
140
140
 
141
141
  ```typescript
@@ -733,41 +733,41 @@ describe('DirectedGraph Test3', () => {
733
733
  </tbody>
734
734
  </table>
735
735
 
736
- ![overview diagram](src/assets/overview-diagram-of-data-structures.png)
736
+ ![overview diagram](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/assets/overview-diagram-of-data-structures.png)
737
737
 
738
- ![complexities](src/assets/complexities-diff.jpg)
738
+ ![complexities](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/assets/complexities-diff.jpg)
739
739
 
740
- ![complexities of data structures](src/assets/data-structure-complexities.jpg)
740
+ ![complexities of data structures](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/assets/data-structure-complexities.jpg)
741
741
 
742
- ![](src/data-structures/binary-tree/diagrams/bst-rotation.gif)
742
+ ![](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/binary-tree/bst-rotation.gif)
743
743
 
744
- ![](src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif)
744
+ ![](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/binary-tree/avl-tree-inserting.gif)
745
745
 
746
- ![](src/data-structures/graph/diagrams/tarjan.webp)
746
+ ![](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/tarjan.webp)
747
747
 
748
- ![](src/data-structures/graph/diagrams/adjacency-list.jpg)
748
+ ![](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/adjacency-list.jpg)
749
749
 
750
- ![](src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg)
750
+ ![](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/adjacency-list-pros-cons.jpg)
751
751
 
752
- ![](src/data-structures/graph/diagrams/adjacency-matrix.jpg)
752
+ ![](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/adjacency-matrix.jpg)
753
753
 
754
- ![](src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg)
754
+ ![](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/adjacency-matrix-pros-cons.jpg)
755
755
 
756
- ![](src/data-structures/graph/diagrams/dfs-can-do.jpg)
756
+ ![](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/dfs-can-do.jpg)
757
757
 
758
- ![](src/data-structures/graph/diagrams/edge-list.jpg)
758
+ ![](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/edge-list.jpg)
759
759
 
760
- ![](src/data-structures/graph/diagrams/edge-list-pros-cons.jpg)
760
+ ![](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/edge-list-pros-cons.jpg)
761
761
 
762
- ![](src/data-structures/graph/diagrams/max-flow.jpg)
762
+ ![](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/max-flow.jpg)
763
763
 
764
- ![](src/data-structures/graph/diagrams/mst.jpg)
764
+ ![](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/mst.jpg)
765
765
 
766
- [//]: # (![]&#40;src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png&#41;)
766
+ [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/tarjan-articulation-point-bridge.png&#41;)
767
767
 
768
- [//]: # (![]&#40;src/data-structures/graph/diagrams/tarjan-complicate-simple.png&#41;)
768
+ [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/tarjan-complicate-simple.png&#41;)
769
769
 
770
- [//]: # (![]&#40;src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png&#41;)
770
+ [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/tarjan-strongly-connected-component.png&#41;)
771
771
 
772
772
 
773
773
 
@@ -6,8 +6,17 @@
6
6
  * @license MIT License
7
7
  */
8
8
  import { PriorityQueue } from '../priority-queue';
9
- import type { HeapItem, HeapOptions } from '../types';
10
- export declare abstract class Heap<T> {
9
+ import type { HeapOptions } from '../types';
10
+ export declare class HeapItem<T = number> {
11
+ constructor(priority?: number, val?: T | null);
12
+ private _priority;
13
+ get priority(): number;
14
+ set priority(value: number);
15
+ private _val;
16
+ get val(): T | null;
17
+ set val(value: T | null);
18
+ }
19
+ export declare abstract class Heap<T = number> {
11
20
  /**
12
21
  * The function is a constructor for a class that initializes a priority callback function based on the
13
22
  * options provided.
@@ -17,9 +26,9 @@ export declare abstract class Heap<T> {
17
26
  protected abstract _pq: PriorityQueue<HeapItem<T>>;
18
27
  get pq(): PriorityQueue<HeapItem<T>>;
19
28
  protected set pq(v: PriorityQueue<HeapItem<T>>);
20
- protected _priorityCb: (element: T) => number;
21
- get priorityCb(): (element: T) => number;
22
- protected set priorityCb(v: (element: T) => number);
29
+ protected _priorityCb: (val: T) => number;
30
+ get priorityCb(): (val: T) => number;
31
+ protected set priorityCb(v: (val: T) => number);
23
32
  /**
24
33
  * The function returns the size of a priority queue.
25
34
  * @returns The size of the priority queue.
@@ -32,7 +41,7 @@ export declare abstract class Heap<T> {
32
41
  /**
33
42
  * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
34
43
  */
35
- getPriorityCb(): (element: T) => number;
44
+ getPriorityCb(): (val: T) => number;
36
45
  /**
37
46
  * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
38
47
  */
@@ -44,33 +53,39 @@ export declare abstract class Heap<T> {
44
53
  isEmpty(): boolean;
45
54
  /**
46
55
  * The `peek` function returns the top item in the priority queue without removing it.
47
- * @returns The `peek()` method is returning either a `HeapItem<T>` object or `null`.Returns an element with the highest priority in the queue
56
+ * @returns The `peek()` method is returning either a `HeapItem<T>` object or `null`.Returns an val with the highest priority in the queue
48
57
  */
49
58
  peek(): HeapItem<T> | null;
50
59
  /**
51
60
  * The `peekLast` function returns the last item in the heap.
52
- * @returns The method `peekLast()` returns either a `HeapItem<T>` object or `null`.Returns an element with the lowest priority in the queue
61
+ * @returns The method `peekLast()` returns either a `HeapItem<T>` object or `null`.Returns an val with the lowest priority in the queue
53
62
  */
54
63
  peekLast(): HeapItem<T> | null;
55
64
  /**
56
- * The `add` function adds an element to a priority queue with an optional priority value.
57
- * @param {T} element - The `element` parameter represents the value that you want to add to the heap. It can be of any
65
+ * The `add` function adds an val to a priority queue with an optional priority value.
66
+ * @param {T} val - The `val` parameter represents the value that you want to add to the heap. It can be of any
58
67
  * type.
59
68
  * @param {number} [priority] - The `priority` parameter is an optional number that represents the priority of the
60
- * element being added to the heap. If the `element` parameter is a number, then the `priority` parameter is set to
61
- * the value of `element`. If the `element` parameter is not a number, then the
69
+ * val being added to the heap. If the `val` parameter is a number, then the `priority` parameter is set to
70
+ * the value of `val`. If the `val` parameter is not a number, then the
62
71
  * @returns The `add` method returns the instance of the `Heap` class.
63
72
  * @throws {Error} if priority is not a valid number
64
73
  */
65
- add(element: T, priority?: number): Heap<T>;
74
+ add(val: T, priority?: number): Heap<T>;
66
75
  /**
67
- * The `poll` function returns the top item from a priority queue or null if the queue is empty.Removes and returns an element with the highest priority in the queue
76
+ * The `poll` function returns the top item from a priority queue or null if the queue is empty.Removes and returns an val with the highest priority in the queue
68
77
  * @returns either a HeapItem<T> object or null.
69
78
  */
70
79
  poll(): HeapItem<T> | null;
80
+ /**
81
+ * The function checks if a given node or value exists in the priority queue.
82
+ * @param {T | HeapItem<T>} node - The parameter `node` can be of type `T` or `HeapItem<T>`.
83
+ * @returns a boolean value.
84
+ */
85
+ has(node: T | HeapItem<T>): boolean;
71
86
  /**
72
87
  * The `toArray` function returns an array of `HeapItem<T>` objects.
73
- * @returns An array of HeapItem<T> objects.Returns a sorted list of elements
88
+ * @returns An array of HeapItem<T> objects.Returns a sorted list of vals
74
89
  */
75
90
  toArray(): HeapItem<T>[];
76
91
  /**
@@ -1,6 +1,36 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Heap = void 0;
3
+ exports.Heap = exports.HeapItem = void 0;
4
+ var HeapItem = /** @class */ (function () {
5
+ function HeapItem(priority, val) {
6
+ if (priority === void 0) { priority = NaN; }
7
+ if (val === void 0) { val = null; }
8
+ this._val = val;
9
+ this._priority = priority;
10
+ }
11
+ Object.defineProperty(HeapItem.prototype, "priority", {
12
+ get: function () {
13
+ return this._priority;
14
+ },
15
+ set: function (value) {
16
+ this._priority = value;
17
+ },
18
+ enumerable: false,
19
+ configurable: true
20
+ });
21
+ Object.defineProperty(HeapItem.prototype, "val", {
22
+ get: function () {
23
+ return this._val;
24
+ },
25
+ set: function (value) {
26
+ this._val = value;
27
+ },
28
+ enumerable: false,
29
+ configurable: true
30
+ });
31
+ return HeapItem;
32
+ }());
33
+ exports.HeapItem = HeapItem;
4
34
  var Heap = /** @class */ (function () {
5
35
  /**
6
36
  * The function is a constructor for a class that initializes a priority callback function based on the
@@ -77,31 +107,31 @@ var Heap = /** @class */ (function () {
77
107
  };
78
108
  /**
79
109
  * The `peek` function returns the top item in the priority queue without removing it.
80
- * @returns The `peek()` method is returning either a `HeapItem<T>` object or `null`.Returns an element with the highest priority in the queue
110
+ * @returns The `peek()` method is returning either a `HeapItem<T>` object or `null`.Returns an val with the highest priority in the queue
81
111
  */
82
112
  Heap.prototype.peek = function () {
83
113
  return this._pq.peek();
84
114
  };
85
115
  /**
86
116
  * The `peekLast` function returns the last item in the heap.
87
- * @returns The method `peekLast()` returns either a `HeapItem<T>` object or `null`.Returns an element with the lowest priority in the queue
117
+ * @returns The method `peekLast()` returns either a `HeapItem<T>` object or `null`.Returns an val with the lowest priority in the queue
88
118
  */
89
119
  Heap.prototype.peekLast = function () {
90
120
  return this._pq.leaf();
91
121
  };
92
122
  /**
93
- * The `add` function adds an element to a priority queue with an optional priority value.
94
- * @param {T} element - The `element` parameter represents the value that you want to add to the heap. It can be of any
123
+ * The `add` function adds an val to a priority queue with an optional priority value.
124
+ * @param {T} val - The `val` parameter represents the value that you want to add to the heap. It can be of any
95
125
  * type.
96
126
  * @param {number} [priority] - The `priority` parameter is an optional number that represents the priority of the
97
- * element being added to the heap. If the `element` parameter is a number, then the `priority` parameter is set to
98
- * the value of `element`. If the `element` parameter is not a number, then the
127
+ * val being added to the heap. If the `val` parameter is a number, then the `priority` parameter is set to
128
+ * the value of `val`. If the `val` parameter is not a number, then the
99
129
  * @returns The `add` method returns the instance of the `Heap` class.
100
130
  * @throws {Error} if priority is not a valid number
101
131
  */
102
- Heap.prototype.add = function (element, priority) {
103
- if (typeof element === 'number') {
104
- priority = element;
132
+ Heap.prototype.add = function (val, priority) {
133
+ if (typeof val === 'number') {
134
+ priority = val;
105
135
  }
106
136
  else {
107
137
  if (priority === undefined) {
@@ -111,16 +141,16 @@ var Heap = /** @class */ (function () {
111
141
  if (priority && Number.isNaN(+priority)) {
112
142
  throw new Error('.add expects a numeric priority');
113
143
  }
114
- if (Number.isNaN(+priority) && Number.isNaN(this._priorityCb(element))) {
144
+ if (Number.isNaN(+priority) && Number.isNaN(this._priorityCb(val))) {
115
145
  throw new Error('.add expects a numeric priority '
116
146
  + 'or a constructor callback that returns a number');
117
147
  }
118
- var _priority = !Number.isNaN(+priority) ? priority : this._priorityCb(element);
119
- this._pq.add({ priority: _priority, element: element });
148
+ var _priority = !Number.isNaN(+priority) ? priority : this._priorityCb(val);
149
+ this._pq.add(new HeapItem(_priority, val));
120
150
  return this;
121
151
  };
122
152
  /**
123
- * The `poll` function returns the top item from a priority queue or null if the queue is empty.Removes and returns an element with the highest priority in the queue
153
+ * The `poll` function returns the top item from a priority queue or null if the queue is empty.Removes and returns an val with the highest priority in the queue
124
154
  * @returns either a HeapItem<T> object or null.
125
155
  */
126
156
  Heap.prototype.poll = function () {
@@ -130,9 +160,24 @@ var Heap = /** @class */ (function () {
130
160
  }
131
161
  return top;
132
162
  };
163
+ /**
164
+ * The function checks if a given node or value exists in the priority queue.
165
+ * @param {T | HeapItem<T>} node - The parameter `node` can be of type `T` or `HeapItem<T>`.
166
+ * @returns a boolean value.
167
+ */
168
+ Heap.prototype.has = function (node) {
169
+ if (node instanceof (HeapItem)) {
170
+ return this.getPq().getNodes().includes(node);
171
+ }
172
+ else {
173
+ return this.getPq().getNodes().findIndex(function (item) {
174
+ return item.val === node;
175
+ }) !== -1;
176
+ }
177
+ };
133
178
  /**
134
179
  * The `toArray` function returns an array of `HeapItem<T>` objects.
135
- * @returns An array of HeapItem<T> objects.Returns a sorted list of elements
180
+ * @returns An array of HeapItem<T> objects.Returns a sorted list of vals
136
181
  */
137
182
  Heap.prototype.toArray = function () {
138
183
  return this._pq.toArray();
@@ -5,14 +5,14 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import { Heap } from './heap';
8
+ import { Heap, HeapItem } from './heap';
9
9
  import { PriorityQueue } from '../priority-queue';
10
- import type { HeapItem, HeapOptions } from '../types';
10
+ import type { HeapOptions } from '../types';
11
11
  /**
12
12
  * @class MaxHeap
13
13
  * @extends Heap
14
14
  */
15
- export declare class MaxHeap<T> extends Heap<T> {
15
+ export declare class MaxHeap<T = number> extends Heap<T> {
16
16
  protected _pq: PriorityQueue<HeapItem<T>>;
17
17
  /**
18
18
  * The constructor initializes a PriorityQueue with a custom comparator function.
@@ -5,14 +5,14 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import { Heap } from './heap';
8
+ import { Heap, HeapItem } from './heap';
9
9
  import { PriorityQueue } from '../priority-queue';
10
- import type { HeapItem, HeapOptions } from '../types';
10
+ import type { HeapOptions } from '../types';
11
11
  /**
12
12
  * @class MinHeap
13
13
  * @extends Heap
14
14
  */
15
- export declare class MinHeap<T> extends Heap<T> {
15
+ export declare class MinHeap<T = number> extends Heap<T> {
16
16
  protected _pq: PriorityQueue<HeapItem<T>>;
17
17
  /**
18
18
  * The constructor initializes a PriorityQueue with a comparator function that compares the priority of two HeapItem
@@ -4,6 +4,7 @@ export * from './stack';
4
4
  export * from './queue';
5
5
  export * from './graph';
6
6
  export * from './binary-tree';
7
+ export * from './tree';
7
8
  export * from './heap';
8
9
  export * from './priority-queue';
9
10
  export * from './matrix';
@@ -20,6 +20,7 @@ __exportStar(require("./stack"), exports);
20
20
  __exportStar(require("./queue"), exports);
21
21
  __exportStar(require("./graph"), exports);
22
22
  __exportStar(require("./binary-tree"), exports);
23
+ __exportStar(require("./tree"), exports);
23
24
  __exportStar(require("./heap"), exports);
24
25
  __exportStar(require("./priority-queue"), exports);
25
26
  __exportStar(require("./matrix"), exports);
@@ -1,89 +1,216 @@
1
- export declare class DoublyLinkedListNode<T> {
2
- constructor(nodeValue: T);
3
- protected _val: T;
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
+ export declare class DoublyLinkedListNode<T = number> {
9
+ /**
10
+ * The constructor function initializes the value, next, and previous properties of an object.
11
+ * @param {T} val - The "val" parameter is the value that will be stored in the node. It can be of any data type, as it
12
+ * is defined as a generic type "T".
13
+ */
14
+ constructor(val: T);
15
+ private _val;
4
16
  get val(): T;
5
- set val(v: T);
6
- protected _next: DoublyLinkedListNode<T> | null;
17
+ set val(value: T);
18
+ private _next;
7
19
  get next(): DoublyLinkedListNode<T> | null;
8
- set next(v: DoublyLinkedListNode<T> | null);
9
- protected _prev: DoublyLinkedListNode<T> | null;
20
+ set next(value: DoublyLinkedListNode<T> | null);
21
+ private _prev;
10
22
  get prev(): DoublyLinkedListNode<T> | null;
11
- set prev(v: DoublyLinkedListNode<T> | null);
23
+ set prev(value: DoublyLinkedListNode<T> | null);
12
24
  }
13
25
  export declare class DoublyLinkedList<T> {
26
+ /**
27
+ * The constructor initializes the linked list with an empty head, tail, and length.
28
+ */
14
29
  constructor();
15
- protected _first: DoublyLinkedListNode<T> | null;
16
- get first(): DoublyLinkedListNode<T> | null;
17
- protected set first(v: DoublyLinkedListNode<T> | null);
18
- protected _last: DoublyLinkedListNode<T> | null;
19
- get last(): DoublyLinkedListNode<T> | null;
20
- protected set last(v: DoublyLinkedListNode<T> | null);
21
- protected _size: number;
22
- get size(): number;
23
- protected set size(v: number);
30
+ private _head;
31
+ get head(): DoublyLinkedListNode<T> | null;
32
+ set head(value: DoublyLinkedListNode<T> | null);
33
+ private _tail;
34
+ get tail(): DoublyLinkedListNode<T> | null;
35
+ set tail(value: DoublyLinkedListNode<T> | null);
36
+ private _length;
37
+ get length(): number;
38
+ protected set length(value: number);
24
39
  /**
25
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
40
+ * The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
41
+ * given array.
42
+ * @param {T[]} data - The `data` parameter is an array of elements of type `T`.
43
+ * @returns The `fromArray` function returns a DoublyLinkedList object.
26
44
  */
27
- getFirst(): DoublyLinkedListNode<T> | null;
45
+ static fromArray<T>(data: T[]): DoublyLinkedList<T>;
46
+ getLength(): number;
28
47
  /**
29
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
48
+ * The push function adds a new node with the given value to the end of the doubly linked list.
49
+ * @param {T} val - The value to be added to the linked list.
30
50
  */
31
- getLast(): DoublyLinkedListNode<T> | null;
51
+ push(val: T): void;
32
52
  /**
33
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
53
+ * The `pop()` function removes and returns the value of the last node in a doubly linked list.
54
+ * @returns The method is returning the value of the removed node (removedNode.val) if the list is not empty. If the
55
+ * list is empty, it returns null.
34
56
  */
35
- getSize(): number;
57
+ pop(): T | null;
36
58
  /**
37
- * The function adds a new node with a given value to the beginning of a doubly linked list.
38
- * @param {T} val - The `val` parameter represents the value of the element that you want to add to the beginning of
39
- * the doubly linked list.
40
- * @returns A boolean value is being returned.
59
+ * The `shift()` function removes and returns the value of the first node in a doubly linked list.
60
+ * @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
61
+ * list.
41
62
  */
42
- addFirst(val: T): boolean;
63
+ shift(): T | null;
43
64
  /**
44
- * The function adds a new node with a given value to the end of a doubly linked list.
45
- * @param {T} val - The `val` parameter represents the value of the element that you want to add to the end of the
65
+ * The unshift function adds a new node with the given value to the beginning of a doubly linked list.
66
+ * @param {T} val - The `val` parameter represents the value of the new node that will be added to the beginning of the
46
67
  * doubly linked list.
47
- * @returns a boolean value, which is always true.
48
- */
49
- addLast(val: T): boolean;
50
- peekFirst(): T | null;
51
- peekFirst(by: 'val'): T | null;
52
- peekFirst(by: 'node'): DoublyLinkedListNode<T> | null;
53
- peekLast(): T | null;
54
- peekLast(by: 'val'): T | null;
55
- peekLast(by: 'node'): DoublyLinkedListNode<T> | null;
56
- pollFirst(): T | null;
57
- pollFirst(by: 'val'): T | null;
58
- pollFirst(by: 'node'): DoublyLinkedListNode<T> | null;
59
- pollLast(): T | null;
60
- pollLast(by: 'val'): T | null;
61
- pollLast(by: 'node'): DoublyLinkedListNode<T> | null;
62
- get(index: number): T | null;
63
- get(index: number, by: 'node'): DoublyLinkedListNode<T> | null;
64
- get(index: number, by: 'val'): T | null;
65
- /**
66
- * Updates the value of the node at the specified index.
67
- * If index = 0; Value of the first element in the list is updated.
68
- * If index = 3; Value of the fourth element in the list is updated.
69
- * @param index Index of the node to be updated
70
- * @param val New value of the node
71
- */
72
- set(index: number, val: T): boolean;
73
- isEmpty(): boolean;
74
- /**
75
- * Inserts a new node at the specified index.
76
- * @param index Index at which the new node has to be inserted
77
- * @param val Value of the new node to be inserted
78
68
  */
79
- insert(index: number, val: T): boolean;
69
+ unshift(val: T): void;
70
+ /**
71
+ * The `getAt` function returns the value at a specified index in a linked list, or null if the index is out of bounds.
72
+ * @param {number} index - The index parameter is a number that represents the position of the element we want to
73
+ * retrieve from the list.
74
+ * @returns The method is returning the value at the specified index in the linked list. If the index is out of bounds
75
+ * or the linked list is empty, it will return null.
76
+ */
77
+ getAt(index: number): T | null;
78
+ /**
79
+ * The function `getNodeAt` returns the node at a given index in a doubly linked list, or null if the index is out of
80
+ * range.
81
+ * @param {number} index - The `index` parameter is a number that represents the position of the node we want to
82
+ * retrieve from the doubly linked list. It indicates the zero-based index of the node we want to access.
83
+ * @returns The method `getNodeAt(index: number)` returns a `DoublyLinkedListNode<T>` object if the index is within the
84
+ * valid range of the linked list, otherwise it returns `null`.
85
+ */
86
+ getNodeAt(index: number): DoublyLinkedListNode<T> | null;
87
+ /**
88
+ * The function `findNodeByValue` searches for a node with a specific value in a doubly linked list and returns the
89
+ * node if found, otherwise it returns null.
90
+ * @param {T} val - The `val` parameter is the value that we want to search for in the doubly linked list.
91
+ * @returns The function `findNodeByValue` returns a `DoublyLinkedListNode<T>` if a node with the specified value `val`
92
+ * is found in the linked list. If no such node is found, it returns `null`.
93
+ */
94
+ findNode(val: T): DoublyLinkedListNode<T> | null;
80
95
  /**
81
- * The `remove` function removes an element at a specified index from a data structure, updating the links between
82
- * nodes accordingly.
83
- * @param {number} index - The index parameter represents the position of the element to be removed in the data
84
- * structure. It is of type number.
85
- * @returns The `remove` method returns the value of the removed element (`T`) if the removal is successful, or `null`
96
+ * The `insert` function inserts a value at a specified index in a doubly linked list.
97
+ * @param {number} index - The index parameter represents the position at which the new value should be inserted in the
98
+ * DoublyLinkedList. It is of type number.
99
+ * @param {T} val - The `val` parameter represents the value that you want to insert into the Doubly Linked List at the
100
+ * specified index.
101
+ * @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
86
102
  * if the index is out of bounds.
87
103
  */
88
- remove(index: number): T | null;
104
+ insert(index: number, val: T): boolean;
105
+ /**
106
+ * The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
107
+ * @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
108
+ * data structure. It is of type number.
109
+ * @returns The method `deleteAt` returns the value of the node that was deleted, or `null` if the index is out of
110
+ * bounds.
111
+ */
112
+ deleteAt(index: number): T | null;
113
+ /**
114
+ * The `delete` function removes a node with a specific value from a doubly linked list.
115
+ * @param {T} val - The `val` parameter represents the value that you want to delete from the linked list.
116
+ * @returns The `delete` method returns a boolean value. It returns `true` if the value `val` is found and deleted from
117
+ * the linked list, and `false` if the value is not found in the linked list.
118
+ */
119
+ delete(val: T): boolean;
120
+ /**
121
+ * The `toArray` function converts a linked list into an array.
122
+ * @returns The `toArray()` method is returning an array of type `T[]`.
123
+ */
124
+ toArray(): T[];
125
+ /**
126
+ * The `clear` function resets the linked list by setting the head, tail, and length to null and 0 respectively.
127
+ */
128
+ clear(): void;
129
+ /**
130
+ * The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
131
+ * @param callback - A function that takes a value of type T as its parameter and returns a boolean value. This
132
+ * function is used to determine whether a particular value in the linked list satisfies a certain condition.
133
+ * @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
134
+ * the callback function. If no element satisfies the condition, it returns `null`.
135
+ */
136
+ find(callback: (val: T) => boolean): T | null;
137
+ /**
138
+ * The function returns the index of the first occurrence of a given value in a linked list.
139
+ * @param {T} val - The parameter `val` is of type `T`, which means it can be any data type. It represents the value
140
+ * that we are searching for in the linked list.
141
+ * @returns The method `indexOf` returns the index of the first occurrence of the specified value `val` in the linked
142
+ * list. If the value is not found, it returns -1.
143
+ */
144
+ indexOf(val: T): number;
145
+ /**
146
+ * The `findLast` function iterates through a linked list from the last node to the first node and returns the last
147
+ * value that satisfies the given callback function, or null if no value satisfies the callback.
148
+ * @param callback - A function that takes a value of type T as its parameter and returns a boolean value. This
149
+ * function is used to determine whether a given value satisfies a certain condition.
150
+ * @returns The method `findLast` returns the last value in the linked list that satisfies the condition specified by
151
+ * the callback function. If no value satisfies the condition, it returns `null`.
152
+ */
153
+ findLast(callback: (val: T) => boolean): T | null;
154
+ /**
155
+ * The `toArrayReverse` function converts a doubly linked list into an array in reverse order.
156
+ * @returns The `toArrayReverse()` function returns an array of type `T[]`.
157
+ */
158
+ toArrayReverse(): T[];
159
+ /**
160
+ * The `reverse` function reverses the order of the elements in a doubly linked list.
161
+ */
162
+ reverse(): void;
163
+ /**
164
+ * The `forEach` function iterates over each element in a linked list and applies a callback function to each element.
165
+ * @param callback - The callback parameter is a function that takes two arguments: val and index. The val argument
166
+ * represents the value of the current node in the linked list, and the index argument represents the index of the
167
+ * current node in the linked list.
168
+ */
169
+ forEach(callback: (val: T, index: number) => void): void;
170
+ /**
171
+ * The `map` function takes a callback function and applies it to each element in the DoublyLinkedList, returning a new
172
+ * DoublyLinkedList with the transformed values.
173
+ * @param callback - The callback parameter is a function that takes a value of type T (the type of values stored in
174
+ * the original DoublyLinkedList) and returns a value of type U (the type of values that will be stored in the mapped
175
+ * DoublyLinkedList).
176
+ * @returns The `map` function is returning a new instance of `DoublyLinkedList<U>` that contains the mapped values.
177
+ */
178
+ map<U>(callback: (val: T) => U): DoublyLinkedList<U>;
179
+ /**
180
+ * The `filter` function iterates through a DoublyLinkedList and returns a new DoublyLinkedList containing only the
181
+ * elements that satisfy the given callback function.
182
+ * @param callback - The `callback` parameter is a function that takes a value of type `T` and returns a boolean value.
183
+ * It is used to determine whether a value should be included in the filtered list or not.
184
+ * @returns The filtered list, which is an instance of the DoublyLinkedList class.
185
+ */
186
+ filter(callback: (val: T) => boolean): DoublyLinkedList<T>;
187
+ /**
188
+ * The `reduce` function iterates over a linked list and applies a callback function to each element, accumulating a
189
+ * single value.
190
+ * @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `val`. It is
191
+ * used to perform a specific operation on each element of the linked list.
192
+ * @param {U} initialValue - The `initialValue` parameter is the initial value of the accumulator. It is the starting
193
+ * point for the reduction operation.
194
+ * @returns The `reduce` method is returning the final value of the accumulator after iterating through all the
195
+ * elements in the linked list.
196
+ */
197
+ reduce<U>(callback: (accumulator: U, val: T) => U, initialValue: U): U;
198
+ /**
199
+ * The function inserts a new value after an existing value in a doubly linked list.
200
+ * @param {T} existingValue - The existing value is the value of the node after which we want to insert the new value.
201
+ * @param {T} newValue - The `newValue` parameter represents the value of the new node that you want to insert after
202
+ * the existing node.
203
+ * @returns The method is returning a boolean value. It returns true if the insertion is successful and false if the
204
+ * existing value is not found in the linked list.
205
+ */
206
+ insertAfter(existingValue: T, newValue: T): boolean;
207
+ /**
208
+ * The `insertBefore` function inserts a new value before an existing value in a doubly linked list.
209
+ * @param {T} existingValue - The existing value is the value of the node that you want to insert the new value before.
210
+ * @param {T} newValue - The `newValue` parameter represents the value of the new node that you want to insert before
211
+ * the existing node.
212
+ * @returns The method is returning a boolean value. It returns true if the insertion is successful and false if the
213
+ * existing value is not found in the linked list.
214
+ */
215
+ insertBefore(existingValue: T, newValue: T): boolean;
89
216
  }