data-structure-typed 1.18.8 → 1.19.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 (40) hide show
  1. package/README.md +169 -168
  2. package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +182 -148
  3. package/dist/data-structures/binary-tree/abstract-binary-tree.js +288 -316
  4. package/dist/data-structures/binary-tree/avl-tree.d.ts +22 -14
  5. package/dist/data-structures/binary-tree/avl-tree.js +23 -17
  6. package/dist/data-structures/binary-tree/binary-tree.d.ts +12 -26
  7. package/dist/data-structures/binary-tree/binary-tree.js +11 -26
  8. package/dist/data-structures/binary-tree/bst.d.ts +62 -74
  9. package/dist/data-structures/binary-tree/bst.js +72 -96
  10. package/dist/data-structures/binary-tree/rb-tree.d.ts +3 -14
  11. package/dist/data-structures/binary-tree/rb-tree.js +5 -17
  12. package/dist/data-structures/binary-tree/tree-multiset.d.ts +186 -17
  13. package/dist/data-structures/binary-tree/tree-multiset.js +712 -28
  14. package/dist/data-structures/graph/abstract-graph.d.ts +107 -49
  15. package/dist/data-structures/graph/abstract-graph.js +104 -55
  16. package/dist/data-structures/graph/directed-graph.d.ts +95 -94
  17. package/dist/data-structures/graph/directed-graph.js +95 -95
  18. package/dist/data-structures/graph/undirected-graph.d.ts +62 -61
  19. package/dist/data-structures/graph/undirected-graph.js +62 -61
  20. package/dist/data-structures/interfaces/abstract-binary-tree.d.ts +10 -15
  21. package/dist/data-structures/interfaces/avl-tree.d.ts +2 -2
  22. package/dist/data-structures/interfaces/binary-tree.d.ts +1 -1
  23. package/dist/data-structures/interfaces/bst.d.ts +3 -4
  24. package/dist/data-structures/interfaces/rb-tree.d.ts +1 -2
  25. package/dist/data-structures/interfaces/tree-multiset.d.ts +3 -3
  26. package/dist/data-structures/types/abstract-binary-tree.d.ts +1 -1
  27. package/dist/data-structures/types/tree-multiset.d.ts +3 -3
  28. package/dist/utils/index.d.ts +1 -0
  29. package/dist/utils/index.js +1 -0
  30. package/dist/utils/types/index.d.ts +1 -0
  31. package/dist/utils/types/index.js +1 -0
  32. package/dist/utils/types/utils.d.ts +0 -18
  33. package/dist/utils/types/validate-type.d.ts +19 -0
  34. package/dist/utils/types/validate-type.js +2 -0
  35. package/dist/utils/utils.d.ts +3 -8
  36. package/dist/utils/utils.js +1 -83
  37. package/dist/utils/validate-type.d.ts +45 -0
  38. package/dist/utils/validate-type.js +58 -0
  39. package/package.json +6 -2
  40. package/tsconfig.json +0 -17
package/README.md CHANGED
@@ -3,9 +3,169 @@
3
3
  ## Brief
4
4
  Javascript & TypeScript Data Structure Library.
5
5
 
6
- Meticulously crafted to empower developers with a versatile set of essential data structures. Our library includes a
7
- wide range of data structures
6
+ Binary Tree, Binary Search Tree (BST), AVL Tree, Tree Multiset, Segment Tree, Binary Indexed Tree, Graph, Directed Graph, Undirected Graph, Linked List, Singly Linked List, Doubly Linked List, Queue, Object Deque, Array Deque, Stack, Hash, Coordinate Set, Coordinate Map, Heap, Priority Queue, Max Priority Queue, Min Priority Queue, Trie
8
7
 
8
+ ## Algorithms list only a few out, you can discover more in API docs
9
+
10
+ DFS, DFSIterative, BFS, morris, Bellman-Ford Algorithm, Dijkstra's Algorithm, Floyd-Warshall Algorithm, Tarjan's Algorithm
11
+
12
+ ## Code design
13
+ By strictly adhering to object-oriented design (BinaryTree -> BST -> AVLTree -> TreeMultiset), you can seamlessly inherit the existing data structures to implement the customized ones you need. Object-oriented design stands as the optimal approach to data structure design.
14
+
15
+ # How
16
+
17
+ ## install
18
+ ### yarn
19
+
20
+ ```bash
21
+ yarn add data-structure-typed
22
+ ```
23
+
24
+ ### npm
25
+
26
+ ```bash
27
+ npm install data-structure-typed
28
+ ```
29
+
30
+ ### Binary Search Tree (BST) snippet
31
+
32
+ #### TS
33
+ ```typescript
34
+ import {BST, BSTNode} from 'data-structure-typed';
35
+
36
+ const bst = new BST();
37
+ bst.add(11);
38
+ bst.add(3);
39
+ bst.addMany([15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5]);
40
+ bst.size === 16; // true
41
+ bst.has(6); // true
42
+ const node6 = bst.get(6);
43
+ bst.getHeight(6) === 2; // true
44
+ bst.getHeight() === 5; // true
45
+ bst.getDepth(6) === 3; // true
46
+ const leftMost = bst.getLeftMost();
47
+ leftMost?.id === 1; // true
48
+ expect(leftMost?.id).toBe(1);
49
+ bst.remove(6);
50
+ bst.get(6); // null
51
+ bst.isAVLBalanced(); // true or false
52
+ const bfsIDs = bst.BFS();
53
+ bfsIDs[0] === 11; // true
54
+ expect(bfsIDs[0]).toBe(11);
55
+
56
+ const objBST = new BST<BSTNode<{ id: number, keyA: number }>>();
57
+ objBST.add(11, {id: 11, keyA: 11});
58
+ objBST.add(3, {id: 3, keyA: 3});
59
+
60
+ objBST.addMany([{id: 15, keyA: 15}, {id: 1, keyA: 1}, {id: 8, keyA: 8},
61
+ {id: 13, keyA: 13}, {id: 16, keyA: 16}, {id: 2, keyA: 2},
62
+ {id: 6, keyA: 6}, {id: 9, keyA: 9}, {id: 12, keyA: 12},
63
+ {id: 14, keyA: 14}, {id: 4, keyA: 4}, {id: 7, keyA: 7},
64
+ {id: 10, keyA: 10}, {id: 5, keyA: 5}]);
65
+
66
+ objBST.remove(11);
67
+
68
+
69
+ const avlTree = new AVLTree();
70
+ avlTree.addMany([11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5])
71
+ avlTree.isAVLBalanced(); // true
72
+ avlTree.remove(10);
73
+ avlTree.isAVLBalanced(); // true
74
+
75
+ ```
76
+ #### JS
77
+ ```javascript
78
+ const {BST, BSTNode} = require('data-structure-typed');
79
+
80
+ const bst = new BST();
81
+ bst.add(11);
82
+ bst.add(3);
83
+ bst.addMany([15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5]);
84
+ bst.size === 16; // true
85
+ bst.has(6); // true
86
+ const node6 = bst.get(6);
87
+ bst.getHeight(6) === 2; // true
88
+ bst.getHeight() === 5; // true
89
+ bst.getDepth(6) === 3; // true
90
+ const leftMost = bst.getLeftMost();
91
+ leftMost?.id === 1; // true
92
+ expect(leftMost?.id).toBe(1);
93
+ bst.remove(6);
94
+ bst.get(6); // null
95
+ bst.isAVLBalanced(); // true or false
96
+ const bfsIDs = bst.BFS();
97
+ bfsIDs[0] === 11; // true
98
+ expect(bfsIDs[0]).toBe(11);
99
+
100
+ const objBST = new BST();
101
+ objBST.add(11, {id: 11, keyA: 11});
102
+ objBST.add(3, {id: 3, keyA: 3});
103
+
104
+ objBST.addMany([{id: 15, keyA: 15}, {id: 1, keyA: 1}, {id: 8, keyA: 8},
105
+ {id: 13, keyA: 13}, {id: 16, keyA: 16}, {id: 2, keyA: 2},
106
+ {id: 6, keyA: 6}, {id: 9, keyA: 9}, {id: 12, keyA: 12},
107
+ {id: 14, keyA: 14}, {id: 4, keyA: 4}, {id: 7, keyA: 7},
108
+ {id: 10, keyA: 10}, {id: 5, keyA: 5}]);
109
+
110
+ objBST.remove(11);
111
+
112
+
113
+ const avlTree = new AVLTree();
114
+ avlTree.addMany([11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5])
115
+ avlTree.isAVLBalanced(); // true
116
+ avlTree.remove(10);
117
+ avlTree.isAVLBalanced(); // true
118
+
119
+ ```
120
+
121
+ ### Directed Graph simple snippet
122
+
123
+ #### TS or JS
124
+ ```typescript
125
+ import {DirectedGraph} from 'data-structure-typed';
126
+
127
+ const graph = new DirectedGraph();
128
+
129
+ graph.addVertex('A');
130
+ graph.addVertex('B');
131
+
132
+ graph.hasVertex('A'); // true
133
+ graph.hasVertex('B'); // true
134
+ graph.hasVertex('C'); // false
135
+
136
+ graph.addEdge('A', 'B');
137
+ graph.hasEdge('A', 'B'); // true
138
+ graph.hasEdge('B', 'A'); // false
139
+
140
+ graph.removeEdgeSrcToDest('A', 'B');
141
+ graph.hasEdge('A', 'B'); // false
142
+
143
+ graph.addVertex('C');
144
+
145
+ graph.addEdge('A', 'B');
146
+ graph.addEdge('B', 'C');
147
+
148
+ const topologicalOrderIds = graph.topologicalSort(); // ['A', 'B', 'C']
149
+ ```
150
+
151
+ ### Undirected Graph snippet
152
+
153
+ #### TS or JS
154
+ ```typescript
155
+ import {UndirectedGraph} from 'data-structure-typed';
156
+
157
+ const graph = new UndirectedGraph();
158
+ graph.addVertex('A');
159
+ graph.addVertex('B');
160
+ graph.addVertex('C');
161
+ graph.addVertex('D');
162
+ graph.removeVertex('C');
163
+ graph.addEdge('A', 'B');
164
+ graph.addEdge('B', 'D');
165
+
166
+ const dijkstraResult = graph.dijkstra('A');
167
+ Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.id) // ['A', 'B', 'D']
168
+ ```
9
169
  ## Data Structures
10
170
 
11
171
  <table>
@@ -46,7 +206,7 @@ wide range of data structures
46
206
  <td>Tree Multiset</td>
47
207
  <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
48
208
  <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
49
- <td><a href="https://data-structure-typed-docs.vercel.app/classes/TreeMultiSet.html"><span>TreeMultiSet</span></a></td>
209
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/TreeMultiset.html"><span>TreeMultiset</span></a></td>
50
210
  <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
51
211
  </tr>
52
212
  <tr>
@@ -199,169 +359,6 @@ wide range of data structures
199
359
  </tbody>
200
360
  </table>
201
361
 
202
- ## Algorithms list only a few out, you can discover more in API docs
203
-
204
- DFS, DFSIterative, BFS, morris, Bellman-Ford Algorithm, Dijkstra's Algorithm, Floyd-Warshall Algorithm, Tarjan's Algorithm
205
-
206
- # How
207
- ## install
208
-
209
- ### yarn
210
-
211
- ```bash
212
- yarn add data-structure-typed
213
- ```
214
-
215
- ### npm
216
-
217
- ```bash
218
- npm install data-structure-typed
219
- ```
220
-
221
- ### Binary Search Tree (BST) snippet
222
-
223
- #### TS
224
- ```typescript
225
- import {BST, BSTNode} from 'data-structure-typed';
226
-
227
- const bst = new BST();
228
- bst.add(11);
229
- bst.add(3);
230
- bst.addMany([15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5]);
231
- bst.size === 16; // true
232
- bst.has(6); // true
233
- const node6 = bst.get(6);
234
- bst.getHeight(6) === 2; // true
235
- bst.getHeight() === 5; // true
236
- bst.getDepth(6) === 3; // true
237
- const leftMost = bst.getLeftMost();
238
- leftMost?.id === 1; // true
239
- expect(leftMost?.id).toBe(1);
240
- bst.remove(6);
241
- bst.get(6); // null
242
- bst.isAVLBalanced(); // true or false
243
- const bfsIDs = bst.BFS();
244
- bfsIDs[0] === 11; // true
245
- expect(bfsIDs[0]).toBe(11);
246
-
247
- const objBST = new BST<BSTNode<{ id: number, keyA: number }>>();
248
- objBST.add(11, {id: 11, keyA: 11});
249
- objBST.add(3, {id: 3, keyA: 3});
250
-
251
- objBST.addMany([{id: 15, keyA: 15}, {id: 1, keyA: 1}, {id: 8, keyA: 8},
252
- {id: 13, keyA: 13}, {id: 16, keyA: 16}, {id: 2, keyA: 2},
253
- {id: 6, keyA: 6}, {id: 9, keyA: 9}, {id: 12, keyA: 12},
254
- {id: 14, keyA: 14}, {id: 4, keyA: 4}, {id: 7, keyA: 7},
255
- {id: 10, keyA: 10}, {id: 5, keyA: 5}]);
256
-
257
- objBST.remove(11);
258
-
259
-
260
- const avlTree = new AVLTree();
261
- avlTree.addMany([11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5])
262
- avlTree.isAVLBalanced(); // true
263
- avlTree.remove(10);
264
- avlTree.isAVLBalanced(); // true
265
-
266
- ```
267
- #### JS
268
- ```javascript
269
- const {BST, BSTNode} = require('data-structure-typed');
270
-
271
- const bst = new BST();
272
- bst.add(11);
273
- bst.add(3);
274
- bst.addMany([15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5]);
275
- bst.size === 16; // true
276
- bst.has(6); // true
277
- const node6 = bst.get(6);
278
- bst.getHeight(6) === 2; // true
279
- bst.getHeight() === 5; // true
280
- bst.getDepth(6) === 3; // true
281
- const leftMost = bst.getLeftMost();
282
- leftMost?.id === 1; // true
283
- expect(leftMost?.id).toBe(1);
284
- bst.remove(6);
285
- bst.get(6); // null
286
- bst.isAVLBalanced(); // true or false
287
- const bfsIDs = bst.BFS();
288
- bfsIDs[0] === 11; // true
289
- expect(bfsIDs[0]).toBe(11);
290
-
291
- const objBST = new BST();
292
- objBST.add(11, {id: 11, keyA: 11});
293
- objBST.add(3, {id: 3, keyA: 3});
294
-
295
- objBST.addMany([{id: 15, keyA: 15}, {id: 1, keyA: 1}, {id: 8, keyA: 8},
296
- {id: 13, keyA: 13}, {id: 16, keyA: 16}, {id: 2, keyA: 2},
297
- {id: 6, keyA: 6}, {id: 9, keyA: 9}, {id: 12, keyA: 12},
298
- {id: 14, keyA: 14}, {id: 4, keyA: 4}, {id: 7, keyA: 7},
299
- {id: 10, keyA: 10}, {id: 5, keyA: 5}]);
300
-
301
- objBST.remove(11);
302
-
303
-
304
- const avlTree = new AVLTree();
305
- avlTree.addMany([11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5])
306
- avlTree.isAVLBalanced(); // true
307
- avlTree.remove(10);
308
- avlTree.isAVLBalanced(); // true
309
-
310
- ```
311
-
312
- ### Directed Graph simple snippet
313
-
314
- #### TS or JS
315
- ```typescript
316
- import {DirectedGraph} from 'data-structure-typed';
317
-
318
- const graph = new DirectedGraph();
319
-
320
- graph.addVertex('A');
321
- graph.addVertex('B');
322
-
323
- graph.hasVertex('A'); // true
324
- graph.hasVertex('B'); // true
325
- graph.hasVertex('C'); // false
326
-
327
- graph.addEdge('A', 'B');
328
- graph.hasEdge('A', 'B'); // true
329
- graph.hasEdge('B', 'A'); // false
330
-
331
- graph.removeEdgeSrcToDest('A', 'B');
332
- graph.hasEdge('A', 'B'); // false
333
-
334
- graph.addVertex('C');
335
-
336
- graph.addEdge('A', 'B');
337
- graph.addEdge('B', 'C');
338
-
339
- const topologicalOrderIds = graph.topologicalSort(); // ['A', 'B', 'C']
340
- ```
341
-
342
- ### Undirected Graph snippet
343
-
344
- #### TS or JS
345
- ```typescript
346
- import {UndirectedGraph} from 'data-structure-typed';
347
-
348
- const graph = new UndirectedGraph();
349
- graph.addVertex('A');
350
- graph.addVertex('B');
351
- graph.addVertex('C');
352
- graph.addVertex('D');
353
- graph.removeVertex('C');
354
- graph.addEdge('A', 'B');
355
- graph.addEdge('B', 'D');
356
-
357
- const dijkstraResult = graph.dijkstra('A');
358
- Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.id) // ['A', 'B', 'D']
359
- ```
360
-
361
- [API Docs](https://data-structure-typed-docs.vercel.app)
362
-
363
- [Live Examples](https://data-structure-typed-examples.vercel.app)
364
-
365
362
 
366
363
  ![](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/examples/dfs-pre-order.webp)
367
364
 
@@ -371,16 +368,20 @@ import {UndirectedGraph} from 'data-structure-typed';
371
368
 
372
369
  ![](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/examples/parenthesis-check.webp)
373
370
 
374
- <a href="https://data-structure-typed-examples.vercel.app" target="_blank">Live Examples</a>
375
371
 
372
+ ## API docs & Examples
376
373
 
377
- ## API docs
374
+ [API Docs](https://data-structure-typed-docs.vercel.app)
378
375
 
376
+ [Live Examples](https://data-structure-typed-examples.vercel.app)
377
+
378
+ <a href="https://data-structure-typed-examples.vercel.app" target="_blank">Live Examples</a>
379
379
 
380
380
  [//]: # ([Examples Repository]&#40;https://github.com/zrwusa/data-structure-typed-examples&#41;)
381
381
 
382
382
  <a href="https://github.com/zrwusa/data-structure-typed-examples" target="_blank">Examples Repository</a>
383
383
 
384
+
384
385
  # Why
385
386
 
386
387
  ## Complexities