data-structure-typed 1.15.2 → 1.16.1

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 (208) 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/priority-queue/max-priority-queue.d.ts +4 -5
  9. package/dist/data-structures/priority-queue/max-priority-queue.js +30 -6
  10. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +4 -5
  11. package/dist/data-structures/priority-queue/min-priority-queue.js +31 -6
  12. package/dist/data-structures/priority-queue/priority-queue.d.ts +13 -2
  13. package/dist/data-structures/priority-queue/priority-queue.js +28 -22
  14. package/dist/data-structures/tree/index.d.ts +1 -0
  15. package/dist/data-structures/tree/index.js +17 -0
  16. package/dist/data-structures/tree/tree.d.ts +9 -0
  17. package/dist/data-structures/tree/tree.js +52 -0
  18. package/dist/data-structures/types/heap.d.ts +0 -4
  19. package/dist/utils/types/utils.d.ts +1 -0
  20. package/docs/.nojekyll +1 -0
  21. package/docs/assets/highlight.css +92 -0
  22. package/docs/assets/main.js +58 -0
  23. package/docs/assets/search.js +1 -0
  24. package/docs/assets/style.css +1367 -0
  25. package/docs/classes/AVLTree.html +2192 -0
  26. package/docs/classes/AVLTreeNode.html +574 -0
  27. package/docs/classes/AaTree.html +150 -0
  28. package/docs/classes/AbstractEdge.html +269 -0
  29. package/docs/classes/AbstractGraph.html +927 -0
  30. package/docs/classes/AbstractVertex.html +215 -0
  31. package/docs/classes/ArrayDeque.html +417 -0
  32. package/docs/classes/BST.html +2038 -0
  33. package/docs/classes/BSTNode.html +570 -0
  34. package/docs/classes/BTree.html +150 -0
  35. package/docs/classes/BinaryIndexedTree.html +289 -0
  36. package/docs/classes/BinaryTree.html +1827 -0
  37. package/docs/classes/BinaryTreeNode.html +533 -0
  38. package/docs/classes/Character.html +198 -0
  39. package/docs/classes/CoordinateMap.html +469 -0
  40. package/docs/classes/CoordinateSet.html +430 -0
  41. package/docs/classes/Deque.html +767 -0
  42. package/docs/classes/DirectedEdge.html +354 -0
  43. package/docs/classes/DirectedGraph.html +1243 -0
  44. package/docs/classes/DirectedVertex.html +226 -0
  45. package/docs/classes/DoublyLinkedList.html +733 -0
  46. package/docs/classes/DoublyLinkedListNode.html +258 -0
  47. package/docs/classes/Heap.html +482 -0
  48. package/docs/classes/HeapItem.html +233 -0
  49. package/docs/classes/Matrix2D.html +480 -0
  50. package/docs/classes/MatrixNTI2D.html +218 -0
  51. package/docs/classes/MaxHeap.html +500 -0
  52. package/docs/classes/MaxPriorityQueue.html +809 -0
  53. package/docs/classes/MinHeap.html +501 -0
  54. package/docs/classes/MinPriorityQueue.html +811 -0
  55. package/docs/classes/Navigator.html +291 -0
  56. package/docs/classes/ObjectDeque.html +423 -0
  57. package/docs/classes/PriorityQueue.html +733 -0
  58. package/docs/classes/Queue.html +370 -0
  59. package/docs/classes/RBTree.html +150 -0
  60. package/docs/classes/SegmentTree.html +345 -0
  61. package/docs/classes/SegmentTreeNode.html +418 -0
  62. package/docs/classes/SinglyLinkedList.html +1105 -0
  63. package/docs/classes/SinglyLinkedListNode.html +375 -0
  64. package/docs/classes/SplayTree.html +150 -0
  65. package/docs/classes/Stack.html +346 -0
  66. package/docs/classes/TreeMultiSet.html +2036 -0
  67. package/docs/classes/TreeNode.html +236 -0
  68. package/docs/classes/Trie.html +350 -0
  69. package/docs/classes/TrieNode.html +258 -0
  70. package/docs/classes/TwoThreeTree.html +150 -0
  71. package/docs/classes/UndirectedEdge.html +313 -0
  72. package/docs/classes/UndirectedGraph.html +1080 -0
  73. package/docs/classes/UndirectedVertex.html +226 -0
  74. package/docs/classes/Vector2D.html +783 -0
  75. package/docs/enums/CP.html +159 -0
  76. package/docs/enums/FamilyPosition.html +159 -0
  77. package/docs/enums/LoopType.html +160 -0
  78. package/docs/index.html +494 -0
  79. package/docs/interfaces/AVLTreeDeleted.html +161 -0
  80. package/docs/interfaces/BinaryTreeNodeObj.html +168 -0
  81. package/docs/interfaces/HeapOptions.html +167 -0
  82. package/docs/interfaces/IDirectedGraph.html +243 -0
  83. package/docs/interfaces/IGraph.html +427 -0
  84. package/docs/interfaces/NavigatorParams.html +197 -0
  85. package/docs/interfaces/PriorityQueueOptions.html +168 -0
  86. package/docs/modules.html +218 -0
  87. package/docs/types/BSTComparator.html +140 -0
  88. package/docs/types/BSTDeletedResult.html +137 -0
  89. package/docs/types/BinaryTreeDeleted.html +137 -0
  90. package/docs/types/BinaryTreeNodeId.html +125 -0
  91. package/docs/types/BinaryTreeNodePropertyName.html +125 -0
  92. package/docs/types/DFSOrderPattern.html +125 -0
  93. package/docs/types/DijkstraResult.html +145 -0
  94. package/docs/types/Direction.html +125 -0
  95. package/docs/types/DoublyLinkedListGetBy.html +125 -0
  96. package/docs/types/NodeOrPropertyName.html +125 -0
  97. package/docs/types/PriorityQueueComparator.html +145 -0
  98. package/docs/types/PriorityQueueDFSOrderPattern.html +125 -0
  99. package/docs/types/ResultByProperty.html +130 -0
  100. package/docs/types/ResultsByProperty.html +130 -0
  101. package/docs/types/SegmentTreeNodeVal.html +125 -0
  102. package/docs/types/SpecifyOptional.html +132 -0
  103. package/docs/types/Thunk.html +133 -0
  104. package/docs/types/ToThunkFn.html +133 -0
  105. package/docs/types/TopologicalStatus.html +125 -0
  106. package/docs/types/TreeMultiSetDeletedResult.html +137 -0
  107. package/docs/types/TrlAsyncFn.html +138 -0
  108. package/docs/types/TrlFn.html +138 -0
  109. package/docs/types/Turning.html +125 -0
  110. package/docs/types/VertexId.html +125 -0
  111. package/{tests/unit/data-structures/binary-tree → notes}/bst.test.ts +37 -50
  112. package/notes/note.md +23 -0
  113. package/package.json +1 -1
  114. package/.idea/data-structure-typed.iml +0 -14
  115. package/.idea/modules.xml +0 -8
  116. package/.idea/vcs.xml +0 -6
  117. package/src/assets/complexities-diff.jpg +0 -0
  118. package/src/assets/data-structure-complexities.jpg +0 -0
  119. package/src/assets/logo.png +0 -0
  120. package/src/assets/overview-diagram-of-data-structures.png +0 -0
  121. package/src/data-structures/binary-tree/aa-tree.ts +0 -3
  122. package/src/data-structures/binary-tree/avl-tree.ts +0 -293
  123. package/src/data-structures/binary-tree/b-tree.ts +0 -3
  124. package/src/data-structures/binary-tree/binary-indexed-tree.ts +0 -69
  125. package/src/data-structures/binary-tree/binary-tree.ts +0 -1492
  126. package/src/data-structures/binary-tree/bst.ts +0 -497
  127. package/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
  128. package/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
  129. package/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
  130. package/src/data-structures/binary-tree/index.ts +0 -11
  131. package/src/data-structures/binary-tree/rb-tree.ts +0 -3
  132. package/src/data-structures/binary-tree/segment-tree.ts +0 -267
  133. package/src/data-structures/binary-tree/splay-tree.ts +0 -3
  134. package/src/data-structures/binary-tree/tree-multiset.ts +0 -53
  135. package/src/data-structures/binary-tree/two-three-tree.ts +0 -3
  136. package/src/data-structures/diagrams/README.md +0 -5
  137. package/src/data-structures/graph/abstract-graph.ts +0 -958
  138. package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
  139. package/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
  140. package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
  141. package/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
  142. package/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
  143. package/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
  144. package/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
  145. package/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
  146. package/src/data-structures/graph/diagrams/mst.jpg +0 -0
  147. package/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
  148. package/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
  149. package/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
  150. package/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
  151. package/src/data-structures/graph/diagrams/tarjan.webp +0 -0
  152. package/src/data-structures/graph/directed-graph.ts +0 -429
  153. package/src/data-structures/graph/index.ts +0 -3
  154. package/src/data-structures/graph/undirected-graph.ts +0 -259
  155. package/src/data-structures/hash/coordinate-map.ts +0 -74
  156. package/src/data-structures/hash/coordinate-set.ts +0 -63
  157. package/src/data-structures/hash/hash-table.ts +0 -1
  158. package/src/data-structures/hash/index.ts +0 -6
  159. package/src/data-structures/hash/pair.ts +0 -1
  160. package/src/data-structures/hash/tree-map.ts +0 -1
  161. package/src/data-structures/hash/tree-set.ts +0 -1
  162. package/src/data-structures/heap/heap.ts +0 -162
  163. package/src/data-structures/heap/index.ts +0 -3
  164. package/src/data-structures/heap/max-heap.ts +0 -31
  165. package/src/data-structures/heap/min-heap.ts +0 -34
  166. package/src/data-structures/index.ts +0 -13
  167. package/src/data-structures/linked-list/doubly-linked-list.ts +0 -365
  168. package/src/data-structures/linked-list/index.ts +0 -2
  169. package/src/data-structures/linked-list/singly-linked-list.ts +0 -757
  170. package/src/data-structures/linked-list/skip-linked-list.ts +0 -1
  171. package/src/data-structures/matrix/index.ts +0 -4
  172. package/src/data-structures/matrix/matrix.ts +0 -27
  173. package/src/data-structures/matrix/matrix2d.ts +0 -208
  174. package/src/data-structures/matrix/navigator.ts +0 -122
  175. package/src/data-structures/matrix/vector2d.ts +0 -316
  176. package/src/data-structures/priority-queue/index.ts +0 -3
  177. package/src/data-structures/priority-queue/max-priority-queue.ts +0 -24
  178. package/src/data-structures/priority-queue/min-priority-queue.ts +0 -24
  179. package/src/data-structures/priority-queue/priority-queue.ts +0 -349
  180. package/src/data-structures/queue/deque.ts +0 -251
  181. package/src/data-structures/queue/index.ts +0 -2
  182. package/src/data-structures/queue/queue.ts +0 -120
  183. package/src/data-structures/stack/index.ts +0 -1
  184. package/src/data-structures/stack/stack.ts +0 -98
  185. package/src/data-structures/trie/index.ts +0 -1
  186. package/src/data-structures/trie/trie.ts +0 -225
  187. package/src/data-structures/types/abstract-graph.ts +0 -51
  188. package/src/data-structures/types/avl-tree.ts +0 -6
  189. package/src/data-structures/types/binary-tree.ts +0 -15
  190. package/src/data-structures/types/bst.ts +0 -5
  191. package/src/data-structures/types/directed-graph.ts +0 -18
  192. package/src/data-structures/types/doubly-linked-list.ts +0 -1
  193. package/src/data-structures/types/heap.ts +0 -8
  194. package/src/data-structures/types/index.ts +0 -13
  195. package/src/data-structures/types/navigator.ts +0 -13
  196. package/src/data-structures/types/priority-queue.ts +0 -9
  197. package/src/data-structures/types/segment-tree.ts +0 -1
  198. package/src/data-structures/types/singly-linked-list.ts +0 -1
  199. package/src/data-structures/types/tree-multiset.ts +0 -3
  200. package/src/index.ts +0 -1
  201. package/src/utils/index.ts +0 -2
  202. package/src/utils/types/index.ts +0 -1
  203. package/src/utils/types/utils.ts +0 -4
  204. package/src/utils/utils.ts +0 -78
  205. package/tests/unit/data-structures/graph/abstract-graph.ts +0 -0
  206. package/tests/unit/data-structures/graph/directed-graph.test.ts +0 -492
  207. package/tests/unit/data-structures/graph/index.ts +0 -3
  208. package/tests/unit/data-structures/graph/undirected-graph.ts +0 -0
@@ -1,259 +0,0 @@
1
- /**
2
- * data-structure-typed
3
- *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
- * @license MIT License
7
- */
8
- import {arrayRemove} from '../../utils';
9
- import {AbstractEdge, AbstractGraph, AbstractVertex} from './abstract-graph';
10
- import type {VertexId} from '../types';
11
-
12
- export class UndirectedVertex extends AbstractVertex {
13
- /**
14
- * The constructor function initializes an object with a given id.
15
- * @param {VertexId} id - The `id` parameter is the identifier for the vertex. It is used to uniquely identify the
16
- * vertex within a graph or network.
17
- */
18
- constructor(id: VertexId) {
19
- super(id);
20
- }
21
- }
22
-
23
- export class UndirectedEdge extends AbstractEdge {
24
- /**
25
- * The constructor function initializes an instance of a class with two vertex IDs and an optional weight.
26
- * @param {VertexId} v1 - The parameter `v1` is of type `VertexId` and represents the first vertex in the edge.
27
- * @param {VertexId} v2 - The parameter `v2` is a `VertexId`, which represents the identifier of the second vertex in a
28
- * graph.
29
- * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge
30
- * between two vertices.
31
- */
32
- constructor(v1: VertexId, v2: VertexId, weight?: number) {
33
- super(weight);
34
- this._vertices = [v1, v2];
35
- }
36
-
37
- private _vertices: [VertexId, VertexId];
38
- get vertices() {
39
- return this._vertices;
40
- }
41
-
42
- set vertices(v: [VertexId, VertexId]) {
43
- this._vertices = v;
44
- }
45
-
46
- /**
47
- * 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
- */
49
- getVertices() {
50
- return this._vertices;
51
- }
52
- }
53
-
54
- export class UndirectedGraph<V extends UndirectedVertex, E extends UndirectedEdge> extends AbstractGraph<V, E> {
55
- constructor() {
56
- super();
57
- this._edges = new Map<V, E[]>();
58
- }
59
-
60
- protected _edges: Map<V, E[]>;
61
-
62
- get edges(): Map<V, E[]> {
63
- return this._edges;
64
- }
65
-
66
- protected set edges(v: Map<V, E[]>) {
67
- this._edges = v;
68
- }
69
-
70
- /**
71
- * 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.
72
- */
73
- getEdges(): Map<V, E[]> {
74
- return this._edges;
75
- }
76
-
77
- /**
78
- * The function `getEdge` returns the first edge that connects two vertices, or null if no such edge exists.
79
- * @param {V | null | VertexId} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID
80
- * (`VertexId`). It can also be `null`.
81
- * @param {V | null | VertexId} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `V` (vertex
82
- * object), `null`, or `VertexId` (vertex ID).
83
- * @returns an edge (E) or null.
84
- */
85
- getEdge(v1: V | null | VertexId, v2: V | null | VertexId): E | null {
86
- let edges: E[] | undefined = [];
87
-
88
- if (v1 !== null && v2 !== null) {
89
- const vertex1: V | null = this.getVertex(v1);
90
- const vertex2: V | null = this.getVertex(v2);
91
-
92
- if (vertex1 && vertex2) {
93
- edges = this._edges.get(vertex1)?.filter(e => e.vertices.includes(vertex2.id));
94
- }
95
- }
96
-
97
- return edges ? edges[0] || null : null;
98
- }
99
-
100
- /**
101
- * The function adds an edge to a graph by connecting two vertices.
102
- * @param {E} edge - The `edge` parameter is an object of type `E`, which represents an edge in a graph.
103
- * @returns a boolean value.
104
- */
105
- addEdge(edge: E): boolean {
106
- for (const end of edge.vertices) {
107
- const endVertex = this.getVertex(end);
108
- if (endVertex === null) return false;
109
- if (endVertex) {
110
- const edges = this._edges.get(endVertex);
111
- if (edges) {
112
- edges.push(edge);
113
- } else {
114
- this._edges.set(endVertex, [edge]);
115
- }
116
- }
117
- }
118
- return true;
119
- }
120
-
121
- /**
122
- * The function removes an edge between two vertices in a graph and returns the removed edge, or null if either of the
123
- * vertices does not exist.
124
- * @param {V | VertexId} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexId`).
125
- * @param {V | VertexId} v2 - V | VertexId: The second vertex or vertex ID of the edge to be removed.
126
- * @returns the removed edge (E) if it exists, or null if either of the vertices (v1 or v2) does not exist.
127
- */
128
- removeEdgeBetween(v1: V | VertexId, v2: V | VertexId): E | null {
129
-
130
- const vertex1: V | null = this.getVertex(v1);
131
- const vertex2: V | null = this.getVertex(v2);
132
-
133
- if (!vertex1 || !vertex2) {
134
- return null;
135
- }
136
-
137
- const v1Edges = this._edges.get(vertex1);
138
- let removed: E | null = null;
139
- if (v1Edges) {
140
- removed = arrayRemove<E>(v1Edges, (e: UndirectedEdge) => e.vertices.includes(vertex2.id))[0] || null;
141
- }
142
- const v2Edges = this._edges.get(vertex2);
143
- if (v2Edges) {
144
- arrayRemove<E>(v2Edges, (e: UndirectedEdge) => e.vertices.includes(vertex1.id));
145
- }
146
- return removed;
147
- }
148
-
149
- /**
150
- * The removeEdge function removes an edge between two vertices in a graph.
151
- * @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
152
- * @returns The method is returning either the removed edge (of type E) or null if the edge was not found.
153
- */
154
- removeEdge(edge: E): E | null {
155
- return this.removeEdgeBetween(edge.vertices[0], edge.vertices[1]);
156
- }
157
-
158
- /**
159
- * The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edges connected to that
160
- * vertex.
161
- * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
162
- * @returns The function `degreeOf` returns the degree of a vertex in a graph. The degree of a vertex is the number of
163
- * edges that are incident to that vertex.
164
- */
165
- degreeOf(vertexOrId: VertexId | V): number {
166
- const vertex = this.getVertex(vertexOrId);
167
- if (vertex) {
168
- return this._edges.get(vertex)?.length || 0;
169
- } else {
170
- return 0;
171
- }
172
- }
173
-
174
- /**
175
- * The function "edgesOf" returns an array of edges connected to a given vertex.
176
- * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
177
- * @returns an array of edges connected to the specified vertex. If the vertex exists in the graph, the function
178
- * returns the array of edges connected to that vertex. If the vertex does not exist in the graph, the function returns
179
- * an empty array.
180
- */
181
- edgesOf(vertexOrId: VertexId | V): E[] {
182
- const vertex = this.getVertex(vertexOrId);
183
- if (vertex) {
184
- return this._edges.get(vertex) || [];
185
- } else {
186
- return [];
187
- }
188
- }
189
-
190
- /**
191
- * The function "edgeSet" returns an array of unique edges from a set of edges.
192
- * @returns The method `edgeSet()` returns an array of type `E[]`.
193
- */
194
- edgeSet(): E[] {
195
- const edgeSet: Set<E> = new Set();
196
- this._edges.forEach(edges => {
197
- edges.forEach(edge => {
198
- edgeSet.add(edge);
199
- });
200
- });
201
- return [...edgeSet];
202
- }
203
-
204
- /**
205
- * The function "getEdgesOf" returns an array of edges connected to a given vertex or vertex ID.
206
- * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can accept either a vertex object (`V`) or a vertex ID
207
- * (`VertexId`).
208
- * @returns an array of edges (E[]) that are connected to the specified vertex or vertex ID.
209
- */
210
- getEdgesOf(vertexOrId: V | VertexId): E[] {
211
- const vertex = this.getVertex(vertexOrId);
212
- if (!vertex) {
213
- return [];
214
- }
215
- return this._edges.get(vertex) || [];
216
- }
217
-
218
- /**
219
- * The function "getNeighbors" returns an array of neighboring vertices of a given vertex.
220
- * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
221
- * (`VertexId`).
222
- * @returns an array of vertices (V[]).
223
- */
224
- getNeighbors(vertexOrId: V | VertexId): V[] {
225
- const neighbors: V[] = [];
226
- const vertex = this.getVertex(vertexOrId);
227
- if (vertex) {
228
- const neighborEdges = this.getEdgesOf(vertex);
229
- for (const edge of neighborEdges) {
230
- const neighbor = this.getVertex(edge.vertices.filter(e => e !== vertex.id)[0]);
231
- if (neighbor) {
232
- neighbors.push(neighbor);
233
- }
234
- }
235
- }
236
- return neighbors;
237
- }
238
-
239
- /**
240
- * The function "getEndsOfEdge" returns the vertices at the ends of a given edge, or null if the edge does not exist in
241
- * the graph.
242
- * @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
243
- * @returns The function `getEndsOfEdge` returns an array containing two vertices `[V, V]` if the edge exists in the
244
- * graph and both vertices are found. If the edge does not exist or one or both vertices are not found, it returns
245
- * `null`.
246
- */
247
- getEndsOfEdge(edge: E): [V, V] | null {
248
- if (!this.hasEdge(edge.vertices[0], edge.vertices[1])) {
249
- return null;
250
- }
251
- const v1 = this.getVertex(edge.vertices[0]);
252
- const v2 = this.getVertex(edge.vertices[1]);
253
- if (v1 && v2) {
254
- return [v1, v2];
255
- } else {
256
- return null;
257
- }
258
- }
259
- }
@@ -1,74 +0,0 @@
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 class CoordinateMap<V> extends Map<any, V> {
9
- constructor(joint?: string) {
10
- super();
11
- if (joint !== undefined) this._joint = joint;
12
- }
13
-
14
- protected _joint: string = '_';
15
-
16
- get joint(): string {
17
- return this._joint;
18
- }
19
-
20
- protected set joint(v: string) {
21
- this._joint = v;
22
- }
23
-
24
- /**
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.
26
- */
27
- getJoint(): string {
28
- return this._joint;
29
- }
30
-
31
- /**
32
- * The "has" function overrides the base class's "has" function and checks if a key exists in the map by joining the
33
- * key array with a specified delimiter.
34
- * @param {number[]} key - The parameter "key" is an array of numbers.
35
- * @returns The `has` method is being overridden to return the result of calling the `has` method of the superclass
36
- * (`super.has`) with the `key` array joined together using the `_joint` property.
37
- */
38
- override has(key: number[]) {
39
- return super.has(key.join(this._joint));
40
- }
41
-
42
- /**
43
- * The function overrides the set method of a Map object to convert the key from an array to a string using a specified
44
- * delimiter before calling the original set method.
45
- * @param {number[]} key - The key parameter is an array of numbers.
46
- * @param {V} value - The value parameter is the value that you want to associate with the specified key.
47
- * @returns The `set` method is returning the result of calling the `set` method of the superclass
48
- * (`super.set(key.join(this._joint), value)`).
49
- */
50
- override set(key: number[], value: V) {
51
- return super.set(key.join(this._joint), value);
52
- }
53
-
54
- /**
55
- * The function overrides the get method to join the key array with a specified joint and then calls the super get
56
- * method.
57
- * @param {number[]} key - An array of numbers
58
- * @returns The code is returning the value associated with the specified key in the map.
59
- */
60
- override get(key: number[]) {
61
- return super.get(key.join(this._joint));
62
- }
63
-
64
- /**
65
- * The function overrides the delete method and joins the key array using a specified joint character before calling
66
- * the super delete method.
67
- * @param {number[]} key - An array of numbers that represents the key to be deleted.
68
- * @returns The `delete` method is returning the result of calling the `delete` method on the superclass, with the
69
- * `key` array joined together using the `_joint` property.
70
- */
71
- override delete(key: number[]) {
72
- return super.delete(key.join(this._joint));
73
- }
74
- }
@@ -1,63 +0,0 @@
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 class CoordinateSet extends Set {
9
- constructor(joint?: string) {
10
- super();
11
- if (joint !== undefined) this._joint = joint;
12
- }
13
-
14
- protected _joint: string = '_';
15
-
16
- get joint(): string {
17
- return this._joint;
18
- }
19
-
20
- protected set joint(v: string) {
21
- this._joint = v;
22
- }
23
-
24
- /**
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.
26
- */
27
- getJoint(): string {
28
- return this._joint;
29
- }
30
-
31
- /**
32
- * The "has" function overrides the "has" method of the superclass and checks if a value exists in an array after
33
- * joining its elements with a specified separator.
34
- * @param {number[]} value - The parameter "value" is an array of numbers.
35
- * @returns The overridden `has` method is returning the result of calling the `has` method of the superclass, passing
36
- * in the joined value as an argument.
37
- */
38
- override has(value: number[]) {
39
- return super.has(value.join(this._joint));
40
- }
41
-
42
- /**
43
- * The "add" function overrides the parent class's "add" function by joining the elements of the input array with a
44
- * specified delimiter before calling the parent class's "add" function.
45
- * @param {number[]} value - An array of numbers
46
- * @returns The overridden `add` method is returning the result of calling the `add` method of the superclass
47
- * (`super.add`) with the joined string representation of the `value` array (`value.join(this._joint)`).
48
- */
49
- override add(value: number[]) {
50
- return super.add(value.join(this._joint));
51
- }
52
-
53
- /**
54
- * The function overrides the delete method and deletes an element from a Set by joining the elements of the input
55
- * array with a specified joint and then calling the delete method of the parent class.
56
- * @param {number[]} value - An array of numbers
57
- * @returns The `delete` method is returning the result of calling the `delete` method of the superclass, with the
58
- * `value` array joined together using the `_joint` property.
59
- */
60
- override delete(value: number[]) {
61
- return super.delete(value.join(this._joint));
62
- }
63
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,6 +0,0 @@
1
- export * from './hash-table';
2
- export * from './coordinate-map';
3
- export * from './coordinate-set';
4
- export * from './pair';
5
- export * from './tree-map';
6
- export * from './tree-set';
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,162 +0,0 @@
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 {PriorityQueue} from '../priority-queue';
9
- import type {HeapItem, HeapOptions} from '../types';
10
-
11
- export abstract class Heap<T> {
12
- /**
13
- * The function is a constructor for a class that initializes a priority callback function based on the
14
- * options provided.
15
- * @param [options] - An optional object that contains configuration options for the Heap.
16
- */
17
- protected constructor(options?: HeapOptions<T>) {
18
- if (options) {
19
- const {priority} = options;
20
- if (priority !== undefined && typeof priority !== 'function') {
21
- throw new Error('.constructor expects a valid priority function');
22
- }
23
- this._priorityCb = priority || ((el) => +el);
24
- } else {
25
- this._priorityCb = (el) => +el;
26
- }
27
- }
28
-
29
- protected abstract _pq: PriorityQueue<HeapItem<T>>;
30
-
31
- get pq() {
32
- return this._pq;
33
- }
34
-
35
- protected set pq(v: PriorityQueue<HeapItem<T>>) {
36
- this._pq = v;
37
- }
38
-
39
- protected _priorityCb: (element: T) => number;
40
- get priorityCb() {
41
- return this._priorityCb;
42
- }
43
-
44
- protected set priorityCb(v: (element: T) => number) {
45
- this._priorityCb = v;
46
- }
47
-
48
- /**
49
- * The function returns the size of a priority queue.
50
- * @returns The size of the priority queue.
51
- */
52
- get size(): number {
53
- return this._pq.size;
54
- }
55
-
56
- /**
57
- * 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.
58
- */
59
- getPq() {
60
- return this._pq;
61
- }
62
-
63
- /**
64
- * 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.
65
- */
66
- getPriorityCb() {
67
- return this._priorityCb;
68
- }
69
-
70
- /**
71
- * 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.
72
- */
73
- getSize(): number {
74
- return this._pq.size;
75
- }
76
-
77
- /**
78
- * The function checks if a priority queue is empty.
79
- * @returns {boolean} A boolean value indicating whether the size of the priority queue is less than 1.
80
- */
81
- isEmpty(): boolean {
82
- return this._pq.size < 1;
83
- }
84
-
85
- /**
86
- * The `peek` function returns the top item in the priority queue without removing it.
87
- * @returns The `peek()` method is returning either a `HeapItem<T>` object or `null`.Returns an element with the highest priority in the queue
88
- */
89
- peek(): HeapItem<T> | null {
90
- return this._pq.peek();
91
- }
92
-
93
- /**
94
- * The `peekLast` function returns the last item in the heap.
95
- * @returns The method `peekLast()` returns either a `HeapItem<T>` object or `null`.Returns an element with the lowest priority in the queue
96
- */
97
- peekLast(): HeapItem<T> | null {
98
- return this._pq.leaf();
99
- }
100
-
101
- /**
102
- * The `add` function adds an element to a priority queue with an optional priority value.
103
- * @param {T} element - The `element` parameter represents the value that you want to add to the heap. It can be of any
104
- * type.
105
- * @param {number} [priority] - The `priority` parameter is an optional number that represents the priority of the
106
- * element being added to the heap. If the `element` parameter is a number, then the `priority` parameter is set to
107
- * the value of `element`. If the `element` parameter is not a number, then the
108
- * @returns The `add` method returns the instance of the `Heap` class.
109
- * @throws {Error} if priority is not a valid number
110
- */
111
- add(element: T, priority?: number): Heap<T> {
112
- if (typeof element === 'number') {
113
- priority = element;
114
- } else {
115
- if (priority === undefined) {
116
- throw new Error('.add expects a numeric priority');
117
- }
118
- }
119
-
120
- if (priority && Number.isNaN(+priority)) {
121
- throw new Error('.add expects a numeric priority');
122
- }
123
-
124
- if (Number.isNaN(+priority) && Number.isNaN(this._priorityCb(element))) {
125
- throw new Error(
126
- '.add expects a numeric priority '
127
- + 'or a constructor callback that returns a number'
128
- );
129
- }
130
-
131
- const _priority = !Number.isNaN(+priority) ? priority : this._priorityCb(element);
132
- this._pq.add({priority: _priority, element});
133
- return this;
134
- }
135
-
136
- /**
137
- * 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
138
- * @returns either a HeapItem<T> object or null.
139
- */
140
- poll(): HeapItem<T> | null {
141
- const top = this._pq.poll();
142
- if (!top) {
143
- return null;
144
- }
145
- return top;
146
- }
147
-
148
- /**
149
- * The `toArray` function returns an array of `HeapItem<T>` objects.
150
- * @returns An array of HeapItem<T> objects.Returns a sorted list of elements
151
- */
152
- toArray(): HeapItem<T>[] {
153
- return this._pq.toArray();
154
- }
155
-
156
- /**
157
- * The clear function clears the priority queue.
158
- */
159
- clear(): void {
160
- this._pq.clear();
161
- }
162
- }
@@ -1,3 +0,0 @@
1
- export * from './max-heap';
2
- export * from './min-heap';
3
- export * from './heap';
@@ -1,31 +0,0 @@
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
-
9
- import {Heap} from './heap';
10
- import {PriorityQueue} from '../priority-queue';
11
- import type {HeapItem, HeapOptions} from '../types';
12
-
13
- /**
14
- * @class MaxHeap
15
- * @extends Heap
16
- */
17
- export class MaxHeap<T> extends Heap<T> {
18
- protected _pq: PriorityQueue<HeapItem<T>>;
19
-
20
- /**
21
- * The constructor initializes a PriorityQueue with a custom comparator function.
22
- * @param [options] - The `options` parameter is an optional object that can be passed to the constructor. It is of
23
- * type `HeapOptions<T>`, which is a generic type that represents the options for the heap.
24
- */
25
- constructor(options?: HeapOptions<T>) {
26
- super(options);
27
- this._pq = new PriorityQueue<HeapItem<T>>({
28
- comparator: (a, b) => b.priority - a.priority
29
- });
30
- }
31
- }
@@ -1,34 +0,0 @@
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
-
9
- import {Heap} from './heap';
10
- import {PriorityQueue} from '../priority-queue';
11
- import type {HeapItem, HeapOptions} from '../types';
12
-
13
- /**
14
- * @class MinHeap
15
- * @extends Heap
16
- */
17
- export class MinHeap<T> extends Heap<T> {
18
- protected _pq: PriorityQueue<HeapItem<T>>;
19
-
20
- /**
21
- * The constructor initializes a PriorityQueue with a comparator function that compares the priority of two HeapItem
22
- * objects.
23
- * @param [options] - The `options` parameter is an optional object that can be passed to the constructor. It is of
24
- * type `HeapOptions<T>`, which is a generic type that represents the options for the heap.
25
- */
26
- constructor(options?: HeapOptions<T>) {
27
- super(options);
28
- this._pq = new PriorityQueue<HeapItem<T>>({
29
- comparator: (a, b) => a.priority - b.priority
30
- });
31
- }
32
- }
33
-
34
-
@@ -1,13 +0,0 @@
1
- export * from './hash';
2
- export * from './linked-list';
3
- export * from './stack';
4
- export * from './queue';
5
- export * from './graph';
6
- export * from './binary-tree';
7
- export * from './heap';
8
- export * from './priority-queue';
9
- export * from './matrix';
10
- export * from './trie';
11
- export * from './types';
12
-
13
-