data-structure-typed 1.32.2 → 1.33.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.
- package/.eslintrc.json +58 -0
- package/.idea/data-structure-typed.iml +19 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/.prettierrc +16 -0
- package/.travis.yml +17 -0
- package/CHANGELOG.md +1 -1
- package/README.md +366 -76
- package/coverage/coverage-final.json +4 -4
- package/docs/index.html +260 -9
- package/package.json +50 -18
- package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +46 -1
- package/.eslintrc.js +0 -61
- package/.prettierrc.js +0 -16
- package/coverage/clover.xml +0 -3393
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -386
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -196
- package/coverage/lcov-report/src/data-structures/binary-tree/aa-tree.ts.html +0 -88
- package/coverage/lcov-report/src/data-structures/binary-tree/abstract-binary-tree.ts.html +0 -4978
- package/coverage/lcov-report/src/data-structures/binary-tree/avl-tree.ts.html +0 -1015
- package/coverage/lcov-report/src/data-structures/binary-tree/b-tree.ts.html +0 -88
- package/coverage/lcov-report/src/data-structures/binary-tree/binary-indexed-tree.ts.html +0 -313
- package/coverage/lcov-report/src/data-structures/binary-tree/binary-tree.ts.html +0 -226
- package/coverage/lcov-report/src/data-structures/binary-tree/bst.ts.html +0 -1696
- package/coverage/lcov-report/src/data-structures/binary-tree/index.html +0 -296
- package/coverage/lcov-report/src/data-structures/binary-tree/index.ts.html +0 -121
- package/coverage/lcov-report/src/data-structures/binary-tree/rb-tree.ts.html +0 -388
- package/coverage/lcov-report/src/data-structures/binary-tree/segment-tree.ts.html +0 -811
- package/coverage/lcov-report/src/data-structures/binary-tree/splay-tree.ts.html +0 -88
- package/coverage/lcov-report/src/data-structures/binary-tree/tree-multiset.ts.html +0 -2185
- package/coverage/lcov-report/src/data-structures/binary-tree/two-three-tree.ts.html +0 -88
- package/coverage/lcov-report/src/data-structures/graph/abstract-graph.ts.html +0 -3205
- package/coverage/lcov-report/src/data-structures/graph/directed-graph.ts.html +0 -1495
- package/coverage/lcov-report/src/data-structures/graph/index.html +0 -176
- package/coverage/lcov-report/src/data-structures/graph/index.ts.html +0 -97
- package/coverage/lcov-report/src/data-structures/graph/map-graph.ts.html +0 -472
- package/coverage/lcov-report/src/data-structures/graph/undirected-graph.ts.html +0 -907
- package/coverage/lcov-report/src/data-structures/hash/coordinate-map.ts.html +0 -286
- package/coverage/lcov-report/src/data-structures/hash/coordinate-set.ts.html +0 -253
- package/coverage/lcov-report/src/data-structures/hash/hash-table.ts.html +0 -88
- package/coverage/lcov-report/src/data-structures/hash/index.html +0 -206
- package/coverage/lcov-report/src/data-structures/hash/index.ts.html +0 -103
- package/coverage/lcov-report/src/data-structures/hash/pair.ts.html +0 -88
- package/coverage/lcov-report/src/data-structures/hash/tree-map.ts.html +0 -88
- package/coverage/lcov-report/src/data-structures/hash/tree-set.ts.html +0 -88
- package/coverage/lcov-report/src/data-structures/heap/heap.ts.html +0 -721
- package/coverage/lcov-report/src/data-structures/heap/index.html +0 -161
- package/coverage/lcov-report/src/data-structures/heap/index.ts.html +0 -94
- package/coverage/lcov-report/src/data-structures/heap/max-heap.ts.html +0 -178
- package/coverage/lcov-report/src/data-structures/heap/min-heap.ts.html +0 -181
- package/coverage/lcov-report/src/data-structures/index.html +0 -116
- package/coverage/lcov-report/src/data-structures/index.ts.html +0 -118
- package/coverage/lcov-report/src/data-structures/linked-list/doubly-linked-list.ts.html +0 -1804
- package/coverage/lcov-report/src/data-structures/linked-list/index.html +0 -161
- package/coverage/lcov-report/src/data-structures/linked-list/index.ts.html +0 -94
- package/coverage/lcov-report/src/data-structures/linked-list/singly-linked-list.ts.html +0 -1588
- package/coverage/lcov-report/src/data-structures/linked-list/skip-linked-list.ts.html +0 -88
- package/coverage/lcov-report/src/data-structures/matrix/index.html +0 -176
- package/coverage/lcov-report/src/data-structures/matrix/index.ts.html +0 -97
- package/coverage/lcov-report/src/data-structures/matrix/matrix.ts.html +0 -166
- package/coverage/lcov-report/src/data-structures/matrix/matrix2d.ts.html +0 -721
- package/coverage/lcov-report/src/data-structures/matrix/navigator.ts.html +0 -448
- package/coverage/lcov-report/src/data-structures/matrix/vector2d.ts.html +0 -1033
- package/coverage/lcov-report/src/data-structures/priority-queue/index.html +0 -161
- package/coverage/lcov-report/src/data-structures/priority-queue/index.ts.html +0 -94
- package/coverage/lcov-report/src/data-structures/priority-queue/max-priority-queue.ts.html +0 -253
- package/coverage/lcov-report/src/data-structures/priority-queue/min-priority-queue.ts.html +0 -256
- package/coverage/lcov-report/src/data-structures/priority-queue/priority-queue.ts.html +0 -1162
- package/coverage/lcov-report/src/data-structures/queue/deque.ts.html +0 -976
- package/coverage/lcov-report/src/data-structures/queue/index.html +0 -146
- package/coverage/lcov-report/src/data-structures/queue/index.ts.html +0 -91
- package/coverage/lcov-report/src/data-structures/queue/queue.ts.html +0 -658
- package/coverage/lcov-report/src/data-structures/stack/index.html +0 -131
- package/coverage/lcov-report/src/data-structures/stack/index.ts.html +0 -88
- package/coverage/lcov-report/src/data-structures/stack/stack.ts.html +0 -379
- package/coverage/lcov-report/src/data-structures/tree/index.html +0 -131
- package/coverage/lcov-report/src/data-structures/tree/index.ts.html +0 -88
- package/coverage/lcov-report/src/data-structures/tree/tree.ts.html +0 -292
- package/coverage/lcov-report/src/data-structures/trie/index.html +0 -131
- package/coverage/lcov-report/src/data-structures/trie/index.ts.html +0 -88
- package/coverage/lcov-report/src/data-structures/trie/trie.ts.html +0 -760
- package/coverage/lcov-report/src/index.html +0 -116
- package/coverage/lcov-report/src/index.ts.html +0 -97
- package/coverage/lcov-report/src/interfaces/index.html +0 -116
- package/coverage/lcov-report/src/interfaces/index.ts.html +0 -130
- package/coverage/lcov-report/src/types/data-structures/abstract-binary-tree.ts.html +0 -235
- package/coverage/lcov-report/src/types/data-structures/bst.ts.html +0 -124
- package/coverage/lcov-report/src/types/data-structures/directed-graph.ts.html +0 -109
- package/coverage/lcov-report/src/types/data-structures/index.html +0 -176
- package/coverage/lcov-report/src/types/data-structures/index.ts.html +0 -130
- package/coverage/lcov-report/src/types/data-structures/rb-tree.ts.html +0 -106
- package/coverage/lcov-report/src/types/index.html +0 -116
- package/coverage/lcov-report/src/types/index.ts.html +0 -94
- package/coverage/lcov-report/src/types/utils/index.html +0 -116
- package/coverage/lcov-report/src/types/utils/index.ts.html +0 -91
- package/coverage/lcov-report/src/utils/index.html +0 -131
- package/coverage/lcov-report/src/utils/index.ts.html +0 -88
- package/coverage/lcov-report/src/utils/utils.ts.html +0 -322
- package/coverage/lcov-report/test/utils/index.html +0 -146
- package/coverage/lcov-report/test/utils/index.ts.html +0 -91
- package/coverage/lcov-report/test/utils/magnitude.ts.html +0 -148
- package/coverage/lcov-report/test/utils/number.ts.html +0 -94
- package/coverage/lcov.info +0 -6676
- package/docs/assets/highlight.css +0 -127
- package/docs/assets/main.js +0 -58
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1367
- package/docs/classes/AVLTree.html +0 -2182
- package/docs/classes/AVLTreeNode.html +0 -399
- package/docs/classes/AaTree.html +0 -202
- package/docs/classes/AbstractBinaryTree.html +0 -1836
- package/docs/classes/AbstractBinaryTreeNode.html +0 -441
- package/docs/classes/AbstractEdge.html +0 -345
- package/docs/classes/AbstractGraph.html +0 -1105
- package/docs/classes/AbstractVertex.html +0 -299
- package/docs/classes/ArrayDeque.html +0 -469
- package/docs/classes/BST.html +0 -2026
- package/docs/classes/BSTNode.html +0 -400
- package/docs/classes/BTree.html +0 -202
- package/docs/classes/BinaryIndexedTree.html +0 -371
- package/docs/classes/BinaryTree.html +0 -1867
- package/docs/classes/BinaryTreeNode.html +0 -399
- package/docs/classes/Character.html +0 -250
- package/docs/classes/CoordinateMap.html +0 -513
- package/docs/classes/CoordinateSet.html +0 -474
- package/docs/classes/Deque.html +0 -1005
- package/docs/classes/DirectedEdge.html +0 -404
- package/docs/classes/DirectedGraph.html +0 -1530
- package/docs/classes/DirectedVertex.html +0 -286
- package/docs/classes/DoublyLinkedList.html +0 -998
- package/docs/classes/DoublyLinkedListNode.html +0 -327
- package/docs/classes/HashTable.html +0 -202
- package/docs/classes/Heap.html +0 -647
- package/docs/classes/HeapItem.html +0 -296
- package/docs/classes/LinkedListQueue.html +0 -884
- package/docs/classes/MapEdge.html +0 -391
- package/docs/classes/MapGraph.html +0 -1583
- package/docs/classes/MapVertex.html +0 -356
- package/docs/classes/Matrix2D.html +0 -532
- package/docs/classes/MatrixNTI2D.html +0 -270
- package/docs/classes/MaxHeap.html +0 -671
- package/docs/classes/MaxPriorityQueue.html +0 -866
- package/docs/classes/MinHeap.html +0 -672
- package/docs/classes/MinPriorityQueue.html +0 -868
- package/docs/classes/Navigator.html +0 -343
- package/docs/classes/ObjectDeque.html +0 -527
- package/docs/classes/Pair.html +0 -202
- package/docs/classes/PriorityQueue.html +0 -790
- package/docs/classes/Queue.html +0 -521
- package/docs/classes/RBTree.html +0 -2024
- package/docs/classes/RBTreeNode.html +0 -431
- package/docs/classes/SegmentTree.html +0 -464
- package/docs/classes/SegmentTreeNode.html +0 -387
- package/docs/classes/SinglyLinkedList.html +0 -830
- package/docs/classes/SinglyLinkedListNode.html +0 -300
- package/docs/classes/SkipLinkedList.html +0 -202
- package/docs/classes/SplayTree.html +0 -202
- package/docs/classes/Stack.html +0 -398
- package/docs/classes/TreeMap.html +0 -202
- package/docs/classes/TreeMultiset.html +0 -2510
- package/docs/classes/TreeMultisetNode.html +0 -447
- package/docs/classes/TreeNode.html +0 -344
- package/docs/classes/TreeSet.html +0 -202
- package/docs/classes/Trie.html +0 -402
- package/docs/classes/TrieNode.html +0 -310
- package/docs/classes/TwoThreeTree.html +0 -202
- package/docs/classes/UndirectedEdge.html +0 -374
- package/docs/classes/UndirectedGraph.html +0 -1285
- package/docs/classes/UndirectedVertex.html +0 -284
- package/docs/classes/Vector2D.html +0 -835
- package/docs/enums/CP.html +0 -211
- package/docs/enums/FamilyPosition.html +0 -239
- package/docs/enums/LoopType.html +0 -212
- package/docs/enums/RBColor.html +0 -204
- package/docs/enums/TopologicalProperty.html +0 -211
- package/docs/functions/arrayRemove.html +0 -208
- package/docs/functions/isThunk.html +0 -186
- package/docs/functions/toThunk.html +0 -186
- package/docs/functions/trampoline.html +0 -186
- package/docs/functions/trampolineAsync.html +0 -186
- package/docs/functions/uuidV4.html +0 -181
- package/docs/interfaces/IAVLTree.html +0 -1245
- package/docs/interfaces/IAbstractBinaryTree.html +0 -1101
- package/docs/interfaces/IAbstractBinaryTreeNode.html +0 -335
- package/docs/interfaces/IAbstractGraph.html +0 -433
- package/docs/interfaces/IBST.html +0 -1245
- package/docs/interfaces/IDirectedGraph.html +0 -570
- package/docs/interfaces/IRBTree.html +0 -1247
- package/docs/interfaces/IUNDirectedGraph.html +0 -463
- package/docs/types/AVLTreeNodeNested.html +0 -182
- package/docs/types/AVLTreeOptions.html +0 -180
- package/docs/types/AbstractBinaryTreeNodeNested.html +0 -182
- package/docs/types/AbstractBinaryTreeNodeProperties.html +0 -182
- package/docs/types/AbstractBinaryTreeNodeProperty.html +0 -182
- package/docs/types/AbstractBinaryTreeOptions.html +0 -182
- package/docs/types/BSTComparator.html +0 -192
- package/docs/types/BSTNodeNested.html +0 -182
- package/docs/types/BSTOptions.html +0 -182
- package/docs/types/BinaryTreeDeletedResult.html +0 -189
- package/docs/types/BinaryTreeNodeId.html +0 -177
- package/docs/types/BinaryTreeNodeNested.html +0 -182
- package/docs/types/BinaryTreeNodePropertyName.html +0 -177
- package/docs/types/BinaryTreeOptions.html +0 -180
- package/docs/types/DFSOrderPattern.html +0 -177
- package/docs/types/DijkstraResult.html +0 -199
- package/docs/types/Direction.html +0 -177
- package/docs/types/DummyAny.html +0 -190
- package/docs/types/EdgeId.html +0 -177
- package/docs/types/HeapOptions.html +0 -198
- package/docs/types/IAVLTreeNode.html +0 -184
- package/docs/types/IBSTNode.html +0 -184
- package/docs/types/IBinaryTree.html +0 -182
- package/docs/types/IBinaryTreeNode.html +0 -184
- package/docs/types/IRBTreeNode.html +0 -184
- package/docs/types/ITreeMultiset.html +0 -182
- package/docs/types/ITreeMultisetNode.html +0 -184
- package/docs/types/KeyValueObject.html +0 -182
- package/docs/types/KeyValueObjectWithId.html +0 -184
- package/docs/types/MapGraphCoordinate.html +0 -177
- package/docs/types/NavigatorParams.html +0 -211
- package/docs/types/NodeOrPropertyName.html +0 -177
- package/docs/types/NonNumberNonObjectButDefined.html +0 -177
- package/docs/types/ObjectWithNonNumberId.html +0 -184
- package/docs/types/ObjectWithNumberId.html +0 -184
- package/docs/types/ObjectWithoutId.html +0 -177
- package/docs/types/PriorityQueueComparator.html +0 -197
- package/docs/types/PriorityQueueDFSOrderPattern.html +0 -177
- package/docs/types/PriorityQueueOptions.html +0 -191
- package/docs/types/RBTreeNodeNested.html +0 -182
- package/docs/types/RBTreeOptions.html +0 -180
- package/docs/types/RestrictValById.html +0 -177
- package/docs/types/SegmentTreeNodeVal.html +0 -177
- package/docs/types/SpecifyOptional.html +0 -184
- package/docs/types/Thunk.html +0 -185
- package/docs/types/ToThunkFn.html +0 -185
- package/docs/types/TopologicalStatus.html +0 -177
- package/docs/types/TreeMultisetNodeNested.html +0 -182
- package/docs/types/TreeMultisetOptions.html +0 -180
- package/docs/types/TrlAsyncFn.html +0 -190
- package/docs/types/TrlFn.html +0 -190
- package/docs/types/Turning.html +0 -177
- package/docs/types/VertexId.html +0 -177
- package/docs/variables/THUNK_SYMBOL.html +0 -177
- /package/{CODE-OF-CONDUCT.md → CODE_OF_CONDUCT.md} +0 -0
package/README.md
CHANGED
|
@@ -8,29 +8,49 @@
|
|
|
8
8
|

|
|
9
9
|
|
|
10
10
|
## Brief
|
|
11
|
-
|
|
11
|
+
|
|
12
|
+
Data Structures of Javascript & TypeScript.
|
|
12
13
|
|
|
13
14
|
## Built-in classic algorithms
|
|
14
|
-
|
|
15
|
-
morris, Bellman-Ford Algorithm, Dijkstra's Algorithm,
|
|
16
|
-
Tarjan's Algorithm.
|
|
15
|
+
|
|
16
|
+
DFS(Depth-First Search), DFSIterative, BFS(Breadth-First Search), morris, Bellman-Ford Algorithm, Dijkstra's Algorithm,
|
|
17
|
+
Floyd-Warshall Algorithm, Tarjan's Algorithm.
|
|
17
18
|
|
|
18
19
|
## Installation and Usage
|
|
20
|
+
|
|
19
21
|
### npm
|
|
22
|
+
|
|
20
23
|
```bash
|
|
21
24
|
npm install data-structure-typed --save
|
|
22
25
|
```
|
|
26
|
+
|
|
23
27
|
### yarn
|
|
28
|
+
|
|
24
29
|
```bash
|
|
25
30
|
yarn add data-structure-typed
|
|
26
31
|
```
|
|
32
|
+
|
|
27
33
|
### CDN
|
|
34
|
+
|
|
28
35
|
```html
|
|
36
|
+
|
|
29
37
|
<script src="https://cdn.jsdelivr.net/npm/data-structure-typed/umd/bundle.min.js"></script>
|
|
30
38
|
```
|
|
39
|
+
|
|
31
40
|
```js
|
|
32
41
|
const {AVLTree} = dataStructureTyped;
|
|
33
|
-
const {
|
|
42
|
+
const {
|
|
43
|
+
Heap,
|
|
44
|
+
MinHeap,
|
|
45
|
+
SinglyLinkedList,
|
|
46
|
+
Stack,
|
|
47
|
+
AVLTreeNode,
|
|
48
|
+
BST,
|
|
49
|
+
Trie,
|
|
50
|
+
DirectedGraph,
|
|
51
|
+
DirectedVertex,
|
|
52
|
+
TreeMultiset
|
|
53
|
+
} = dataStructureTyped;
|
|
34
54
|
```
|
|
35
55
|
|
|
36
56
|

|
|
@@ -50,86 +70,93 @@ const {Heap, MinHeap, SinglyLinkedList, Stack, AVLTreeNode, BST, Trie, DirectedG
|
|
|
50
70
|
<a href="https://github.com/zrwusa/vivid-algorithm" target="_blank">Examples Repository</a>
|
|
51
71
|
|
|
52
72
|
## Code Snippet
|
|
73
|
+
|
|
53
74
|
### Binary Search Tree (BST) snippet
|
|
75
|
+
|
|
54
76
|
#### TS
|
|
77
|
+
|
|
55
78
|
```ts
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
79
|
+
import {BST, BSTNode} from 'data-structure-typed';
|
|
80
|
+
|
|
81
|
+
const bst = new BST();
|
|
82
|
+
bst.add(11);
|
|
83
|
+
bst.add(3);
|
|
84
|
+
bst.addMany([15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5]);
|
|
85
|
+
bst.size === 16; // true
|
|
86
|
+
bst.has(6); // true
|
|
87
|
+
const node6 = bst.get(6); // BSTNode
|
|
88
|
+
bst.getHeight(6) === 2; // true
|
|
89
|
+
bst.getHeight() === 5; // true
|
|
90
|
+
bst.getDepth(6) === 3; // true
|
|
91
|
+
|
|
92
|
+
bst.getLeftMost()?.id === 1; // true
|
|
93
|
+
|
|
94
|
+
bst.remove(6);
|
|
95
|
+
bst.get(6); // null
|
|
96
|
+
bst.isAVLBalanced(); // true
|
|
97
|
+
bst.BFS()[0] === 11; // true
|
|
98
|
+
|
|
99
|
+
const objBST = new BST<BSTNode<{ id: number, keyA: number }>>();
|
|
100
|
+
objBST.add(11, {id: 11, keyA: 11});
|
|
101
|
+
objBST.add(3, {id: 3, keyA: 3});
|
|
102
|
+
|
|
103
|
+
objBST.addMany([{id: 15, keyA: 15}, {id: 1, keyA: 1}, {id: 8, keyA: 8},
|
|
104
|
+
{id: 13, keyA: 13}, {id: 16, keyA: 16}, {id: 2, keyA: 2},
|
|
105
|
+
{id: 6, keyA: 6}, {id: 9, keyA: 9}, {id: 12, keyA: 12},
|
|
106
|
+
{id: 14, keyA: 14}, {id: 4, keyA: 4}, {id: 7, keyA: 7},
|
|
107
|
+
{id: 10, keyA: 10}, {id: 5, keyA: 5}]);
|
|
108
|
+
|
|
109
|
+
objBST.remove(11);
|
|
87
110
|
```
|
|
111
|
+
|
|
88
112
|
#### JS
|
|
113
|
+
|
|
89
114
|
```js
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
115
|
+
const {BST, BSTNode} = require('data-structure-typed');
|
|
116
|
+
|
|
117
|
+
const bst = new BST();
|
|
118
|
+
bst.add(11);
|
|
119
|
+
bst.add(3);
|
|
120
|
+
bst.addMany([15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5]);
|
|
121
|
+
bst.size === 16; // true
|
|
122
|
+
bst.has(6); // true
|
|
123
|
+
const node6 = bst.get(6);
|
|
124
|
+
bst.getHeight(6) === 2; // true
|
|
125
|
+
bst.getHeight() === 5; // true
|
|
126
|
+
bst.getDepth(6) === 3; // true
|
|
127
|
+
const leftMost = bst.getLeftMost();
|
|
128
|
+
leftMost?.id === 1; // true
|
|
129
|
+
expect(leftMost?.id).toBe(1);
|
|
130
|
+
bst.remove(6);
|
|
131
|
+
bst.get(6); // null
|
|
132
|
+
bst.isAVLBalanced(); // true or false
|
|
133
|
+
const bfsIDs = bst.BFS();
|
|
134
|
+
bfsIDs[0] === 11; // true
|
|
135
|
+
expect(bfsIDs[0]).toBe(11);
|
|
136
|
+
|
|
137
|
+
const objBST = new BST();
|
|
138
|
+
objBST.add(11, {id: 11, keyA: 11});
|
|
139
|
+
objBST.add(3, {id: 3, keyA: 3});
|
|
140
|
+
|
|
141
|
+
objBST.addMany([{id: 15, keyA: 15}, {id: 1, keyA: 1}, {id: 8, keyA: 8},
|
|
142
|
+
{id: 13, keyA: 13}, {id: 16, keyA: 16}, {id: 2, keyA: 2},
|
|
143
|
+
{id: 6, keyA: 6}, {id: 9, keyA: 9}, {id: 12, keyA: 12},
|
|
144
|
+
{id: 14, keyA: 14}, {id: 4, keyA: 4}, {id: 7, keyA: 7},
|
|
145
|
+
{id: 10, keyA: 10}, {id: 5, keyA: 5}]);
|
|
146
|
+
|
|
147
|
+
objBST.remove(11);
|
|
148
|
+
|
|
149
|
+
const avlTree = new AVLTree();
|
|
150
|
+
avlTree.addMany([11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5])
|
|
151
|
+
avlTree.isAVLBalanced(); // true
|
|
152
|
+
avlTree.remove(10);
|
|
153
|
+
avlTree.isAVLBalanced(); // true
|
|
129
154
|
```
|
|
130
155
|
|
|
131
156
|
### AVLTree snippet
|
|
157
|
+
|
|
132
158
|
#### TS
|
|
159
|
+
|
|
133
160
|
```ts
|
|
134
161
|
import {AVLTree} from 'data-structure-typed';
|
|
135
162
|
|
|
@@ -139,7 +166,9 @@ avlTree.isAVLBalanced(); // true
|
|
|
139
166
|
avlTree.remove(10);
|
|
140
167
|
avlTree.isAVLBalanced(); // true
|
|
141
168
|
```
|
|
169
|
+
|
|
142
170
|
#### JS
|
|
171
|
+
|
|
143
172
|
```js
|
|
144
173
|
const {AVLTree} = require('data-structure-typed');
|
|
145
174
|
|
|
@@ -151,7 +180,9 @@ avlTree.isAVLBalanced(); // true
|
|
|
151
180
|
```
|
|
152
181
|
|
|
153
182
|
### Directed Graph simple snippet
|
|
183
|
+
|
|
154
184
|
#### TS or JS
|
|
185
|
+
|
|
155
186
|
```ts
|
|
156
187
|
import {DirectedGraph} from 'data-structure-typed';
|
|
157
188
|
|
|
@@ -180,7 +211,9 @@ const topologicalOrderIds = graph.topologicalSort(); // ['A', 'B', 'C']
|
|
|
180
211
|
```
|
|
181
212
|
|
|
182
213
|
### Undirected Graph snippet
|
|
214
|
+
|
|
183
215
|
#### TS or JS
|
|
216
|
+
|
|
184
217
|
```ts
|
|
185
218
|
import {UndirectedGraph} from 'data-structure-typed';
|
|
186
219
|
|
|
@@ -198,6 +231,7 @@ Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.id) // ['A', 'B', 'D
|
|
|
198
231
|
```
|
|
199
232
|
|
|
200
233
|
## Data Structures
|
|
234
|
+
|
|
201
235
|
<table>
|
|
202
236
|
<thead>
|
|
203
237
|
<tr>
|
|
@@ -374,11 +408,15 @@ Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.id) // ['A', 'B', 'D
|
|
|
374
408
|
</table>
|
|
375
409
|
|
|
376
410
|
## Code design
|
|
377
|
-
|
|
411
|
+
|
|
412
|
+
By strictly adhering to object-oriented design (BinaryTree -> BST -> AVLTree -> TreeMultiset), you can seamlessly
|
|
413
|
+
inherit the existing data structures to implement the customized ones you need. Object-oriented design stands as the
|
|
414
|
+
optimal approach to data structure design.
|
|
378
415
|
|
|
379
416
|
## Complexities
|
|
380
417
|
|
|
381
418
|
### performance of Big O
|
|
419
|
+
|
|
382
420
|
<table>
|
|
383
421
|
<thead>
|
|
384
422
|
<tr>
|
|
@@ -443,6 +481,7 @@ By strictly adhering to object-oriented design (BinaryTree -> BST -> AVLTree ->
|
|
|
443
481
|
</table>
|
|
444
482
|
|
|
445
483
|
### Data Structure Complexity
|
|
484
|
+
|
|
446
485
|
<table>
|
|
447
486
|
<thead>
|
|
448
487
|
<tr>
|
|
@@ -539,6 +578,7 @@ By strictly adhering to object-oriented design (BinaryTree -> BST -> AVLTree ->
|
|
|
539
578
|
</table>
|
|
540
579
|
|
|
541
580
|
### Sorting Complexity
|
|
581
|
+
|
|
542
582
|
<table>
|
|
543
583
|
<thead>
|
|
544
584
|
<tr>
|
|
@@ -635,3 +675,253 @@ By strictly adhering to object-oriented design (BinaryTree -> BST -> AVLTree ->
|
|
|
635
675
|
</tr>
|
|
636
676
|
</tbody>
|
|
637
677
|
</table>
|
|
678
|
+
|
|
679
|
+
|
|
680
|
+
<table>
|
|
681
|
+
<tr>
|
|
682
|
+
<th>Data Structure</th>
|
|
683
|
+
<th>C++ STL</th>
|
|
684
|
+
<th>java.util</th>
|
|
685
|
+
<th>Python collections</th>
|
|
686
|
+
</tr>
|
|
687
|
+
<tr>
|
|
688
|
+
<td>Dynamic Array (ArrayList)</td>
|
|
689
|
+
<td>std::vector<T></td>
|
|
690
|
+
<td>ArrayList<E></td>
|
|
691
|
+
<td>list</td>
|
|
692
|
+
</tr>
|
|
693
|
+
<tr>
|
|
694
|
+
<td>Linked List</td>
|
|
695
|
+
<td>std::list<T></td>
|
|
696
|
+
<td>LinkedList<E></td>
|
|
697
|
+
<td>deque</td>
|
|
698
|
+
</tr>
|
|
699
|
+
<tr>
|
|
700
|
+
<td>Set</td>
|
|
701
|
+
<td>std::set<T></td>
|
|
702
|
+
<td>HashSet<E></td>
|
|
703
|
+
<td>set</td>
|
|
704
|
+
</tr>
|
|
705
|
+
<tr>
|
|
706
|
+
<td>Map</td>
|
|
707
|
+
<td>std::map<K, V></td>
|
|
708
|
+
<td>HashMap<K, V></td>
|
|
709
|
+
<td>dict</td>
|
|
710
|
+
</tr>
|
|
711
|
+
<tr>
|
|
712
|
+
<td>Stack</td>
|
|
713
|
+
<td>std::stack<T></td>
|
|
714
|
+
<td>Stack<E></td>
|
|
715
|
+
<td>N/A</td>
|
|
716
|
+
</tr>
|
|
717
|
+
<tr>
|
|
718
|
+
<td>Queue</td>
|
|
719
|
+
<td>std::queue<T></td>
|
|
720
|
+
<td>LinkedList<E></td>
|
|
721
|
+
<td>N/A</td>
|
|
722
|
+
</tr>
|
|
723
|
+
<tr>
|
|
724
|
+
<td>Priority Queue</td>
|
|
725
|
+
<td>std::priority_queue<T></td>
|
|
726
|
+
<td>PriorityQueue<E></td>
|
|
727
|
+
<td>N/A</td>
|
|
728
|
+
</tr>
|
|
729
|
+
<tr>
|
|
730
|
+
<td>Hash Table</td>
|
|
731
|
+
<td>N/A</td>
|
|
732
|
+
<td>N/A</td>
|
|
733
|
+
<td>defaultdict, Counter, etc.</td>
|
|
734
|
+
</tr>
|
|
735
|
+
<tr>
|
|
736
|
+
<td>Deque</td>
|
|
737
|
+
<td>std::deque<T></td>
|
|
738
|
+
<td>N/A</td>
|
|
739
|
+
<td>N/A</td>
|
|
740
|
+
</tr>
|
|
741
|
+
<tr>
|
|
742
|
+
<td>Multiset</td>
|
|
743
|
+
<td>std::multiset<T></td>
|
|
744
|
+
<td>N/A</td>
|
|
745
|
+
<td>N/A</td>
|
|
746
|
+
</tr>
|
|
747
|
+
<tr>
|
|
748
|
+
<td>Multimap</td>
|
|
749
|
+
<td>std::multimap<K, V></td>
|
|
750
|
+
<td>N/A</td>
|
|
751
|
+
<td>N/A</td>
|
|
752
|
+
</tr>
|
|
753
|
+
<tr>
|
|
754
|
+
<td>Unordered Set</td>
|
|
755
|
+
<td>std::unordered_set<T></td>
|
|
756
|
+
<td>HashSet<E></td>
|
|
757
|
+
<td>N/A</td>
|
|
758
|
+
</tr>
|
|
759
|
+
<tr>
|
|
760
|
+
<td>Unordered Map</td>
|
|
761
|
+
<td>std::unordered_map<K, V></td>
|
|
762
|
+
<td>HashMap<K, V></td>
|
|
763
|
+
<td>N/A</td>
|
|
764
|
+
</tr>
|
|
765
|
+
<tr>
|
|
766
|
+
<td>Bitset</td>
|
|
767
|
+
<td>std::bitset<N></td>
|
|
768
|
+
<td>N/A</td>
|
|
769
|
+
<td>N/A</td>
|
|
770
|
+
</tr>
|
|
771
|
+
<tr>
|
|
772
|
+
<td>Ordered Dictionary (OrderedDict)</td>
|
|
773
|
+
<td>N/A</td>
|
|
774
|
+
<td>N/A</td>
|
|
775
|
+
<td>OrderedDict</td>
|
|
776
|
+
</tr>
|
|
777
|
+
<tr>
|
|
778
|
+
<td>User-Defined Dictionary</td>
|
|
779
|
+
<td>N/A</td>
|
|
780
|
+
<td>N/A</td>
|
|
781
|
+
<td>UserDict</td>
|
|
782
|
+
</tr>
|
|
783
|
+
<tr>
|
|
784
|
+
<td>User-Defined List</td>
|
|
785
|
+
<td>N/A</td>
|
|
786
|
+
<td>N/A</td>
|
|
787
|
+
<td>UserList</td>
|
|
788
|
+
</tr>
|
|
789
|
+
<tr>
|
|
790
|
+
<td>User-Defined Set</td>
|
|
791
|
+
<td>N/A</td>
|
|
792
|
+
<td>N/A</td>
|
|
793
|
+
<td>UserSet</td>
|
|
794
|
+
</tr>
|
|
795
|
+
<tr>
|
|
796
|
+
<td>Double-Ended Queue (Deque)</td>
|
|
797
|
+
<td>std::deque<T></td>
|
|
798
|
+
<td>N/A</td>
|
|
799
|
+
<td>N/A</td>
|
|
800
|
+
</tr>
|
|
801
|
+
<tr>
|
|
802
|
+
<td>Skip List</td>
|
|
803
|
+
<td>N/A</td>
|
|
804
|
+
<td>N/A</td>
|
|
805
|
+
<td>N/A</td>
|
|
806
|
+
</tr>
|
|
807
|
+
<tr>
|
|
808
|
+
<td>Circular Queue</td>
|
|
809
|
+
<td>N/A</td>
|
|
810
|
+
<td>N/A</td>
|
|
811
|
+
<td>N/A</td>
|
|
812
|
+
</tr>
|
|
813
|
+
<tr>
|
|
814
|
+
<td>Bit Array</td>
|
|
815
|
+
<td>N/A</td>
|
|
816
|
+
<td>N/A</td>
|
|
817
|
+
<td>N/A</td>
|
|
818
|
+
</tr>
|
|
819
|
+
<tr>
|
|
820
|
+
<td>Bloom Filter</td>
|
|
821
|
+
<td>N/A</td>
|
|
822
|
+
<td>N/A</td>
|
|
823
|
+
<td>N/A</td>
|
|
824
|
+
</tr>
|
|
825
|
+
<tr>
|
|
826
|
+
<td>Linked Hash Set</td>
|
|
827
|
+
<td>N/A</td>
|
|
828
|
+
<td>LinkedHashSet<E></td>
|
|
829
|
+
<td>N/A</td>
|
|
830
|
+
</tr>
|
|
831
|
+
<tr>
|
|
832
|
+
<td>Linked Hash Map</td>
|
|
833
|
+
<td>N/A</td>
|
|
834
|
+
<td>LinkedHashMap<K, V></td>
|
|
835
|
+
<td>N/A</td>
|
|
836
|
+
</tr>
|
|
837
|
+
<tr>
|
|
838
|
+
<td>Sorted Set</td>
|
|
839
|
+
<td>N/A</td>
|
|
840
|
+
<td>TreeSet<E></td>
|
|
841
|
+
<td>N/A</td>
|
|
842
|
+
</tr>
|
|
843
|
+
<tr>
|
|
844
|
+
<td>Sorted Map</td>
|
|
845
|
+
<td>N/A</td>
|
|
846
|
+
<td>TreeMap<K, V></td>
|
|
847
|
+
<td>N/A</td>
|
|
848
|
+
</tr>
|
|
849
|
+
<tr>
|
|
850
|
+
<td>Tree Set</td>
|
|
851
|
+
<td>N/A</td>
|
|
852
|
+
<td>N/A</td>
|
|
853
|
+
<td>N/A</td>
|
|
854
|
+
</tr>
|
|
855
|
+
<tr>
|
|
856
|
+
<td>Tree Map</td>
|
|
857
|
+
<td>N/A</td>
|
|
858
|
+
<td>N/A</td>
|
|
859
|
+
<td>N/A</td>
|
|
860
|
+
</tr>
|
|
861
|
+
<tr>
|
|
862
|
+
<td>Persistent Collections</td>
|
|
863
|
+
<td>N/A</td>
|
|
864
|
+
<td>N/A</td>
|
|
865
|
+
<td>N/A</td>
|
|
866
|
+
</tr>
|
|
867
|
+
<tr>
|
|
868
|
+
<td>std::unordered_multiset</td>
|
|
869
|
+
<td>std::unordered_multiset<T></td>
|
|
870
|
+
<td>N/A</td>
|
|
871
|
+
<td>N/A</td>
|
|
872
|
+
</tr>
|
|
873
|
+
<tr>
|
|
874
|
+
<td>std::unordered_multimap</td>
|
|
875
|
+
<td>std::unordered_multimap<K, V></td>
|
|
876
|
+
<td>N/A</td>
|
|
877
|
+
<td>N/A</td>
|
|
878
|
+
</tr>
|
|
879
|
+
<tr>
|
|
880
|
+
<td>N/A</td>
|
|
881
|
+
<td>TreeSet<E></td>
|
|
882
|
+
<td>TreeSet<E></td>
|
|
883
|
+
<td>N/A</td>
|
|
884
|
+
</tr>
|
|
885
|
+
<tr>
|
|
886
|
+
<td>N/A</td>
|
|
887
|
+
<td>TreeMap<K, V></td>
|
|
888
|
+
<td>TreeMap<K, V></td>
|
|
889
|
+
<td>N/A</td>
|
|
890
|
+
</tr>
|
|
891
|
+
<tr>
|
|
892
|
+
<td>N/A</td>
|
|
893
|
+
<td>LinkedBlockingQueue<E></td>
|
|
894
|
+
<td>N/A</td>
|
|
895
|
+
<td>N/A</td>
|
|
896
|
+
</tr>
|
|
897
|
+
<tr>
|
|
898
|
+
<td>N/A</td>
|
|
899
|
+
<td>ConcurrentHashMap<K, V></td>
|
|
900
|
+
<td>N/A</td>
|
|
901
|
+
<td>N/A</td>
|
|
902
|
+
</tr>
|
|
903
|
+
<tr>
|
|
904
|
+
<td>N/A</td>
|
|
905
|
+
<td>N/A</td>
|
|
906
|
+
<td>namedtuple</td>
|
|
907
|
+
<td>N/A</td>
|
|
908
|
+
</tr>
|
|
909
|
+
<tr>
|
|
910
|
+
<td>N/A</td>
|
|
911
|
+
<td>N/A</td>
|
|
912
|
+
<td>ChainMap</td>
|
|
913
|
+
<td>N/A</td>
|
|
914
|
+
</tr>
|
|
915
|
+
<tr>
|
|
916
|
+
<td>N/A</td>
|
|
917
|
+
<td>N/A</td>
|
|
918
|
+
<td>defaultdict</td>
|
|
919
|
+
<td>N/A</td>
|
|
920
|
+
</tr>
|
|
921
|
+
<tr>
|
|
922
|
+
<td>N/A</td>
|
|
923
|
+
<td>N/A</td>
|
|
924
|
+
<td>Counter</td>
|
|
925
|
+
<td>N/A</td>
|
|
926
|
+
</tr>
|
|
927
|
+
</table>
|