data-structure-typed 1.15.1 → 1.15.2

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 (41) hide show
  1. package/README.md +378 -7
  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 +14 -14
  14. package/dist/data-structures/heap/heap.js +12 -12
  15. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +9 -9
  16. package/dist/data-structures/linked-list/doubly-linked-list.js +12 -12
  17. package/dist/data-structures/linked-list/singly-linked-list.d.ts +7 -7
  18. package/dist/data-structures/priority-queue/priority-queue.d.ts +7 -7
  19. package/dist/data-structures/priority-queue/priority-queue.js +6 -6
  20. package/dist/data-structures/queue/deque.d.ts +1 -1
  21. package/dist/utils/types/utils.d.ts +0 -3
  22. package/dist/utils/types/utils.js +0 -14
  23. package/dist/utils/utils.js +0 -197
  24. package/package.json +2 -4
  25. package/src/assets/overview-diagram-of-data-structures.png +0 -0
  26. package/src/data-structures/binary-tree/binary-tree.ts +83 -76
  27. package/src/data-structures/binary-tree/segment-tree.ts +55 -36
  28. package/src/data-structures/graph/abstract-graph.ts +21 -19
  29. package/src/data-structures/graph/directed-graph.ts +23 -18
  30. package/src/data-structures/graph/undirected-graph.ts +16 -11
  31. package/src/data-structures/hash/coordinate-map.ts +11 -8
  32. package/src/data-structures/hash/coordinate-set.ts +11 -8
  33. package/src/data-structures/heap/heap.ts +34 -28
  34. package/src/data-structures/linked-list/doubly-linked-list.ts +40 -26
  35. package/src/data-structures/linked-list/singly-linked-list.ts +32 -23
  36. package/src/data-structures/priority-queue/priority-queue.ts +17 -14
  37. package/src/data-structures/queue/deque.ts +14 -4
  38. package/src/utils/types/utils.ts +1 -173
  39. package/src/utils/utils.ts +0 -212
  40. package/tests/unit/data-structures/binary-tree/bst.test.ts +40 -31
  41. package/tests/unit/data-structures/graph/directed-graph.test.ts +31 -34
package/README.md CHANGED
@@ -1,5 +1,19 @@
1
+ # What
1
2
 
2
- Javascript Data Structure, TypeScript Data Structure Library
3
+ ## Brief
4
+ Javascript & TypeScript Data Structure Library.
5
+
6
+ Meticulously crafted to empower developers with a versatile set of essential data structures. Our library includes a
7
+ wide range of data structures
8
+
9
+ ## Data Structures
10
+
11
+ Binary Tree, Binary Search Tree (BST), AVL Tree, Tree Multiset, Segment Tree, Binary Indexed Tree, Graph, Directed
12
+ Graph, Undirected Graph, Linked List, Singly Linked List, Doubly Linked List, Queue, Object Deque, Array Deque, Stack,
13
+ Hash, Coordinate Set, Coordinate Map, Heap, Priority Queue, Max Priority Queue, Min Priority Queue, Trie
14
+
15
+
16
+ # How
3
17
 
4
18
  ## install
5
19
 
@@ -15,19 +29,374 @@ yarn add data-structure-typed
15
29
  npm install data-structure-typed
16
30
  ```
17
31
 
32
+ ### Binary Search Tree (BST) snippet
33
+
34
+ ```typescript
35
+ import {BST, BSTNode} from 'data-structure-typed';
36
+
37
+ const tree = new BST();
38
+ expect(tree).toBeInstanceOf(BST);
39
+
40
+ const ids = [11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5];
41
+ tree.addMany(ids);
42
+ expect(tree.root).toBeInstanceOf(BSTNode);
43
+ if (tree.root) expect(tree.root.id).toBe(11);
44
+ expect(tree.count).toBe(16);
45
+ expect(tree.has(6)).toBe(true);
46
+
47
+ const node6 = tree.get(6);
48
+ expect(node6 && tree.getHeight(node6)).toBe(2);
49
+ expect(node6 && tree.getDepth(node6)).toBe(3);
50
+
51
+ const nodeId10 = tree.get(10, 'id');
52
+ expect(nodeId10?.id).toBe(10);
53
+
54
+ const nodeVal9 = tree.get(9, 'val');
55
+ expect(nodeVal9?.id).toBe(9);
56
+
57
+ const nodesByCount1 = tree.getNodes(1, 'count');
58
+ expect(nodesByCount1.length).toBe(16);
59
+
60
+ const leftMost = tree.getLeftMost();
61
+ expect(leftMost?.id).toBe(1);
62
+
63
+ const node15 = tree.get(15);
64
+ const minNodeBySpecificNode = node15 && tree.getLeftMost(node15);
65
+ expect(minNodeBySpecificNode?.id).toBe(12);
66
+
67
+ const subTreeSum = node15 && tree.subTreeSum(node15);
68
+ expect(subTreeSum).toBe(70);
69
+
70
+ const lesserSum = tree.lesserSum(10);
71
+ expect(lesserSum).toBe(45);
72
+
73
+ expect(node15).toBeInstanceOf(BSTNode);
74
+ if (node15 instanceof BSTNode) {
75
+ const subTreeAdd = tree.subTreeAdd(node15, 1, 'count');
76
+ expect(subTreeAdd).toBeDefined();
77
+ }
78
+
79
+ const node11 = tree.get(11);
80
+ expect(node11).toBeInstanceOf(BSTNode);
81
+ if (node11 instanceof BSTNode) {
82
+ const allGreaterNodesAdded = tree.allGreaterNodesAdd(node11, 2, 'count');
83
+ expect(allGreaterNodesAdded).toBeDefined();
84
+ }
85
+
86
+ const dfsInorderNodes = tree.DFS('in', 'node');
87
+ expect(dfsInorderNodes[0].id).toBe(1);
88
+ expect(dfsInorderNodes[dfsInorderNodes.length - 1].id).toBe(16);
89
+
90
+ tree.balance();
91
+ expect(tree.isBalanced()).toBe(true);
92
+
93
+ const bfsNodesAfterBalanced = tree.BFS('node');
94
+ expect(bfsNodesAfterBalanced[0].id).toBe(8);
95
+ expect(bfsNodesAfterBalanced[bfsNodesAfterBalanced.length - 1].id).toBe(16);
96
+
97
+ const removed11 = tree.remove(11, true);
98
+ expect(removed11).toBeInstanceOf(Array);
99
+ expect(removed11[0]).toBeDefined();
100
+ expect(removed11[0].deleted).toBeDefined();
101
+
102
+ if (removed11[0].deleted) expect(removed11[0].deleted.id).toBe(11);
103
+
104
+ expect(tree.isAVLBalanced()).toBe(true);
105
+
106
+ expect(node15 && tree.getHeight(node15)).toBe(2);
107
+
108
+ const removed1 = tree.remove(1, true);
109
+ expect(removed1).toBeInstanceOf(Array);
110
+ expect(removed1[0]).toBeDefined();
111
+ expect(removed1[0].deleted).toBeDefined();
112
+ if (removed1[0].deleted) expect(removed1[0].deleted.id).toBe(1);
113
+
114
+ expect(tree.isAVLBalanced()).toBe(true);
115
+
116
+ expect(tree.getHeight()).toBe(4);
117
+
118
+ // The code for removing these nodes (4, 10, 15, 5, 13, 3, 8, 6, 7, 9, 14) in sequence has been omitted.
119
+
120
+ expect(tree.isAVLBalanced()).toBe(false);
121
+
122
+ const bfsIDs = tree.BFS();
123
+ expect(bfsIDs[0]).toBe(2);
124
+ expect(bfsIDs[1]).toBe(12);
125
+ expect(bfsIDs[2]).toBe(16);
126
+
127
+ const bfsNodes = tree.BFS('node');
128
+ expect(bfsNodes[0].id).toBe(2);
129
+ expect(bfsNodes[1].id).toBe(12);
130
+ expect(bfsNodes[2].id).toBe(16);
131
+ ```
132
+
18
133
  ## Live Examples
19
134
 
20
135
  [//]: # ([Live Examples](https://data-structure-typed-examples.vercel.app))
21
136
 
22
137
  <a href="https://data-structure-typed-examples.vercel.app" target="_blank">Live Examples</a>
23
138
 
24
- ## Data Structures
139
+ ### Directed Graph simple snippet
25
140
 
26
- Meticulously crafted to empower developers with a versatile set of essential data structures. Our library includes a
27
- wide range of data structures:
28
- Binary Tree, Binary Search Tree (BST), AVL Tree, Tree Multiset, Segment Tree, Binary Indexed Tree, Graph, Directed
29
- Graph, Undirected Graph, Linked List, Singly Linked List, Doubly Linked List, Queue, Object Deque, Array Deque, Stack,
30
- Hash, Coordinate Set, Coordinate Map, Heap, Priority Queue, Max Priority Queue, Min Priority Queue, Trie
141
+ ```typescript
142
+ import {DirectedGraph, DirectedVertex, DirectedEdge, VertexId} from 'data-structure-typed';
143
+
144
+ let graph: DirectedGraph<DirectedVertex, DirectedEdge>;
145
+
146
+ beforeEach(() => {
147
+ graph = new DirectedGraph();
148
+ });
149
+
150
+
151
+ it('should add vertices', () => {
152
+ const vertex1 = new DirectedVertex('A');
153
+ const vertex2 = new DirectedVertex('B');
154
+
155
+ graph.addVertex(vertex1);
156
+ graph.addVertex(vertex2);
157
+
158
+ expect(graph.hasVertex(vertex1)).toBe(true);
159
+ expect(graph.hasVertex(vertex2)).toBe(true);
160
+ });
161
+
162
+ it('should add edges', () => {
163
+ const vertex1 = new DirectedVertex('A');
164
+ const vertex2 = new DirectedVertex('B');
165
+ const edge = new DirectedEdge('A', 'B');
166
+
167
+ graph.addVertex(vertex1);
168
+ graph.addVertex(vertex2);
169
+ graph.addEdge(edge);
170
+
171
+ expect(graph.hasEdge('A', 'B')).toBe(true);
172
+ expect(graph.hasEdge('B', 'A')).toBe(false);
173
+ });
174
+
175
+ it('should remove edges', () => {
176
+ const vertex1 = new DirectedVertex('A');
177
+ const vertex2 = new DirectedVertex('B');
178
+ const edge = new DirectedEdge('A', 'B');
179
+
180
+ graph.addVertex(vertex1);
181
+ graph.addVertex(vertex2);
182
+ graph.addEdge(edge);
183
+
184
+ expect(graph.removeEdge(edge)).toBe(edge);
185
+ expect(graph.hasEdge('A', 'B')).toBe(false);
186
+ });
187
+
188
+ it('should perform topological sort', () => {
189
+ const vertexA = new DirectedVertex('A');
190
+ const vertexB = new DirectedVertex('B');
191
+ const vertexC = new DirectedVertex('C');
192
+ const edgeAB = new DirectedEdge('A', 'B');
193
+ const edgeBC = new DirectedEdge('B', 'C');
194
+
195
+ graph.addVertex(vertexA);
196
+ graph.addVertex(vertexB);
197
+ graph.addVertex(vertexC);
198
+ graph.addEdge(edgeAB);
199
+ graph.addEdge(edgeBC);
200
+
201
+ const topologicalOrder = graph.topologicalSort();
202
+ if (topologicalOrder) expect(topologicalOrder.map(v => v.id)).toEqual(['A', 'B', 'C']);
203
+ });
204
+ ```
205
+
206
+ ### Directed Graph complex snippet
207
+
208
+ ```typescript
209
+ import {DirectedGraph, DirectedVertex, DirectedEdge, VertexId} from 'data-structure-typed';
210
+
211
+ class MyVertex extends DirectedVertex {
212
+ private _data: string;
213
+ get data(): string {
214
+ return this._data;
215
+ }
216
+ set data(value: string) {
217
+ this._data = value;
218
+ }
219
+
220
+ constructor(id: VertexId, data: string) {
221
+ super(id);
222
+ this._data = data;
223
+ }
224
+ }
225
+
226
+ class MyEdge extends DirectedEdge {
227
+ private _data: string;
228
+ get data(): string {
229
+ return this._data;
230
+ }
231
+ set data(value: string) {
232
+ this._data = value;
233
+ }
234
+
235
+ constructor(v1: VertexId, v2: VertexId, weight: number, data: string) {
236
+ super(v1, v2, weight);
237
+ this._data = data;
238
+ }
239
+ }
240
+
241
+ describe('DirectedGraph Test3', () => {
242
+ const myGraph = new DirectedGraph<MyVertex, MyEdge>();
243
+
244
+ it('should test graph operations', () => {
245
+ const vertex1 = new MyVertex(1, 'data1');
246
+ const vertex2 = new MyVertex(2, 'data2');
247
+ const vertex3 = new MyVertex(3, 'data3');
248
+ const vertex4 = new MyVertex(4, 'data4');
249
+ const vertex5 = new MyVertex(5, 'data5');
250
+ const vertex6 = new MyVertex(6, 'data6');
251
+ const vertex7 = new MyVertex(7, 'data7');
252
+ const vertex8 = new MyVertex(8, 'data8');
253
+ const vertex9 = new MyVertex(9, 'data9');
254
+ myGraph.addVertex(vertex1);
255
+ myGraph.addVertex(vertex2);
256
+ myGraph.addVertex(vertex3);
257
+ myGraph.addVertex(vertex4);
258
+ myGraph.addVertex(vertex5);
259
+ myGraph.addVertex(vertex6);
260
+ myGraph.addVertex(vertex7);
261
+ myGraph.addVertex(vertex8);
262
+ myGraph.addVertex(vertex9);
263
+
264
+ myGraph.addEdge(new MyEdge(1, 2, 10, 'edge-data1-2'));
265
+ myGraph.addEdge(new MyEdge(2, 1, 20, 'edge-data2-1'));
266
+
267
+ expect(myGraph.getEdge(1, 2)).toBeTruthy();
268
+ expect(myGraph.getEdge(2, 1)).toBeTruthy();
269
+ expect(myGraph.getEdge(1, '100')).toBeFalsy();
270
+
271
+ myGraph.removeEdgeBetween(1, 2);
272
+ expect(myGraph.getEdge(1, 2)).toBeFalsy();
273
+
274
+ myGraph.addEdge(new MyEdge(3, 1, 3, 'edge-data-3-1'));
275
+ myGraph.addEdge(new MyEdge(1, 9, 19, 'edge-data1-9'));
276
+ myGraph.addEdge(new MyEdge(9, 7, 97, 'edge-data9-7'));
277
+ myGraph.addEdge(new MyEdge(7, 9, 79, 'edge-data7-9'));
278
+ myGraph.addEdge(new MyEdge(1, 4, 14, 'edge-data1-4'));
279
+ myGraph.addEdge(new MyEdge(4, 7, 47, 'edge-data4-7'));
280
+ myGraph.addEdge(new MyEdge(1, 2, 12, 'edge-data1-2'));
281
+ myGraph.addEdge(new MyEdge(2, 3, 23, 'edge-data2-3'));
282
+ myGraph.addEdge(new MyEdge(3, 5, 35, 'edge-data3-5'));
283
+ myGraph.addEdge(new MyEdge(5, 7, 57, 'edge-data5-7'));
284
+ myGraph.addEdge(new MyEdge(7, 3, 73, 'edge-data7-3'));
285
+
286
+ const topologicalSorted = myGraph.topologicalSort();
287
+ expect(topologicalSorted).toBeNull();
288
+
289
+ const minPath1to7 = myGraph.getMinPathBetween(1, 7);
290
+ expect(minPath1to7).toBeInstanceOf(Array);
291
+ if (minPath1to7 && minPath1to7.length > 0) {
292
+ expect(minPath1to7).toHaveLength(3);
293
+ expect(minPath1to7[0]).toBeInstanceOf(MyVertex);
294
+ expect(minPath1to7[0].id).toBe(1);
295
+ expect(minPath1to7[1].id).toBe(9);
296
+ expect(minPath1to7[2].id).toBe(7);
297
+ }
298
+
299
+ const fordResult1 = myGraph.bellmanFord(1);
300
+ expect(fordResult1).toBeTruthy();
301
+ expect(fordResult1.hasNegativeCycle).toBeUndefined();
302
+ const {distMap, preMap, paths, min, minPath} = fordResult1;
303
+ expect(distMap).toBeInstanceOf(Map);
304
+ expect(distMap.size).toBe(9);
305
+ expect(distMap.get(vertex1)).toBe(0);
306
+ expect(distMap.get(vertex2)).toBe(12);
307
+ expect(distMap.get(vertex3)).toBe(35);
308
+ expect(distMap.get(vertex4)).toBe(14);
309
+ expect(distMap.get(vertex5)).toBe(70);
310
+ expect(distMap.get(vertex6)).toBe(Infinity);
311
+ expect(distMap.get(vertex7)).toBe(61);
312
+ expect(distMap.get(vertex8)).toBe(Infinity);
313
+ expect(distMap.get(vertex9)).toBe(19);
314
+
315
+ expect(preMap).toBeInstanceOf(Map);
316
+ expect(preMap.size).toBe(0);
317
+
318
+ expect(paths).toBeInstanceOf(Array);
319
+ expect(paths.length).toBe(0);
320
+ expect(min).toBe(Infinity);
321
+ expect(minPath).toBeInstanceOf(Array);
322
+
323
+ const floydResult = myGraph.floyd();
324
+ expect(floydResult).toBeTruthy();
325
+ if (floydResult) {
326
+ const {costs, predecessor} = floydResult;
327
+ expect(costs).toBeInstanceOf(Array);
328
+ expect(costs.length).toBe(9);
329
+ expect(costs[0]).toEqual([32, 12, 35, 14, 70, Infinity, 61, Infinity, 19]);
330
+ expect(costs[1]).toEqual([20, 32, 23, 34, 58, Infinity, 81, Infinity, 39]);
331
+ expect(costs[2]).toEqual([3, 15, 38, 17, 35, Infinity, 64, Infinity, 22]);
332
+ expect(costs[3]).toEqual([123, 135, 120, 137, 155, Infinity, 47, Infinity, 126]);
333
+ expect(costs[4]).toEqual([133, 145, 130, 147, 165, Infinity, 57, Infinity, 136]);
334
+ expect(costs[5]).toEqual([Infinity, Infinity, Infinity, Infinity, Infinity, Infinity, Infinity, Infinity, Infinity]);
335
+ expect(costs[6]).toEqual([76, 88, 73, 90, 108, Infinity, 137, Infinity, 79]);
336
+ expect(costs[7]).toEqual([Infinity, Infinity, Infinity, Infinity, Infinity, Infinity, Infinity, Infinity, Infinity]);
337
+ expect(costs[8]).toEqual([173, 185, 170, 187, 205, Infinity, 97, Infinity, 176]);
338
+
339
+ expect(predecessor).toBeInstanceOf(Array);
340
+ expect(predecessor.length).toBe(9);
341
+ expect(predecessor[0]).toEqual([vertex2, null, vertex2, null, vertex3, null, vertex4, null, null]);
342
+ expect(predecessor[1]).toEqual([null, vertex1, null, vertex1, vertex3, null, vertex4, null, vertex1]);
343
+ expect(predecessor[5]).toEqual([null, null, null, null, null, null, null, null, null]);
344
+ expect(predecessor[7]).toEqual([null, null, null, null, null, null, null, null, null]);
345
+ expect(predecessor[8]).toEqual([vertex7, vertex7, vertex7, vertex7, vertex7, null, null, null, vertex7]);
346
+ }
347
+
348
+ const dijkstraRes12tt = myGraph.dijkstra(1, 2, true, true);
349
+ expect(dijkstraRes12tt).toBeTruthy();
350
+ if (dijkstraRes12tt) {
351
+ const {distMap, minDist, minPath, paths, preMap, seen} = dijkstraRes12tt;
352
+ expect(distMap).toBeInstanceOf(Map);
353
+ expect(distMap.size).toBe(9);
354
+ expect(distMap.get(vertex1)).toBe(0);
355
+ expect(distMap.get(vertex2)).toBe(12);
356
+ expect(distMap.get(vertex3)).toBe(Infinity);
357
+ expect(distMap.get(vertex4)).toBe(14);
358
+ expect(distMap.get(vertex5)).toBe(Infinity);
359
+ expect(distMap.get(vertex6)).toBe(Infinity);
360
+ expect(distMap.get(vertex7)).toBe(Infinity);
361
+ expect(distMap.get(vertex8)).toBe(Infinity);
362
+ expect(distMap.get(vertex9)).toBe(19);
363
+
364
+ expect(minDist).toBe(12);
365
+ expect(minPath).toBeInstanceOf(Array);
366
+ expect(minPath.length).toBe(2);
367
+ expect(minPath[0]).toBe(vertex1);
368
+ expect(minPath[1]).toBe(vertex2);
369
+
370
+ expect(paths).toBeInstanceOf(Array);
371
+ expect(paths.length).toBe(9);
372
+ expect(paths[0]).toBeInstanceOf(Array);
373
+ expect(paths[0][0]).toBe(vertex1);
374
+
375
+ expect(paths[1]).toBeInstanceOf(Array);
376
+ expect(paths[1][0]).toBe(vertex1);
377
+ expect(paths[1][1]).toBe(vertex2);
378
+
379
+ expect(paths[2]).toBeInstanceOf(Array);
380
+ expect(paths[2][0]).toBe(vertex3);
381
+ expect(paths[3]).toBeInstanceOf(Array);
382
+ expect(paths[3][0]).toBe(vertex1);
383
+ expect(paths[3][1]).toBe(vertex4);
384
+ expect(paths[4]).toBeInstanceOf(Array);
385
+ expect(paths[4][0]).toBe(vertex5);
386
+
387
+ expect(paths[5]).toBeInstanceOf(Array);
388
+ expect(paths[5][0]).toBe(vertex6);
389
+ expect(paths[6]).toBeInstanceOf(Array);
390
+ expect(paths[6][0]).toBe(vertex7);
391
+ expect(paths[7]).toBeInstanceOf(Array);
392
+ expect(paths[7][0]).toBe(vertex8);
393
+ expect(paths[8]).toBeInstanceOf(Array);
394
+ expect(paths[8][0]).toBe(vertex1);
395
+ expect(paths[8][1]).toBe(vertex9);
396
+ }
397
+ });
398
+ });
399
+ ```
31
400
 
32
401
  ## API docs
33
402
 
@@ -99,6 +468,7 @@ Hash, Coordinate Set, Coordinate Map, Heap, Priority Queue, Max Priority Queue,
99
468
 
100
469
  <a href="https://github.com/zrwusa/data-structure-typed-examples" target="_blank">Examples Repository</a>
101
470
 
471
+ # Why
102
472
 
103
473
  ## Complexities
104
474
 
@@ -363,6 +733,7 @@ Hash, Coordinate Set, Coordinate Map, Heap, Priority Queue, Max Priority Queue,
363
733
  </tbody>
364
734
  </table>
365
735
 
736
+ ![overview diagram](src/assets/overview-diagram-of-data-structures.png)
366
737
 
367
738
  ![complexities](src/assets/complexities-diff.jpg)
368
739
 
@@ -22,63 +22,63 @@ export declare enum LoopType {
22
22
  recursive = 2
23
23
  }
24
24
  export declare class BinaryTreeNode<T> {
25
+ constructor(id: BinaryTreeNodeId, val: T, count?: number);
25
26
  protected _id: BinaryTreeNodeId;
26
27
  get id(): BinaryTreeNodeId;
28
+ set id(v: BinaryTreeNodeId);
29
+ protected _val: T;
30
+ get val(): T;
31
+ set val(v: T);
32
+ protected _left?: BinaryTreeNode<T> | null;
33
+ get left(): BinaryTreeNode<T> | null | undefined;
34
+ set left(v: BinaryTreeNode<T> | null | undefined);
35
+ protected _right?: BinaryTreeNode<T> | null;
36
+ get right(): BinaryTreeNode<T> | null | undefined;
37
+ set right(v: BinaryTreeNode<T> | null | undefined);
38
+ protected _parent: BinaryTreeNode<T> | null | undefined;
39
+ get parent(): BinaryTreeNode<T> | null | undefined;
40
+ set parent(v: BinaryTreeNode<T> | null | undefined);
41
+ protected _familyPosition: FamilyPosition;
42
+ get familyPosition(): FamilyPosition;
43
+ set familyPosition(v: FamilyPosition);
44
+ protected _count: number;
45
+ get count(): number;
46
+ set count(v: number);
47
+ protected _height: number;
48
+ get height(): number;
49
+ set height(v: number);
27
50
  /**
28
51
  * 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.
29
52
  */
30
53
  getId(): BinaryTreeNodeId;
31
- set id(v: BinaryTreeNodeId);
32
- protected _val: T;
33
- get val(): T;
34
54
  /**
35
55
  * 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.
36
56
  */
37
57
  getVal(): T;
38
- set val(v: T);
39
- protected _left?: BinaryTreeNode<T> | null;
40
- get left(): BinaryTreeNode<T> | null | undefined;
41
58
  /**
42
59
  * 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.
43
60
  */
44
61
  getLeft(): BinaryTreeNode<T> | null | undefined;
45
- set left(v: BinaryTreeNode<T> | null | undefined);
46
- protected _right?: BinaryTreeNode<T> | null;
47
- get right(): BinaryTreeNode<T> | null | undefined;
48
62
  /**
49
63
  * 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.
50
64
  */
51
65
  getRight(): BinaryTreeNode<T> | null | undefined;
52
- set right(v: BinaryTreeNode<T> | null | undefined);
53
- protected _parent: BinaryTreeNode<T> | null | undefined;
54
- get parent(): BinaryTreeNode<T> | null | undefined;
55
66
  /**
56
67
  * 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.
57
68
  */
58
69
  getParent(): BinaryTreeNode<T> | null | undefined;
59
- set parent(v: BinaryTreeNode<T> | null | undefined);
60
- protected _familyPosition: FamilyPosition;
61
- get familyPosition(): FamilyPosition;
62
70
  /**
63
71
  * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
64
72
  */
65
73
  getFamilyPosition(): FamilyPosition;
66
- set familyPosition(v: FamilyPosition);
67
- protected _count: number;
68
- get count(): number;
69
74
  /**
70
75
  * 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.
71
76
  */
72
77
  getCount(): number;
73
- set count(v: number);
74
- protected _height: number;
75
- get height(): number;
76
78
  /**
77
79
  * 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.
78
80
  */
79
81
  getHeight(): number;
80
- set height(v: number);
81
- constructor(id: BinaryTreeNodeId, val: T, count?: number);
82
82
  swapLocation(swapNode: BinaryTreeNode<T>): BinaryTreeNode<T>;
83
83
  clone(): BinaryTreeNode<T>;
84
84
  }
@@ -104,26 +104,26 @@ export declare class BinaryTree<T> {
104
104
  });
105
105
  protected _root: BinaryTreeNode<T> | null;
106
106
  get root(): BinaryTreeNode<T> | null;
107
+ protected set root(v: BinaryTreeNode<T> | null);
108
+ protected _size: number;
109
+ get size(): number;
110
+ protected set size(v: number);
111
+ protected _count: number;
112
+ get count(): number;
113
+ protected set count(v: number);
107
114
  /**
108
115
  * 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 Getters (using the same name as the property) while utilizing separate method names for Setters.
109
116
  * @returns The method is returning either a BinaryTreeNode object of type T or null.
110
117
  */
111
118
  getRoot(): BinaryTreeNode<T> | null;
112
- protected set root(v: BinaryTreeNode<T> | null);
113
- protected _size: number;
114
- get size(): number;
115
119
  /**
116
120
  * 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.
117
121
  */
118
122
  getSize(): number;
119
- protected set size(v: number);
120
- protected _count: number;
121
- get count(): number;
122
123
  /**
123
124
  * 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.
124
125
  */
125
126
  getCount(): number;
126
- protected set count(v: number);
127
127
  /**
128
128
  * The function creates a new binary tree node with the given id, value, and count, or returns null if the value is
129
129
  * null.