data-structure-typed 1.15.1 → 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 (224) hide show
  1. package/README.md +398 -27
  2. package/dist/data-structures/binary-tree/binary-tree.d.ts +30 -30
  3. package/dist/data-structures/binary-tree/binary-tree.js +55 -55
  4. package/dist/data-structures/binary-tree/segment-tree.d.ts +17 -17
  5. package/dist/data-structures/binary-tree/segment-tree.js +30 -30
  6. package/dist/data-structures/graph/abstract-graph.d.ts +6 -6
  7. package/dist/data-structures/graph/abstract-graph.js +6 -6
  8. package/dist/data-structures/graph/directed-graph.d.ts +4 -4
  9. package/dist/data-structures/graph/directed-graph.js +6 -6
  10. package/dist/data-structures/graph/undirected-graph.d.ts +3 -3
  11. package/dist/data-structures/hash/coordinate-map.d.ts +2 -2
  12. package/dist/data-structures/hash/coordinate-set.d.ts +2 -2
  13. package/dist/data-structures/heap/heap.d.ts +40 -25
  14. package/dist/data-structures/heap/heap.js +72 -27
  15. package/dist/data-structures/heap/max-heap.d.ts +3 -3
  16. package/dist/data-structures/heap/min-heap.d.ts +3 -3
  17. package/dist/data-structures/index.d.ts +1 -0
  18. package/dist/data-structures/index.js +1 -0
  19. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +9 -9
  20. package/dist/data-structures/linked-list/doubly-linked-list.js +12 -12
  21. package/dist/data-structures/linked-list/singly-linked-list.d.ts +7 -7
  22. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +4 -5
  23. package/dist/data-structures/priority-queue/max-priority-queue.js +30 -6
  24. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +4 -5
  25. package/dist/data-structures/priority-queue/min-priority-queue.js +31 -6
  26. package/dist/data-structures/priority-queue/priority-queue.d.ts +20 -9
  27. package/dist/data-structures/priority-queue/priority-queue.js +34 -28
  28. package/dist/data-structures/queue/deque.d.ts +1 -1
  29. package/dist/data-structures/tree/index.d.ts +1 -0
  30. package/dist/data-structures/tree/index.js +17 -0
  31. package/dist/data-structures/tree/tree.d.ts +9 -0
  32. package/dist/data-structures/tree/tree.js +52 -0
  33. package/dist/data-structures/types/heap.d.ts +0 -4
  34. package/dist/utils/types/utils.d.ts +1 -3
  35. package/dist/utils/types/utils.js +0 -14
  36. package/dist/utils/utils.js +0 -197
  37. package/docs/.nojekyll +1 -0
  38. package/docs/assets/highlight.css +92 -0
  39. package/docs/assets/main.js +58 -0
  40. package/docs/assets/search.js +1 -0
  41. package/docs/assets/style.css +1367 -0
  42. package/docs/classes/AVLTree.html +2192 -0
  43. package/docs/classes/AVLTreeNode.html +574 -0
  44. package/docs/classes/AaTree.html +150 -0
  45. package/docs/classes/AbstractEdge.html +269 -0
  46. package/docs/classes/AbstractGraph.html +927 -0
  47. package/docs/classes/AbstractVertex.html +215 -0
  48. package/docs/classes/ArrayDeque.html +417 -0
  49. package/docs/classes/BST.html +2038 -0
  50. package/docs/classes/BSTNode.html +570 -0
  51. package/docs/classes/BTree.html +150 -0
  52. package/docs/classes/BinaryIndexedTree.html +289 -0
  53. package/docs/classes/BinaryTree.html +1827 -0
  54. package/docs/classes/BinaryTreeNode.html +533 -0
  55. package/docs/classes/Character.html +198 -0
  56. package/docs/classes/CoordinateMap.html +469 -0
  57. package/docs/classes/CoordinateSet.html +430 -0
  58. package/docs/classes/Deque.html +767 -0
  59. package/docs/classes/DirectedEdge.html +354 -0
  60. package/docs/classes/DirectedGraph.html +1243 -0
  61. package/docs/classes/DirectedVertex.html +226 -0
  62. package/docs/classes/DoublyLinkedList.html +733 -0
  63. package/docs/classes/DoublyLinkedListNode.html +258 -0
  64. package/docs/classes/Heap.html +482 -0
  65. package/docs/classes/HeapItem.html +233 -0
  66. package/docs/classes/Matrix2D.html +480 -0
  67. package/docs/classes/MatrixNTI2D.html +218 -0
  68. package/docs/classes/MaxHeap.html +500 -0
  69. package/docs/classes/MaxPriorityQueue.html +809 -0
  70. package/docs/classes/MinHeap.html +501 -0
  71. package/docs/classes/MinPriorityQueue.html +811 -0
  72. package/docs/classes/Navigator.html +291 -0
  73. package/docs/classes/ObjectDeque.html +423 -0
  74. package/docs/classes/PriorityQueue.html +733 -0
  75. package/docs/classes/Queue.html +370 -0
  76. package/docs/classes/RBTree.html +150 -0
  77. package/docs/classes/SegmentTree.html +345 -0
  78. package/docs/classes/SegmentTreeNode.html +418 -0
  79. package/docs/classes/SinglyLinkedList.html +1105 -0
  80. package/docs/classes/SinglyLinkedListNode.html +375 -0
  81. package/docs/classes/SplayTree.html +150 -0
  82. package/docs/classes/Stack.html +346 -0
  83. package/docs/classes/TreeMultiSet.html +2036 -0
  84. package/docs/classes/TreeNode.html +236 -0
  85. package/docs/classes/Trie.html +350 -0
  86. package/docs/classes/TrieNode.html +258 -0
  87. package/docs/classes/TwoThreeTree.html +150 -0
  88. package/docs/classes/UndirectedEdge.html +313 -0
  89. package/docs/classes/UndirectedGraph.html +1080 -0
  90. package/docs/classes/UndirectedVertex.html +226 -0
  91. package/docs/classes/Vector2D.html +783 -0
  92. package/docs/enums/CP.html +159 -0
  93. package/docs/enums/FamilyPosition.html +159 -0
  94. package/docs/enums/LoopType.html +160 -0
  95. package/docs/index.html +494 -0
  96. package/docs/interfaces/AVLTreeDeleted.html +161 -0
  97. package/docs/interfaces/BinaryTreeNodeObj.html +168 -0
  98. package/docs/interfaces/HeapOptions.html +167 -0
  99. package/docs/interfaces/IDirectedGraph.html +243 -0
  100. package/docs/interfaces/IGraph.html +427 -0
  101. package/docs/interfaces/NavigatorParams.html +197 -0
  102. package/docs/interfaces/PriorityQueueOptions.html +168 -0
  103. package/docs/modules.html +218 -0
  104. package/docs/types/BSTComparator.html +140 -0
  105. package/docs/types/BSTDeletedResult.html +137 -0
  106. package/docs/types/BinaryTreeDeleted.html +137 -0
  107. package/docs/types/BinaryTreeNodeId.html +125 -0
  108. package/docs/types/BinaryTreeNodePropertyName.html +125 -0
  109. package/docs/types/DFSOrderPattern.html +125 -0
  110. package/docs/types/DijkstraResult.html +145 -0
  111. package/docs/types/Direction.html +125 -0
  112. package/docs/types/DoublyLinkedListGetBy.html +125 -0
  113. package/docs/types/NodeOrPropertyName.html +125 -0
  114. package/docs/types/PriorityQueueComparator.html +145 -0
  115. package/docs/types/PriorityQueueDFSOrderPattern.html +125 -0
  116. package/docs/types/ResultByProperty.html +130 -0
  117. package/docs/types/ResultsByProperty.html +130 -0
  118. package/docs/types/SegmentTreeNodeVal.html +125 -0
  119. package/docs/types/SpecifyOptional.html +132 -0
  120. package/docs/types/Thunk.html +133 -0
  121. package/docs/types/ToThunkFn.html +133 -0
  122. package/docs/types/TopologicalStatus.html +125 -0
  123. package/docs/types/TreeMultiSetDeletedResult.html +137 -0
  124. package/docs/types/TrlAsyncFn.html +138 -0
  125. package/docs/types/TrlFn.html +138 -0
  126. package/docs/types/Turning.html +125 -0
  127. package/docs/types/VertexId.html +125 -0
  128. package/{tests/unit/data-structures/binary-tree → notes}/bst.test.ts +11 -15
  129. package/notes/note.md +23 -0
  130. package/package.json +2 -4
  131. package/.idea/data-structure-typed.iml +0 -14
  132. package/.idea/modules.xml +0 -8
  133. package/.idea/vcs.xml +0 -6
  134. package/src/assets/complexities-diff.jpg +0 -0
  135. package/src/assets/data-structure-complexities.jpg +0 -0
  136. package/src/assets/logo.png +0 -0
  137. package/src/data-structures/binary-tree/aa-tree.ts +0 -3
  138. package/src/data-structures/binary-tree/avl-tree.ts +0 -293
  139. package/src/data-structures/binary-tree/b-tree.ts +0 -3
  140. package/src/data-structures/binary-tree/binary-indexed-tree.ts +0 -69
  141. package/src/data-structures/binary-tree/binary-tree.ts +0 -1485
  142. package/src/data-structures/binary-tree/bst.ts +0 -497
  143. package/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
  144. package/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
  145. package/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
  146. package/src/data-structures/binary-tree/index.ts +0 -11
  147. package/src/data-structures/binary-tree/rb-tree.ts +0 -3
  148. package/src/data-structures/binary-tree/segment-tree.ts +0 -248
  149. package/src/data-structures/binary-tree/splay-tree.ts +0 -3
  150. package/src/data-structures/binary-tree/tree-multiset.ts +0 -53
  151. package/src/data-structures/binary-tree/two-three-tree.ts +0 -3
  152. package/src/data-structures/diagrams/README.md +0 -5
  153. package/src/data-structures/graph/abstract-graph.ts +0 -956
  154. package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
  155. package/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
  156. package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
  157. package/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
  158. package/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
  159. package/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
  160. package/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
  161. package/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
  162. package/src/data-structures/graph/diagrams/mst.jpg +0 -0
  163. package/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
  164. package/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
  165. package/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
  166. package/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
  167. package/src/data-structures/graph/diagrams/tarjan.webp +0 -0
  168. package/src/data-structures/graph/directed-graph.ts +0 -424
  169. package/src/data-structures/graph/index.ts +0 -3
  170. package/src/data-structures/graph/undirected-graph.ts +0 -254
  171. package/src/data-structures/hash/coordinate-map.ts +0 -71
  172. package/src/data-structures/hash/coordinate-set.ts +0 -60
  173. package/src/data-structures/hash/hash-table.ts +0 -1
  174. package/src/data-structures/hash/index.ts +0 -6
  175. package/src/data-structures/hash/pair.ts +0 -1
  176. package/src/data-structures/hash/tree-map.ts +0 -1
  177. package/src/data-structures/hash/tree-set.ts +0 -1
  178. package/src/data-structures/heap/heap.ts +0 -156
  179. package/src/data-structures/heap/index.ts +0 -3
  180. package/src/data-structures/heap/max-heap.ts +0 -31
  181. package/src/data-structures/heap/min-heap.ts +0 -34
  182. package/src/data-structures/index.ts +0 -13
  183. package/src/data-structures/linked-list/doubly-linked-list.ts +0 -351
  184. package/src/data-structures/linked-list/index.ts +0 -2
  185. package/src/data-structures/linked-list/singly-linked-list.ts +0 -748
  186. package/src/data-structures/linked-list/skip-linked-list.ts +0 -1
  187. package/src/data-structures/matrix/index.ts +0 -4
  188. package/src/data-structures/matrix/matrix.ts +0 -27
  189. package/src/data-structures/matrix/matrix2d.ts +0 -208
  190. package/src/data-structures/matrix/navigator.ts +0 -122
  191. package/src/data-structures/matrix/vector2d.ts +0 -316
  192. package/src/data-structures/priority-queue/index.ts +0 -3
  193. package/src/data-structures/priority-queue/max-priority-queue.ts +0 -24
  194. package/src/data-structures/priority-queue/min-priority-queue.ts +0 -24
  195. package/src/data-structures/priority-queue/priority-queue.ts +0 -346
  196. package/src/data-structures/queue/deque.ts +0 -241
  197. package/src/data-structures/queue/index.ts +0 -2
  198. package/src/data-structures/queue/queue.ts +0 -120
  199. package/src/data-structures/stack/index.ts +0 -1
  200. package/src/data-structures/stack/stack.ts +0 -98
  201. package/src/data-structures/trie/index.ts +0 -1
  202. package/src/data-structures/trie/trie.ts +0 -225
  203. package/src/data-structures/types/abstract-graph.ts +0 -51
  204. package/src/data-structures/types/avl-tree.ts +0 -6
  205. package/src/data-structures/types/binary-tree.ts +0 -15
  206. package/src/data-structures/types/bst.ts +0 -5
  207. package/src/data-structures/types/directed-graph.ts +0 -18
  208. package/src/data-structures/types/doubly-linked-list.ts +0 -1
  209. package/src/data-structures/types/heap.ts +0 -8
  210. package/src/data-structures/types/index.ts +0 -13
  211. package/src/data-structures/types/navigator.ts +0 -13
  212. package/src/data-structures/types/priority-queue.ts +0 -9
  213. package/src/data-structures/types/segment-tree.ts +0 -1
  214. package/src/data-structures/types/singly-linked-list.ts +0 -1
  215. package/src/data-structures/types/tree-multiset.ts +0 -3
  216. package/src/index.ts +0 -1
  217. package/src/utils/index.ts +0 -2
  218. package/src/utils/types/index.ts +0 -1
  219. package/src/utils/types/utils.ts +0 -176
  220. package/src/utils/utils.ts +0 -290
  221. package/tests/unit/data-structures/graph/abstract-graph.ts +0 -0
  222. package/tests/unit/data-structures/graph/directed-graph.test.ts +0 -495
  223. package/tests/unit/data-structures/graph/index.ts +0 -3
  224. package/tests/unit/data-structures/graph/undirected-graph.ts +0 -0
@@ -1,248 +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 type {SegmentTreeNodeVal} from '../types';
10
-
11
- export class SegmentTreeNode {
12
- constructor(start: number, end: number, sum: number, val?: SegmentTreeNodeVal | null) {
13
- this._start = start;
14
- this._end = end;
15
- this._sum = sum;
16
- this._val = val || null;
17
- }
18
-
19
- protected _start = 0;
20
- get start(): number {
21
- return this._start;
22
- }
23
- /**
24
- * 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.
25
- */
26
- getStart(): number {
27
- return this._start;
28
- }
29
- set start(v: number) {
30
- this._start = v;
31
- }
32
-
33
- protected _end = 0;
34
- get end(): number {
35
- return this._end;
36
- }
37
- /**
38
- * 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.
39
- */
40
- getEnd(): number {
41
- return this._end;
42
- }
43
- set end(v: number) {
44
- this._end = v;
45
- }
46
-
47
- protected _val: SegmentTreeNodeVal | null = null;
48
- get val(): SegmentTreeNodeVal | null {
49
- return this._val;
50
- }
51
- /**
52
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
53
- */
54
- getVal(): SegmentTreeNodeVal | null {
55
- return this._val;
56
- }
57
- set val(v: SegmentTreeNodeVal | null) {
58
- this._val = v;
59
- }
60
-
61
- protected _sum = 0;
62
- get sum(): number {
63
- return this._sum;
64
- }
65
- /**
66
- * 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.
67
- */
68
- getSum(): number {
69
- return this._sum;
70
- }
71
- set sum(v: number) {
72
- this._sum = v;
73
- }
74
-
75
- protected _left: SegmentTreeNode | null = null;
76
- get left(): SegmentTreeNode | null {
77
- return this._left;
78
- }
79
- /**
80
- * 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.
81
- */
82
- getLeft(): SegmentTreeNode | null {
83
- return this._left;
84
- }
85
- set left(v: SegmentTreeNode | null) {
86
- this._left = v;
87
- }
88
-
89
- protected _right: SegmentTreeNode | null = null;
90
- get right(): SegmentTreeNode | null {
91
- return this._right;
92
- }
93
- /**
94
- * 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.
95
- */
96
- getRight(): SegmentTreeNode | null {
97
- return this._right;
98
- }
99
- set right(v: SegmentTreeNode | null) {
100
- this._right = v;
101
- }
102
- }
103
-
104
- export class SegmentTree {
105
- protected _values: number[] = [];
106
- protected _start = 0;
107
- protected _end: number;
108
-
109
- /**
110
- * The constructor initializes the values, start, end, and root properties of an object.
111
- * @param {number[]} values - An array of numbers that will be used to build a binary search tree.
112
- * @param {number} [start] - The `start` parameter is the index of the first element in the `values` array that should
113
- * be included in the range. If no value is provided for `start`, it defaults to 0, which means the range starts from
114
- * the beginning of the array.
115
- * @param {number} [end] - The "end" parameter is the index of the last element in the "values" array that should be
116
- * included in the range. If not provided, it defaults to the index of the last element in the "values" array.
117
- */
118
- constructor(values: number[], start?: number, end?: number) {
119
- start = start || 0;
120
- end = end || values.length - 1;
121
- this._values = values;
122
- this._start = start;
123
- this._end = end;
124
- this._root = this.build(start, end);
125
- }
126
-
127
- protected _root: SegmentTreeNode | null;
128
- get root(): SegmentTreeNode | null {
129
- return this._root;
130
- }
131
- /**
132
- * 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.
133
- */
134
- getRoot(): SegmentTreeNode | null {
135
- return this._root;
136
- }
137
- set root(v: SegmentTreeNode | null) {
138
- this._root = v;
139
- }
140
-
141
- /**
142
- * The function builds a segment tree by recursively dividing the given range into smaller segments and creating nodes
143
- * for each segment.
144
- * @param {number} start - The `start` parameter represents the starting index of the segment or range for which we are
145
- * building the segment tree.
146
- * @param {number} end - The `end` parameter represents the ending index of the segment or range for which we are
147
- * building the segment tree.
148
- * @returns a SegmentTreeNode object.
149
- */
150
- build(start: number, end: number): SegmentTreeNode {
151
- if (start === end) {
152
- return new SegmentTreeNode(start, end, this._values[start]);
153
- }
154
- const mid = start + Math.floor((end - start) / 2);
155
- const left = this.build(start, mid);
156
- const right = this.build(mid + 1, end);
157
- const cur = new SegmentTreeNode(start, end, left.sum + right.sum);
158
- cur.left = left;
159
- cur.right = right;
160
- return cur;
161
- }
162
-
163
- /**
164
- * The function updates the value of a node in a segment tree and recalculates the sum of its children if they exist.
165
- * @param {number} index - The index parameter represents the index of the node in the segment tree that needs to be
166
- * updated.
167
- * @param {number} sum - The `sum` parameter represents the new value that should be assigned to the `sum` property of
168
- * the `SegmentTreeNode` at the specified `index`.
169
- * @param {SegmentTreeNodeVal} [val] - The `val` parameter is an optional value that can be assigned to the `val`
170
- * property of the `SegmentTreeNode` object. It is not currently used in the code, but you can uncomment the line `//
171
- * cur.val = val;` and pass a value for `val` in the
172
- * @returns The function does not return anything.
173
- */
174
- updateNode(index: number, sum: number, val?: SegmentTreeNodeVal) {
175
- const root = this.root || null;
176
- if (!root) {
177
- return;
178
- }
179
- const dfs = (cur: SegmentTreeNode, index: number, sum: number, val?: SegmentTreeNodeVal) => {
180
- if (cur.start === cur.end && cur.start === index) {
181
- cur.sum = sum;
182
- // cur.val = val;
183
- return;
184
- }
185
- const mid = cur.start + Math.floor((cur.end - cur.start) / 2);
186
- if (index <= mid) {
187
- if (cur.left) {
188
- dfs(cur.left, index, sum, val);
189
- }
190
- } else {
191
- if (cur.right) {
192
- dfs(cur.right, index, sum, val);
193
- }
194
- }
195
- if (cur.left && cur.right) {
196
- cur.sum = cur.left.sum + cur.right.sum;
197
- }
198
- };
199
-
200
- dfs(root, index, sum);
201
- }
202
-
203
- /**
204
- * The function `querySumByRange` calculates the sum of values within a given range in a segment tree.
205
- * @param {number} indexA - The starting index of the range for which you want to calculate the sum.
206
- * @param {number} indexB - The parameter `indexB` represents the ending index of the range for which you want to
207
- * calculate the sum.
208
- * @returns The function `querySumByRange` returns a number.
209
- */
210
- querySumByRange(indexA: number, indexB: number): number {
211
- const root = this.root || null;
212
- if (!root) {
213
- return 0;
214
- }
215
-
216
- const dfs = (cur: SegmentTreeNode, i: number, j: number): number => {
217
- if (cur.start === i && cur.end === j) {
218
- return cur.sum;
219
- }
220
- const mid = cur.start + Math.floor((cur.end - cur.start) / 2);
221
- if (j <= mid) {
222
- // TODO after no-non-null-assertion not ensure the logic
223
- if (cur.left) {
224
- return dfs(cur.left, i, j);
225
- } else {
226
- return NaN;
227
- }
228
- } else if (i > mid) {
229
- // TODO after no-non-null-assertion not ensure the logic
230
- if (cur.right) {
231
- // TODO after no-non-null-assertion not ensure the logic
232
- return dfs(cur.right, i, j);
233
-
234
- } else {
235
- return NaN;
236
- }
237
- } else {
238
- // TODO after no-non-null-assertion not ensure the logic
239
- if (cur.left && cur.right) {
240
- return dfs(cur.left, i, mid) + dfs(cur.right, mid + 1, j);
241
- } else {
242
- return NaN;
243
- }
244
- }
245
- };
246
- return dfs(root, indexA, indexB);
247
- }
248
- }
@@ -1,3 +0,0 @@
1
- export class SplayTree {
2
-
3
- }
@@ -1,53 +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 {BST, BSTNode} from './bst';
9
- import type {BinaryTreeNodeId, TreeMultiSetDeletedResult} from '../types';
10
-
11
- export class TreeMultiSet<T> extends BST<T> {
12
- /**
13
- * The function creates a new BSTNode with the given id, value, and count.
14
- * @param {BinaryTreeNodeId} id - The id parameter is the unique identifier for the binary tree node. It is used to
15
- * distinguish one node from another in the tree.
16
- * @param {T} val - The `val` parameter represents the value that will be stored in the binary search tree node.
17
- * @param {number} [count] - The "count" parameter is an optional parameter of type number. It represents the number of
18
- * occurrences of the value in the binary search tree node. If not provided, the count will default to 1.
19
- * @returns A new instance of the BSTNode class with the specified id, value, and count (if provided).
20
- */
21
- override createNode(id: BinaryTreeNodeId, val: T, count?: number): BSTNode<T> {
22
- return new BSTNode<T>(id, val, count);
23
- }
24
-
25
- /**
26
- * The function overrides the add method of the BinarySearchTree class in TypeScript.
27
- * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that you want to add.
28
- * @param {T | null} val - The `val` parameter represents the value that you want to add to the binary search tree. It
29
- * can be of type `T` (the generic type) or `null`.
30
- * @param {number} [count] - The `count` parameter is an optional parameter of type `number`. It represents the number
31
- * of times the value should be added to the binary search tree. If not provided, the default value is `undefined`.
32
- * @returns The `add` method is returning a `BSTNode<T>` object or `null`.
33
- */
34
- override add(id: BinaryTreeNodeId, val: T | null, count?: number): BSTNode<T> | null {
35
- return super.add(id, val, count);
36
- }
37
-
38
- /**
39
- * The function overrides the remove method of the superclass and returns the result of calling the superclass's remove
40
- * method.
41
- * @param {BinaryTreeNodeId} id - The `id` parameter represents the identifier of the binary tree node that needs to be
42
- * removed from the tree.
43
- * @param {boolean} [isUpdateAllLeftSum] - The `isUpdateAllLeftSum` parameter is an optional boolean value that
44
- * determines whether to update the left sum of all nodes in the tree after removing a node. If `isUpdateAllLeftSum` is
45
- * set to `true`, the left sum of all nodes will be recalculated. If it
46
- * @returns The method is returning an array of TreeMultiSetDeletedResult objects.
47
- */
48
- override remove(id: BinaryTreeNodeId, isUpdateAllLeftSum?: boolean): TreeMultiSetDeletedResult<T>[] {
49
- return super.remove(id, isUpdateAllLeftSum);
50
- }
51
- }
52
-
53
-
@@ -1,3 +0,0 @@
1
- export class TwoThreeTree {
2
-
3
- }
@@ -1,5 +0,0 @@
1
- // 操作 常见名称 Ada Java JavaScript C++ Python Perl PHP Ruby // 尾部插入 inject, snoc Append offerLast push push_back append push
2
- array_push push // 头部插入 push, cons Prepend offerFirst unshift push_front appendleft unshift array_unshift unshift //
3
- 尾部删除 eject Delete_Last pollLast pop pop_back pop pop array_pop pop // 头部删除 pop Delete_First pollFirst shift pop_front
4
- popleft shift array_shift shift // 查看尾部 Last_Element peekLast [length - 1] back [-1] $array[-1] end
5
- last // 查看头部 First_Element peekFirst [0] front [0] $array[0] reset first