data-structure-typed 0.8.18 → 0.9.16
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/.idea/modules.xml +1 -1
- package/README.md +197 -2
- package/dist/data-structures/binary-tree/aa-tree.js +5 -2
- package/dist/data-structures/binary-tree/avl-tree.d.ts +1 -5
- package/dist/data-structures/binary-tree/avl-tree.js +93 -46
- package/dist/data-structures/binary-tree/b-tree.js +5 -2
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -1
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +14 -13
- package/dist/data-structures/binary-tree/binary-tree.d.ts +20 -32
- package/dist/data-structures/binary-tree/binary-tree.js +480 -370
- package/dist/data-structures/binary-tree/bst.d.ts +4 -8
- package/dist/data-structures/binary-tree/bst.js +152 -107
- package/dist/data-structures/binary-tree/rb-tree.js +5 -2
- package/dist/data-structures/binary-tree/segment-tree.d.ts +3 -3
- package/dist/data-structures/binary-tree/segment-tree.js +91 -61
- package/dist/data-structures/binary-tree/splay-tree.js +5 -2
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +1 -5
- package/dist/data-structures/binary-tree/tree-multiset.js +31 -11
- package/dist/data-structures/binary-tree/two-three-tree.js +5 -2
- package/dist/data-structures/graph/abstract-graph.d.ts +5 -33
- package/dist/data-structures/graph/abstract-graph.js +546 -311
- package/dist/data-structures/graph/directed-graph.d.ts +5 -13
- package/dist/data-structures/graph/directed-graph.js +250 -128
- package/dist/data-structures/graph/undirected-graph.d.ts +4 -3
- package/dist/data-structures/graph/undirected-graph.js +166 -81
- package/dist/data-structures/hash/coordinate-map.d.ts +1 -1
- package/dist/data-structures/hash/coordinate-map.js +38 -20
- package/dist/data-structures/hash/coordinate-set.js +33 -15
- package/dist/data-structures/hash/index.d.ts +5 -0
- package/dist/data-structures/hash/index.js +5 -0
- package/dist/data-structures/heap/heap.d.ts +2 -8
- package/dist/data-structures/heap/heap.js +36 -31
- package/dist/data-structures/heap/max-heap.d.ts +3 -2
- package/dist/data-structures/heap/max-heap.js +27 -9
- package/dist/data-structures/heap/min-heap.d.ts +3 -2
- package/dist/data-structures/heap/min-heap.js +27 -9
- package/dist/data-structures/index.d.ts +1 -0
- package/dist/data-structures/index.js +1 -0
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +0 -1
- package/dist/data-structures/linked-list/doubly-linked-list.js +56 -53
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +8 -12
- package/dist/data-structures/linked-list/singly-linked-list.js +308 -174
- package/dist/data-structures/matrix/matrix.js +8 -7
- package/dist/data-structures/matrix/matrix2d.d.ts +5 -5
- package/dist/data-structures/matrix/matrix2d.js +80 -63
- package/dist/data-structures/matrix/navigator.d.ts +2 -16
- package/dist/data-structures/matrix/navigator.js +37 -18
- package/dist/data-structures/matrix/vector2d.d.ts +18 -18
- package/dist/data-structures/matrix/vector2d.js +117 -94
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +3 -2
- package/dist/data-structures/priority-queue/max-priority-queue.js +25 -8
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +3 -2
- package/dist/data-structures/priority-queue/min-priority-queue.js +25 -8
- package/dist/data-structures/priority-queue/priority-queue.d.ts +15 -21
- package/dist/data-structures/priority-queue/priority-queue.js +159 -116
- package/dist/data-structures/queue/deque.js +82 -56
- package/dist/data-structures/queue/queue.d.ts +9 -10
- package/dist/data-structures/queue/queue.js +34 -34
- package/dist/data-structures/stack/stack.d.ts +9 -10
- package/dist/data-structures/stack/stack.js +31 -31
- package/dist/data-structures/trampoline.d.ts +14 -23
- package/dist/data-structures/trampoline.js +103 -25
- package/dist/data-structures/trie/trie.d.ts +13 -3
- package/dist/data-structures/trie/trie.js +234 -80
- package/dist/data-structures/types/abstract-graph.d.ts +29 -0
- package/dist/data-structures/types/abstract-graph.js +2 -0
- package/dist/data-structures/types/avl-tree.d.ts +5 -0
- package/dist/data-structures/types/avl-tree.js +2 -0
- package/dist/data-structures/types/binary-tree.d.ts +16 -0
- package/dist/data-structures/types/binary-tree.js +2 -0
- package/dist/data-structures/types/bst.d.ts +7 -0
- package/dist/data-structures/types/bst.js +2 -0
- package/dist/data-structures/types/directed-graph.d.ts +10 -0
- package/dist/data-structures/types/directed-graph.js +2 -0
- package/dist/data-structures/types/doubly-linked-list.d.ts +1 -0
- package/dist/data-structures/types/doubly-linked-list.js +2 -0
- package/dist/data-structures/types/heap.d.ts +7 -0
- package/dist/data-structures/types/heap.js +2 -0
- package/dist/data-structures/types/index.d.ts +13 -0
- package/dist/data-structures/types/index.js +29 -0
- package/dist/data-structures/types/navigator.d.ts +14 -0
- package/dist/data-structures/types/navigator.js +2 -0
- package/dist/data-structures/types/priority-queue.d.ts +7 -0
- package/dist/data-structures/types/priority-queue.js +2 -0
- package/dist/data-structures/types/segment-tree.d.ts +1 -0
- package/dist/data-structures/types/segment-tree.js +2 -0
- package/dist/data-structures/types/singly-linked-list.d.ts +5 -0
- package/dist/data-structures/types/singly-linked-list.js +2 -0
- package/dist/data-structures/types/tree-multiset.d.ts +5 -0
- package/dist/data-structures/types/tree-multiset.js +2 -0
- package/dist/{types → data-structures/types}/utils.d.ts +7 -1
- package/dist/{types → data-structures/types}/utils.js +20 -19
- package/dist/{utils.d.ts → utils/utils.d.ts} +6 -23
- package/dist/utils/utils.js +651 -0
- package/package.json +20 -42
- package/src/data-structures/binary-tree/avl-tree.ts +1 -6
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +4 -4
- package/src/data-structures/binary-tree/binary-tree.ts +184 -139
- package/src/data-structures/binary-tree/bst.ts +15 -24
- package/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
- package/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
- package/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
- package/src/data-structures/binary-tree/segment-tree.ts +20 -12
- package/src/data-structures/binary-tree/tree-multiset.ts +1 -4
- package/src/data-structures/diagrams/README.md +7 -0
- package/src/data-structures/graph/abstract-graph.ts +58 -94
- package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.png +0 -0
- package/src/data-structures/graph/diagrams/adjacency-list.png +0 -0
- package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.png +0 -0
- package/src/data-structures/graph/diagrams/adjacency-matrix.png +0 -0
- package/src/data-structures/graph/diagrams/dfs-can-do.png +0 -0
- package/src/data-structures/graph/diagrams/edge-list-pros-cons.png +0 -0
- package/src/data-structures/graph/diagrams/edge-list.png +0 -0
- package/src/data-structures/graph/diagrams/max-flow.png +0 -0
- package/src/data-structures/graph/diagrams/mst.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
- package/src/data-structures/graph/directed-graph.ts +12 -28
- package/src/data-structures/graph/undirected-graph.ts +11 -10
- package/src/data-structures/hash/coordinate-map.ts +1 -1
- package/src/data-structures/hash/index.ts +5 -0
- package/src/data-structures/heap/heap.ts +2 -11
- package/src/data-structures/heap/max-heap.ts +3 -2
- package/src/data-structures/heap/min-heap.ts +3 -2
- package/src/data-structures/index.ts +1 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +1 -9
- package/src/data-structures/linked-list/singly-linked-list.ts +18 -32
- package/src/data-structures/matrix/matrix2d.ts +11 -11
- package/src/data-structures/matrix/navigator.ts +2 -14
- package/src/data-structures/matrix/vector2d.ts +52 -52
- package/src/data-structures/priority-queue/max-priority-queue.ts +4 -3
- package/src/data-structures/priority-queue/min-priority-queue.ts +4 -3
- package/src/data-structures/priority-queue/priority-queue.ts +70 -78
- package/src/data-structures/queue/deque.ts +2 -2
- package/src/data-structures/queue/queue.ts +12 -13
- package/src/data-structures/stack/stack.ts +12 -13
- package/src/data-structures/trampoline.ts +31 -71
- package/src/data-structures/trie/trie.ts +61 -11
- package/src/data-structures/types/abstract-graph.ts +51 -0
- package/src/data-structures/types/avl-tree.ts +6 -0
- package/src/data-structures/types/binary-tree.ts +15 -0
- package/src/data-structures/types/bst.ts +5 -0
- package/src/data-structures/types/directed-graph.ts +18 -0
- package/src/data-structures/types/doubly-linked-list.ts +1 -0
- package/src/data-structures/types/heap.ts +8 -0
- package/src/data-structures/types/index.ts +13 -0
- package/src/data-structures/types/navigator.ts +12 -0
- package/src/data-structures/types/priority-queue.ts +9 -0
- package/src/data-structures/types/segment-tree.ts +1 -0
- package/src/data-structures/types/singly-linked-list.ts +15 -0
- package/src/data-structures/types/tree-multiset.ts +3 -0
- package/src/{types → data-structures/types}/utils.ts +20 -5
- package/src/utils/index.ts +1 -0
- package/src/{utils.ts → utils/utils.ts} +32 -132
- package/tsconfig.json +9 -6
- package/dist/types/data-structures/binary-tree/aa-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -21
- package/dist/types/data-structures/binary-tree/b-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -8
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -140
- package/dist/types/data-structures/binary-tree/bst.d.ts +0 -32
- package/dist/types/data-structures/binary-tree/index.d.ts +0 -4
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +0 -33
- package/dist/types/data-structures/binary-tree/splay-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +0 -11
- package/dist/types/data-structures/binary-tree/two-three-tree.d.ts +0 -2
- package/dist/types/data-structures/graph/abstract-graph.d.ts +0 -126
- package/dist/types/data-structures/graph/directed-graph.d.ts +0 -51
- package/dist/types/data-structures/graph/index.d.ts +0 -3
- package/dist/types/data-structures/graph/undirected-graph.d.ts +0 -24
- package/dist/types/data-structures/hash/coordinate-map.d.ts +0 -8
- package/dist/types/data-structures/hash/coordinate-set.d.ts +0 -7
- package/dist/types/data-structures/hash/hash-table.d.ts +0 -1
- package/dist/types/data-structures/hash/index.d.ts +0 -1
- package/dist/types/data-structures/hash/pair.d.ts +0 -1
- package/dist/types/data-structures/hash/tree-map.d.ts +0 -1
- package/dist/types/data-structures/hash/tree-set.d.ts +0 -1
- package/dist/types/data-structures/heap/heap.d.ts +0 -72
- package/dist/types/data-structures/heap/index.d.ts +0 -3
- package/dist/types/data-structures/heap/max-heap.d.ts +0 -14
- package/dist/types/data-structures/heap/min-heap.d.ts +0 -14
- package/dist/types/data-structures/index.d.ts +0 -9
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -59
- package/dist/types/data-structures/linked-list/index.d.ts +0 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +0 -358
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +0 -1
- package/dist/types/data-structures/matrix/index.d.ts +0 -3
- package/dist/types/data-structures/matrix/matrix.d.ts +0 -9
- package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -25
- package/dist/types/data-structures/matrix/navigator.d.ts +0 -31
- package/dist/types/data-structures/matrix/vector2d.d.ts +0 -74
- package/dist/types/data-structures/priority-queue/index.d.ts +0 -3
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -4
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -4
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +0 -36
- package/dist/types/data-structures/queue/deque.d.ts +0 -37
- package/dist/types/data-structures/queue/index.d.ts +0 -1
- package/dist/types/data-structures/queue/queue.d.ts +0 -76
- package/dist/types/data-structures/stack/index.d.ts +0 -1
- package/dist/types/data-structures/stack/stack.d.ts +0 -69
- package/dist/types/data-structures/trampoline.d.ts +0 -25
- package/dist/types/data-structures/trie/index.d.ts +0 -1
- package/dist/types/data-structures/trie/trie.d.ts +0 -28
- package/dist/types/types/index.d.ts +0 -1
- package/dist/types/types/utils.d.ts +0 -46
- package/dist/utils.js +0 -569
- package/src/types/index.ts +0 -1
- package/src/types/patches/index.d.ts +0 -0
- /package/dist/{types → utils}/index.d.ts +0 -0
- /package/dist/{types → utils}/index.js +0 -0
package/.idea/modules.xml
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<project version="4">
|
|
3
3
|
<component name="ProjectModuleManager">
|
|
4
4
|
<modules>
|
|
5
|
-
<module fileurl="file://$PROJECT_DIR$/.idea/data-structure-
|
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/data-structure-typed.iml" filepath="$PROJECT_DIR$/.idea/data-structure-typed.iml" />
|
|
6
6
|
</modules>
|
|
7
7
|
</component>
|
|
8
8
|
</project>
|
package/README.md
CHANGED
|
@@ -1,2 +1,197 @@
|
|
|
1
|
-
# data-structure-
|
|
2
|
-
|
|
1
|
+
# data-structure-typed
|
|
2
|
+
|
|
3
|
+
## install
|
|
4
|
+
|
|
5
|
+
### yarn
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
yarn add data-structure-typed
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### npm
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install data-structure-typed
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## data structures
|
|
18
|
+
|
|
19
|
+
<table>
|
|
20
|
+
<thead>
|
|
21
|
+
<tr>
|
|
22
|
+
<th>Data Structure</th>
|
|
23
|
+
<th>Derived</th>
|
|
24
|
+
<th>Basic Features</th>
|
|
25
|
+
<th>Additional Features</th>
|
|
26
|
+
</tr>
|
|
27
|
+
</thead>
|
|
28
|
+
|
|
29
|
+
<tbody>
|
|
30
|
+
<tr>
|
|
31
|
+
<td>Binary Tree</td>
|
|
32
|
+
<td>AVL Tree, Binary Search Tree, Tree Multiset</td>
|
|
33
|
+
<td>put, has, get, remove, size, insertTo, insertMany, fill, getDepth, getHeight, getMinHeight, getPathToRoot, isBalanced </td>
|
|
34
|
+
<td>getLeftMost, isBST, getSubTreeSizeAndCount, subTreeSum, subTreeAdd, BFS, DFS, DFSIterative, levelIterative, listLevels, getPredecessor, morris, </td>
|
|
35
|
+
</tr>
|
|
36
|
+
|
|
37
|
+
<tr>
|
|
38
|
+
<td>AVL Tree</td>
|
|
39
|
+
<td></td>
|
|
40
|
+
<td>All the features inherited from Binary Tree, balanceFactor, updateHeight, balancePath, balanceLL, balanceLR, balanceRR, balanceRL</td>
|
|
41
|
+
<td></td>
|
|
42
|
+
</tr>
|
|
43
|
+
|
|
44
|
+
<tr>
|
|
45
|
+
<td>Binary Search Tree (BST)</td>
|
|
46
|
+
<td></td>
|
|
47
|
+
<td>All the features inherited from Binary Tree, lastKey</td>
|
|
48
|
+
<td>All the features inherited from Binary Tree, lesserSum, allGreaterNodesAdd, balance, isAVLBalanced</td>
|
|
49
|
+
</tr>
|
|
50
|
+
|
|
51
|
+
<tr>
|
|
52
|
+
<td>Tree Multiset</td>
|
|
53
|
+
<td></td>
|
|
54
|
+
<td>All the features inherited from Binary Tree</td>
|
|
55
|
+
<td>All the features inherited from Binary Tree</td>
|
|
56
|
+
</tr>
|
|
57
|
+
|
|
58
|
+
<tr>
|
|
59
|
+
<td>Segment Tree</td>
|
|
60
|
+
<td></td>
|
|
61
|
+
<td>build, updateNode, querySumByRange</td>
|
|
62
|
+
<td></td>
|
|
63
|
+
</tr>
|
|
64
|
+
|
|
65
|
+
<tr>
|
|
66
|
+
<td>Binary Indexed Tree</td>
|
|
67
|
+
<td></td>
|
|
68
|
+
<td>update, getPrefixSum, getRangeSum, BinaryIndexedTree.lowBit</td>
|
|
69
|
+
<td></td>
|
|
70
|
+
</tr>
|
|
71
|
+
<tr>
|
|
72
|
+
<td>Graph</td>
|
|
73
|
+
<td>Directed Graph, Undirected Graph</td>
|
|
74
|
+
<td>getVertex, getVertexId, containsVertex, vertexSet, addVertex, removeVertex, removeAllVertices, containsEdge, setEdgeWeight, getAllPathsBetween, getPathSumWeight, getMinCostBetween, getMinPathBetween, </td>
|
|
75
|
+
<td>dijkstra, dijkstraWithoutHeap, bellmanFord, floyd, tarjan</td>
|
|
76
|
+
</tr>
|
|
77
|
+
<tr>
|
|
78
|
+
<td>Directed Graph</td>
|
|
79
|
+
<td></td>
|
|
80
|
+
<td>All the features inherited from Graph, getEdge, addEdge, removeEdgeBetween, removeEdge, removeAllEdges, incomingEdgesOf, outgoingEdgesOf, degreeOf, inDegreeOf, outDegreeOf, edgesOf, getEdgeSrc, getEdgeDest, getDestinations, edgeSet, getNeighbors, getEndsOfEdge</td>
|
|
81
|
+
<td>All the features inherited from Graph, topologicalSort</td>
|
|
82
|
+
</tr>
|
|
83
|
+
<tr>
|
|
84
|
+
<td>Undirected Graph</td>
|
|
85
|
+
<td></td>
|
|
86
|
+
<td>All the features inherited from Graph, getEdge, addEdge, removeEdgeBetween, removeEdge, degreeOf, edgesOf, edgeSet, getEdgesOf, getNeighbors, getEndsOfEdge</td>
|
|
87
|
+
<td>All the features inherited from Graph</td>
|
|
88
|
+
</tr>
|
|
89
|
+
<tr>
|
|
90
|
+
<td>Singly Linked List</td>
|
|
91
|
+
<td></td>
|
|
92
|
+
<td>length, head, tail, size, get, getNode, findNodeIndex, findNode, find, findIndex, append, push, prepend, insertAt, removeNode, removeAt, insertBefore, sort, insertAfter, shift, pop, merge, clear, slice, reverse, forEach, map, filter, reduce, toArray, toString</td>
|
|
93
|
+
<td></td>
|
|
94
|
+
|
|
95
|
+
</tr>
|
|
96
|
+
<tr>
|
|
97
|
+
<td>Hash</td>
|
|
98
|
+
<td>CoordinateSet, CoordinateMap</td>
|
|
99
|
+
<td></td>
|
|
100
|
+
<td></td>
|
|
101
|
+
</tr>
|
|
102
|
+
<tr>
|
|
103
|
+
<td>CoordinateSet</td>
|
|
104
|
+
<td></td>
|
|
105
|
+
<td>has, set, get, delete</td>
|
|
106
|
+
<td></td>
|
|
107
|
+
</tr>
|
|
108
|
+
<tr>
|
|
109
|
+
<td>CoordinateMap</td>
|
|
110
|
+
<td></td>
|
|
111
|
+
<td>has, add, delete</td>
|
|
112
|
+
<td></td>
|
|
113
|
+
</tr>
|
|
114
|
+
<tr>
|
|
115
|
+
<td>Heap</td>
|
|
116
|
+
<td></td>
|
|
117
|
+
<td></td>
|
|
118
|
+
</tr>
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
<tr>
|
|
122
|
+
<td>Doubly Linked List</td>
|
|
123
|
+
<td></td>
|
|
124
|
+
<td>size, offerFirst, offerLast, peekFirst, peekLast, pollFirst, pollLast, get, isEmpty, insert, remove, </td>
|
|
125
|
+
<td></td>
|
|
126
|
+
</tr>
|
|
127
|
+
|
|
128
|
+
[//]: # ( <tr>)
|
|
129
|
+
|
|
130
|
+
[//]: # ( <td>Matrix</td>)
|
|
131
|
+
|
|
132
|
+
[//]: # ( <td></td>)
|
|
133
|
+
|
|
134
|
+
[//]: # ( <td></td>)
|
|
135
|
+
|
|
136
|
+
[//]: # ( <td></td>)
|
|
137
|
+
|
|
138
|
+
[//]: # ( </tr>)
|
|
139
|
+
|
|
140
|
+
<tr>
|
|
141
|
+
<td>Priority Queue</td>
|
|
142
|
+
<td>Max Priority Queue, Min Priority Queue</td>
|
|
143
|
+
<td>offer, peek, poll, leaf, isEmpty, clear, toArray, clone</td>
|
|
144
|
+
<td>isValid, sort, DFS</td>
|
|
145
|
+
</tr>
|
|
146
|
+
<tr>
|
|
147
|
+
<td>Max Priority Queue</td>
|
|
148
|
+
<td></td>
|
|
149
|
+
<td>All the features inherited from Priority Queue</td>
|
|
150
|
+
<td>All the features inherited from Priority Queue</td>
|
|
151
|
+
</tr>
|
|
152
|
+
<tr>
|
|
153
|
+
<td>Min Priority Queue</td>
|
|
154
|
+
<td></td>
|
|
155
|
+
<td>All the features inherited from Priority Queue</td>
|
|
156
|
+
<td>All the features inherited from Priority Queue</td>
|
|
157
|
+
</tr>
|
|
158
|
+
<tr>
|
|
159
|
+
<td>Queue</td>
|
|
160
|
+
<td>Queue, Dequeue</td>
|
|
161
|
+
<td>offer, poll, peek, peekLast, size, isEmpty, toArray, clear, clone, Queue.fromArray</td>
|
|
162
|
+
<td></td>
|
|
163
|
+
</tr>
|
|
164
|
+
<tr>
|
|
165
|
+
<td>ObjectDeque</td>
|
|
166
|
+
<td></td>
|
|
167
|
+
<td>size, offerFirst, offerLast, pollFirst, peekFirst, pollLast, peekLast, get, isEmpty</td>
|
|
168
|
+
<td></td>
|
|
169
|
+
</tr>
|
|
170
|
+
<tr>
|
|
171
|
+
<td>ArrayDeque</td>
|
|
172
|
+
<td></td>
|
|
173
|
+
<td>offerLast, pollLast, pollFirst, offerFirst, peekFirst, peekLast, get, set, insert, remove, isEmpty</td>
|
|
174
|
+
<td></td>
|
|
175
|
+
</tr>
|
|
176
|
+
<tr>
|
|
177
|
+
<td>Stack</td>
|
|
178
|
+
<td></td>
|
|
179
|
+
<td>isEmpty, size, peek, push, pop, toArray, clear, clone, Stack.fromArray</td>
|
|
180
|
+
<td></td>
|
|
181
|
+
</tr>
|
|
182
|
+
<tr>
|
|
183
|
+
<td>Trie</td>
|
|
184
|
+
<td></td>
|
|
185
|
+
<td>put, has, remove, isAbsPrefix, isPrefix, getAll</td>
|
|
186
|
+
<td></td>
|
|
187
|
+
</tr>
|
|
188
|
+
</tbody>
|
|
189
|
+
|
|
190
|
+
</table>
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+

|
|
196
|
+
|
|
197
|
+

|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { BST, BSTNode } from './bst';
|
|
2
|
-
import { BinaryTreeNodeId } from '
|
|
3
|
-
export interface AVLTreeDeleted<T> {
|
|
4
|
-
deleted: AVLTreeNode<T> | null;
|
|
5
|
-
needBalanced: AVLTreeNode<T> | null;
|
|
6
|
-
}
|
|
2
|
+
import type { AVLTreeDeleted, BinaryTreeNodeId } from '../types';
|
|
7
3
|
export declare class AVLTreeNode<T> extends BSTNode<T> {
|
|
8
4
|
clone(): AVLTreeNode<T>;
|
|
9
5
|
}
|
|
@@ -1,57 +1,103 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __values = (this && this.__values) || function(o) {
|
|
18
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
19
|
+
if (m) return m.call(o);
|
|
20
|
+
if (o && typeof o.length === "number") return {
|
|
21
|
+
next: function () {
|
|
22
|
+
if (o && i >= o.length) o = void 0;
|
|
23
|
+
return { value: o && o[i++], done: !o };
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
27
|
+
};
|
|
2
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
29
|
exports.AVLTree = exports.AVLTreeNode = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
30
|
+
var bst_1 = require("./bst");
|
|
31
|
+
var AVLTreeNode = /** @class */ (function (_super) {
|
|
32
|
+
__extends(AVLTreeNode, _super);
|
|
33
|
+
function AVLTreeNode() {
|
|
34
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
8
35
|
}
|
|
9
|
-
|
|
36
|
+
AVLTreeNode.prototype.clone = function () {
|
|
37
|
+
return new AVLTreeNode(this.id, this.val, this.count);
|
|
38
|
+
};
|
|
39
|
+
return AVLTreeNode;
|
|
40
|
+
}(bst_1.BSTNode));
|
|
10
41
|
exports.AVLTreeNode = AVLTreeNode;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
42
|
+
var AVLTree = /** @class */ (function (_super) {
|
|
43
|
+
__extends(AVLTree, _super);
|
|
44
|
+
function AVLTree() {
|
|
45
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
14
46
|
}
|
|
15
|
-
|
|
16
|
-
|
|
47
|
+
AVLTree.prototype.createNode = function (id, val, count) {
|
|
48
|
+
return new AVLTreeNode(id, val, count);
|
|
49
|
+
};
|
|
50
|
+
AVLTree.prototype.put = function (id, val, count) {
|
|
51
|
+
var inserted = _super.prototype.put.call(this, id, val, count);
|
|
17
52
|
if (inserted)
|
|
18
53
|
this.balancePath(inserted);
|
|
19
54
|
return inserted;
|
|
20
|
-
}
|
|
21
|
-
remove(id, isUpdateAllLeftSum) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
55
|
+
};
|
|
56
|
+
AVLTree.prototype.remove = function (id, isUpdateAllLeftSum) {
|
|
57
|
+
var e_1, _a;
|
|
58
|
+
var deletedResults = _super.prototype.remove.call(this, id, isUpdateAllLeftSum);
|
|
59
|
+
try {
|
|
60
|
+
for (var deletedResults_1 = __values(deletedResults), deletedResults_1_1 = deletedResults_1.next(); !deletedResults_1_1.done; deletedResults_1_1 = deletedResults_1.next()) {
|
|
61
|
+
var needBalanced = deletedResults_1_1.value.needBalanced;
|
|
62
|
+
if (needBalanced) {
|
|
63
|
+
this.balancePath(needBalanced);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
68
|
+
finally {
|
|
69
|
+
try {
|
|
70
|
+
if (deletedResults_1_1 && !deletedResults_1_1.done && (_a = deletedResults_1.return)) _a.call(deletedResults_1);
|
|
26
71
|
}
|
|
72
|
+
finally { if (e_1) throw e_1.error; }
|
|
27
73
|
}
|
|
28
74
|
return deletedResults;
|
|
29
|
-
}
|
|
30
|
-
balanceFactor(node) {
|
|
75
|
+
};
|
|
76
|
+
AVLTree.prototype.balanceFactor = function (node) {
|
|
31
77
|
if (!node.right) // node has no right subtree
|
|
32
78
|
return -node.height;
|
|
33
79
|
else if (!node.left) // node has no left subtree
|
|
34
80
|
return +node.height;
|
|
35
81
|
else
|
|
36
82
|
return node.right.height - node.left.height;
|
|
37
|
-
}
|
|
38
|
-
updateHeight(node) {
|
|
83
|
+
};
|
|
84
|
+
AVLTree.prototype.updateHeight = function (node) {
|
|
39
85
|
if (!node.left && !node.right) // node is a leaf
|
|
40
86
|
node.height = 0;
|
|
41
87
|
else if (!node.left) {
|
|
42
88
|
// node has no left subtree
|
|
43
|
-
|
|
89
|
+
var rightHeight = node.right ? node.right.height : 0;
|
|
44
90
|
node.height = 1 + rightHeight;
|
|
45
91
|
}
|
|
46
92
|
else if (!node.right) // node has no right subtree
|
|
47
93
|
node.height = 1 + node.left.height;
|
|
48
94
|
else
|
|
49
95
|
node.height = 1 + Math.max(node.right.height, node.left.height);
|
|
50
|
-
}
|
|
51
|
-
balancePath(node) {
|
|
52
|
-
|
|
53
|
-
for (
|
|
54
|
-
|
|
96
|
+
};
|
|
97
|
+
AVLTree.prototype.balancePath = function (node) {
|
|
98
|
+
var path = this.getPathToRoot(node);
|
|
99
|
+
for (var i = path.length - 1; i >= 0; i--) {
|
|
100
|
+
var A = path[i];
|
|
55
101
|
this.updateHeight(A);
|
|
56
102
|
switch (this.balanceFactor(A)) {
|
|
57
103
|
case -2:
|
|
@@ -75,10 +121,10 @@ class AVLTree extends bst_1.BST {
|
|
|
75
121
|
}
|
|
76
122
|
}
|
|
77
123
|
}
|
|
78
|
-
}
|
|
79
|
-
balanceLL(A) {
|
|
80
|
-
|
|
81
|
-
|
|
124
|
+
};
|
|
125
|
+
AVLTree.prototype.balanceLL = function (A) {
|
|
126
|
+
var parentOfA = A.parent;
|
|
127
|
+
var B = A.left; // A is left-heavy and B is left-heavy
|
|
82
128
|
A.parent = B;
|
|
83
129
|
if (B && B.right) {
|
|
84
130
|
B.right.parent = A;
|
|
@@ -105,11 +151,11 @@ class AVLTree extends bst_1.BST {
|
|
|
105
151
|
this.updateHeight(A);
|
|
106
152
|
if (B)
|
|
107
153
|
this.updateHeight(B);
|
|
108
|
-
}
|
|
109
|
-
balanceLR(A) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
154
|
+
};
|
|
155
|
+
AVLTree.prototype.balanceLR = function (A) {
|
|
156
|
+
var parentOfA = A.parent;
|
|
157
|
+
var B = A.left; // A is left-heavy
|
|
158
|
+
var C = null;
|
|
113
159
|
if (B) {
|
|
114
160
|
C = B.right; // B is right-heavy
|
|
115
161
|
}
|
|
@@ -150,10 +196,10 @@ class AVLTree extends bst_1.BST {
|
|
|
150
196
|
this.updateHeight(A); // Adjust heights
|
|
151
197
|
B && this.updateHeight(B);
|
|
152
198
|
C && this.updateHeight(C);
|
|
153
|
-
}
|
|
154
|
-
balanceRR(A) {
|
|
155
|
-
|
|
156
|
-
|
|
199
|
+
};
|
|
200
|
+
AVLTree.prototype.balanceRR = function (A) {
|
|
201
|
+
var parentOfA = A.parent;
|
|
202
|
+
var B = A.right; // A is right-heavy and B is right-heavy
|
|
157
203
|
A.parent = B;
|
|
158
204
|
if (B) {
|
|
159
205
|
if (B.left) {
|
|
@@ -181,11 +227,11 @@ class AVLTree extends bst_1.BST {
|
|
|
181
227
|
}
|
|
182
228
|
this.updateHeight(A);
|
|
183
229
|
B && this.updateHeight(B);
|
|
184
|
-
}
|
|
185
|
-
balanceRL(A) {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
230
|
+
};
|
|
231
|
+
AVLTree.prototype.balanceRL = function (A) {
|
|
232
|
+
var parentOfA = A.parent;
|
|
233
|
+
var B = A.right; // A is right-heavy
|
|
234
|
+
var C = null;
|
|
189
235
|
if (B) {
|
|
190
236
|
C = B.left; // B is left-heavy
|
|
191
237
|
}
|
|
@@ -226,6 +272,7 @@ class AVLTree extends bst_1.BST {
|
|
|
226
272
|
this.updateHeight(A); // Adjust heights
|
|
227
273
|
B && this.updateHeight(B);
|
|
228
274
|
C && this.updateHeight(C);
|
|
229
|
-
}
|
|
230
|
-
|
|
275
|
+
};
|
|
276
|
+
return AVLTree;
|
|
277
|
+
}(bst_1.BST));
|
|
231
278
|
exports.AVLTree = AVLTree;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export declare class BinaryIndexedTree {
|
|
2
2
|
private readonly _sumTree;
|
|
3
3
|
constructor(n: number);
|
|
4
|
+
static lowBit(x: number): number;
|
|
4
5
|
update(i: number, delta: number): void;
|
|
5
6
|
getPrefixSum(i: number): number;
|
|
6
7
|
getRangeSum(start: number, end: number): number;
|
|
7
|
-
static lowBit(x: number): number;
|
|
8
8
|
}
|
|
@@ -1,31 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BinaryIndexedTree = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
var BinaryIndexedTree = /** @class */ (function () {
|
|
5
|
+
function BinaryIndexedTree(n) {
|
|
6
6
|
this._sumTree = new Array(n + 1).fill(0);
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
BinaryIndexedTree.lowBit = function (x) {
|
|
9
|
+
return x & (-x);
|
|
10
|
+
};
|
|
11
|
+
BinaryIndexedTree.prototype.update = function (i, delta) {
|
|
9
12
|
while (i < this._sumTree.length) {
|
|
10
13
|
this._sumTree[i] += delta;
|
|
11
14
|
i += BinaryIndexedTree.lowBit(i);
|
|
12
15
|
}
|
|
13
|
-
}
|
|
14
|
-
getPrefixSum(i) {
|
|
15
|
-
|
|
16
|
+
};
|
|
17
|
+
BinaryIndexedTree.prototype.getPrefixSum = function (i) {
|
|
18
|
+
var sum = 0;
|
|
16
19
|
while (i > 0) {
|
|
17
20
|
sum += this._sumTree[i];
|
|
18
21
|
i -= BinaryIndexedTree.lowBit(i);
|
|
19
22
|
}
|
|
20
23
|
return sum;
|
|
21
|
-
}
|
|
22
|
-
getRangeSum(start, end) {
|
|
24
|
+
};
|
|
25
|
+
BinaryIndexedTree.prototype.getRangeSum = function (start, end) {
|
|
23
26
|
if (!(0 <= start && start <= end && end <= this._sumTree.length))
|
|
24
27
|
throw 'Index out of bounds';
|
|
25
28
|
return this.getPrefixSum(end) - this.getPrefixSum(start);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
}
|
|
29
|
+
};
|
|
30
|
+
return BinaryIndexedTree;
|
|
31
|
+
}());
|
|
31
32
|
exports.BinaryIndexedTree = BinaryIndexedTree;
|
|
@@ -1,18 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export type NodeOrPropertyName = 'node' | BinaryTreeNodePropertyName;
|
|
3
|
-
export type DFSOrderPattern = 'in' | 'pre' | 'post';
|
|
4
|
-
export type BinaryTreeNodeId = number;
|
|
5
|
-
export type BinaryTreeDeleted<T> = {
|
|
6
|
-
deleted: BinaryTreeNode<T> | null | undefined;
|
|
7
|
-
needBalanced: BinaryTreeNode<T> | null;
|
|
8
|
-
};
|
|
9
|
-
export type ResultByProperty<T> = T | BinaryTreeNode<T> | number | BinaryTreeNodeId;
|
|
10
|
-
export type ResultsByProperty<T> = ResultByProperty<T>[];
|
|
11
|
-
export interface BinaryTreeNodeObj<T> {
|
|
12
|
-
id: BinaryTreeNodeId;
|
|
13
|
-
val: T;
|
|
14
|
-
count?: number;
|
|
15
|
-
}
|
|
1
|
+
import type { BinaryTreeDeleted, BinaryTreeNodeId, BinaryTreeNodePropertyName, DFSOrderPattern, NodeOrPropertyName, ResultsByProperty } from '../types';
|
|
16
2
|
export declare enum FamilyPosition {
|
|
17
3
|
root = 0,
|
|
18
4
|
left = 1,
|
|
@@ -23,6 +9,7 @@ export declare enum LoopType {
|
|
|
23
9
|
recursive = 2
|
|
24
10
|
}
|
|
25
11
|
export declare class BinaryTreeNode<T> {
|
|
12
|
+
constructor(id: BinaryTreeNodeId, val: T, count?: number);
|
|
26
13
|
protected _id: BinaryTreeNodeId;
|
|
27
14
|
get id(): BinaryTreeNodeId;
|
|
28
15
|
set id(v: BinaryTreeNodeId);
|
|
@@ -47,35 +34,34 @@ export declare class BinaryTreeNode<T> {
|
|
|
47
34
|
protected _height: number;
|
|
48
35
|
get height(): number;
|
|
49
36
|
set height(v: number);
|
|
50
|
-
constructor(id: BinaryTreeNodeId, val: T, count?: number);
|
|
51
37
|
swapLocation(swapNode: BinaryTreeNode<T>): BinaryTreeNode<T>;
|
|
52
38
|
clone(): BinaryTreeNode<T>;
|
|
53
39
|
}
|
|
54
40
|
export declare class BinaryTree<T> {
|
|
55
|
-
protected _root: BinaryTreeNode<T> | null;
|
|
56
|
-
get root(): BinaryTreeNode<T> | null;
|
|
57
|
-
protected set root(v: BinaryTreeNode<T> | null);
|
|
58
|
-
protected _size: number;
|
|
59
|
-
get size(): number;
|
|
60
|
-
protected set size(v: number);
|
|
61
|
-
protected _count: number;
|
|
62
|
-
get count(): number;
|
|
63
|
-
protected set count(v: number);
|
|
64
|
-
private readonly _autoIncrementId;
|
|
65
|
-
private _maxId;
|
|
66
|
-
private readonly _isDuplicatedVal;
|
|
67
41
|
protected _loopType: LoopType;
|
|
68
42
|
protected _visitedId: BinaryTreeNodeId[];
|
|
69
43
|
protected _visitedVal: Array<T>;
|
|
70
44
|
protected _visitedNode: BinaryTreeNode<T>[];
|
|
71
45
|
protected _visitedCount: number[];
|
|
72
46
|
protected _visitedLeftSum: number[];
|
|
73
|
-
|
|
47
|
+
private readonly _autoIncrementId;
|
|
48
|
+
private _maxId;
|
|
49
|
+
private readonly _isDuplicatedVal;
|
|
74
50
|
constructor(options?: {
|
|
75
51
|
loopType?: LoopType;
|
|
76
52
|
autoIncrementId?: boolean;
|
|
77
53
|
isDuplicatedVal?: boolean;
|
|
78
54
|
});
|
|
55
|
+
protected _root: BinaryTreeNode<T> | null;
|
|
56
|
+
protected get root(): BinaryTreeNode<T> | null;
|
|
57
|
+
protected set root(v: BinaryTreeNode<T> | null);
|
|
58
|
+
protected _size: number;
|
|
59
|
+
protected get size(): number;
|
|
60
|
+
protected set size(v: number);
|
|
61
|
+
protected _count: number;
|
|
62
|
+
protected get count(): number;
|
|
63
|
+
protected set count(v: number);
|
|
64
|
+
getCount(): number;
|
|
79
65
|
createNode(id: BinaryTreeNodeId, val: T | null, count?: number): BinaryTreeNode<T> | null;
|
|
80
66
|
clear(): void;
|
|
81
67
|
isEmpty(): boolean;
|
|
@@ -95,9 +81,7 @@ export declare class BinaryTree<T> {
|
|
|
95
81
|
has(nodeProperty: BinaryTreeNodeId | T, propertyName?: BinaryTreeNodePropertyName): boolean;
|
|
96
82
|
get(nodeProperty: BinaryTreeNodeId | T, propertyName?: BinaryTreeNodePropertyName): BinaryTreeNode<T> | null;
|
|
97
83
|
getPathToRoot(node: BinaryTreeNode<T>): BinaryTreeNode<T>[];
|
|
98
|
-
|
|
99
|
-
protected _accumulatedByPropertyName(node: BinaryTreeNode<T>, nodeOrPropertyName?: NodeOrPropertyName): void;
|
|
100
|
-
protected _getResultByPropertyName(nodeOrPropertyName?: NodeOrPropertyName): ResultsByProperty<T>;
|
|
84
|
+
getRoot(): BinaryTreeNode<T> | null;
|
|
101
85
|
getLeftMost(): BinaryTreeNode<T> | null;
|
|
102
86
|
getLeftMost(node: BinaryTreeNode<T>): BinaryTreeNode<T>;
|
|
103
87
|
getRightMost(): BinaryTreeNode<T> | null;
|
|
@@ -137,4 +121,8 @@ export declare class BinaryTree<T> {
|
|
|
137
121
|
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): T[];
|
|
138
122
|
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): BinaryTreeNode<T>[];
|
|
139
123
|
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
|
|
124
|
+
protected _resetResults(): void;
|
|
125
|
+
protected _pushByPropertyNameStopOrNot(cur: BinaryTreeNode<T>, result: (BinaryTreeNode<T> | null | undefined)[], nodeProperty: BinaryTreeNodeId | T, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): boolean | undefined;
|
|
126
|
+
protected _accumulatedByPropertyName(node: BinaryTreeNode<T>, nodeOrPropertyName?: NodeOrPropertyName): void;
|
|
127
|
+
protected _getResultByPropertyName(nodeOrPropertyName?: NodeOrPropertyName): ResultsByProperty<T>;
|
|
140
128
|
}
|