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.
- package/README.md +378 -7
- package/dist/data-structures/binary-tree/binary-tree.d.ts +30 -30
- package/dist/data-structures/binary-tree/binary-tree.js +55 -55
- package/dist/data-structures/binary-tree/segment-tree.d.ts +17 -17
- package/dist/data-structures/binary-tree/segment-tree.js +30 -30
- package/dist/data-structures/graph/abstract-graph.d.ts +6 -6
- package/dist/data-structures/graph/abstract-graph.js +6 -6
- package/dist/data-structures/graph/directed-graph.d.ts +4 -4
- package/dist/data-structures/graph/directed-graph.js +6 -6
- package/dist/data-structures/graph/undirected-graph.d.ts +3 -3
- package/dist/data-structures/hash/coordinate-map.d.ts +2 -2
- package/dist/data-structures/hash/coordinate-set.d.ts +2 -2
- package/dist/data-structures/heap/heap.d.ts +14 -14
- package/dist/data-structures/heap/heap.js +12 -12
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +9 -9
- package/dist/data-structures/linked-list/doubly-linked-list.js +12 -12
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +7 -7
- package/dist/data-structures/priority-queue/priority-queue.d.ts +7 -7
- package/dist/data-structures/priority-queue/priority-queue.js +6 -6
- package/dist/data-structures/queue/deque.d.ts +1 -1
- package/dist/utils/types/utils.d.ts +0 -3
- package/dist/utils/types/utils.js +0 -14
- package/dist/utils/utils.js +0 -197
- package/package.json +2 -4
- package/src/assets/overview-diagram-of-data-structures.png +0 -0
- package/src/data-structures/binary-tree/binary-tree.ts +83 -76
- package/src/data-structures/binary-tree/segment-tree.ts +55 -36
- package/src/data-structures/graph/abstract-graph.ts +21 -19
- package/src/data-structures/graph/directed-graph.ts +23 -18
- package/src/data-structures/graph/undirected-graph.ts +16 -11
- package/src/data-structures/hash/coordinate-map.ts +11 -8
- package/src/data-structures/hash/coordinate-set.ts +11 -8
- package/src/data-structures/heap/heap.ts +34 -28
- package/src/data-structures/linked-list/doubly-linked-list.ts +40 -26
- package/src/data-structures/linked-list/singly-linked-list.ts +32 -23
- package/src/data-structures/priority-queue/priority-queue.ts +17 -14
- package/src/data-structures/queue/deque.ts +14 -4
- package/src/utils/types/utils.ts +1 -173
- package/src/utils/utils.ts +0 -212
- package/tests/unit/data-structures/binary-tree/bst.test.ts +40 -31
- package/tests/unit/data-structures/graph/directed-graph.test.ts +31 -34
|
@@ -30,15 +30,15 @@ export enum LoopType { iterative = 1, recursive = 2}
|
|
|
30
30
|
|
|
31
31
|
export class BinaryTreeNode<T> {
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
constructor(id: BinaryTreeNodeId, val: T, count?: number) {
|
|
34
|
+
this._id = id;
|
|
35
|
+
this._val = val;
|
|
36
|
+
this._count = count ?? 1;
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
getId(): BinaryTreeNodeId {
|
|
39
|
+
protected _id: BinaryTreeNodeId;
|
|
40
|
+
|
|
41
|
+
get id(): BinaryTreeNodeId {
|
|
42
42
|
return this._id;
|
|
43
43
|
}
|
|
44
44
|
|
|
@@ -51,26 +51,13 @@ export class BinaryTreeNode<T> {
|
|
|
51
51
|
return this._val;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
/**
|
|
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.
|
|
56
|
-
*/
|
|
57
|
-
getVal(): T {
|
|
58
|
-
return this._val;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
54
|
set val(v: T) {
|
|
62
55
|
this._val = v;
|
|
63
56
|
}
|
|
64
57
|
|
|
65
58
|
protected _left?: BinaryTreeNode<T> | null;
|
|
66
|
-
get left(): BinaryTreeNode<T> | null | undefined {
|
|
67
|
-
return this._left;
|
|
68
|
-
}
|
|
69
59
|
|
|
70
|
-
|
|
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.
|
|
72
|
-
*/
|
|
73
|
-
getLeft(): BinaryTreeNode<T> | null | undefined {
|
|
60
|
+
get left(): BinaryTreeNode<T> | null | undefined {
|
|
74
61
|
return this._left;
|
|
75
62
|
}
|
|
76
63
|
|
|
@@ -83,14 +70,8 @@ export class BinaryTreeNode<T> {
|
|
|
83
70
|
}
|
|
84
71
|
|
|
85
72
|
protected _right?: BinaryTreeNode<T> | null;
|
|
86
|
-
get right(): BinaryTreeNode<T> | null | undefined {
|
|
87
|
-
return this._right;
|
|
88
|
-
}
|
|
89
73
|
|
|
90
|
-
|
|
91
|
-
* 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.
|
|
92
|
-
*/
|
|
93
|
-
getRight(): BinaryTreeNode<T> | null | undefined {
|
|
74
|
+
get right(): BinaryTreeNode<T> | null | undefined {
|
|
94
75
|
return this._right;
|
|
95
76
|
}
|
|
96
77
|
|
|
@@ -103,14 +84,8 @@ export class BinaryTreeNode<T> {
|
|
|
103
84
|
}
|
|
104
85
|
|
|
105
86
|
protected _parent: BinaryTreeNode<T> | null | undefined;
|
|
106
|
-
get parent(): BinaryTreeNode<T> | null | undefined {
|
|
107
|
-
return this._parent;
|
|
108
|
-
}
|
|
109
87
|
|
|
110
|
-
|
|
111
|
-
* 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.
|
|
112
|
-
*/
|
|
113
|
-
getParent(): BinaryTreeNode<T> | null | undefined {
|
|
88
|
+
get parent(): BinaryTreeNode<T> | null | undefined {
|
|
114
89
|
return this._parent;
|
|
115
90
|
}
|
|
116
91
|
|
|
@@ -119,14 +94,8 @@ export class BinaryTreeNode<T> {
|
|
|
119
94
|
}
|
|
120
95
|
|
|
121
96
|
protected _familyPosition: FamilyPosition = FamilyPosition.root;
|
|
122
|
-
get familyPosition(): FamilyPosition {
|
|
123
|
-
return this._familyPosition;
|
|
124
|
-
}
|
|
125
97
|
|
|
126
|
-
|
|
127
|
-
* 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.
|
|
128
|
-
*/
|
|
129
|
-
getFamilyPosition(): FamilyPosition {
|
|
98
|
+
get familyPosition(): FamilyPosition {
|
|
130
99
|
return this._familyPosition;
|
|
131
100
|
}
|
|
132
101
|
|
|
@@ -135,14 +104,8 @@ export class BinaryTreeNode<T> {
|
|
|
135
104
|
}
|
|
136
105
|
|
|
137
106
|
protected _count = 1;
|
|
138
|
-
get count(): number {
|
|
139
|
-
return this._count;
|
|
140
|
-
}
|
|
141
107
|
|
|
142
|
-
|
|
143
|
-
* 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.
|
|
144
|
-
*/
|
|
145
|
-
getCount(): number {
|
|
108
|
+
get count(): number {
|
|
146
109
|
return this._count;
|
|
147
110
|
}
|
|
148
111
|
|
|
@@ -151,25 +114,69 @@ export class BinaryTreeNode<T> {
|
|
|
151
114
|
}
|
|
152
115
|
|
|
153
116
|
protected _height = 0;
|
|
117
|
+
|
|
154
118
|
get height(): number {
|
|
155
119
|
return this._height;
|
|
156
120
|
}
|
|
157
121
|
|
|
122
|
+
set height(v: number) {
|
|
123
|
+
this._height = v;
|
|
124
|
+
}
|
|
125
|
+
|
|
158
126
|
/**
|
|
159
127
|
* 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.
|
|
160
128
|
*/
|
|
161
|
-
|
|
162
|
-
return this.
|
|
129
|
+
getId(): BinaryTreeNodeId {
|
|
130
|
+
return this._id;
|
|
163
131
|
}
|
|
164
132
|
|
|
165
|
-
|
|
166
|
-
|
|
133
|
+
/**
|
|
134
|
+
* 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.
|
|
135
|
+
*/
|
|
136
|
+
getVal(): T {
|
|
137
|
+
return this._val;
|
|
167
138
|
}
|
|
168
139
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
140
|
+
/**
|
|
141
|
+
* 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.
|
|
142
|
+
*/
|
|
143
|
+
getLeft(): BinaryTreeNode<T> | null | undefined {
|
|
144
|
+
return this._left;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* 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.
|
|
149
|
+
*/
|
|
150
|
+
getRight(): BinaryTreeNode<T> | null | undefined {
|
|
151
|
+
return this._right;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* 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.
|
|
156
|
+
*/
|
|
157
|
+
getParent(): BinaryTreeNode<T> | null | undefined {
|
|
158
|
+
return this._parent;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* 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.
|
|
163
|
+
*/
|
|
164
|
+
getFamilyPosition(): FamilyPosition {
|
|
165
|
+
return this._familyPosition;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* 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.
|
|
170
|
+
*/
|
|
171
|
+
getCount(): number {
|
|
172
|
+
return this._count;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* 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.
|
|
177
|
+
*/
|
|
178
|
+
getHeight(): number {
|
|
179
|
+
return this._height;
|
|
173
180
|
}
|
|
174
181
|
|
|
175
182
|
swapLocation(swapNode: BinaryTreeNode<T>): BinaryTreeNode<T> {
|
|
@@ -235,14 +242,6 @@ export class BinaryTree<T> {
|
|
|
235
242
|
return this._root;
|
|
236
243
|
}
|
|
237
244
|
|
|
238
|
-
/**
|
|
239
|
-
* 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.
|
|
240
|
-
* @returns The method is returning either a BinaryTreeNode object of type T or null.
|
|
241
|
-
*/
|
|
242
|
-
getRoot(): BinaryTreeNode<T> | null {
|
|
243
|
-
return this._root;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
245
|
protected set root(v: BinaryTreeNode<T> | null) {
|
|
247
246
|
if (v) {
|
|
248
247
|
v.parent = null;
|
|
@@ -257,13 +256,6 @@ export class BinaryTree<T> {
|
|
|
257
256
|
return this._size;
|
|
258
257
|
}
|
|
259
258
|
|
|
260
|
-
/**
|
|
261
|
-
* 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.
|
|
262
|
-
*/
|
|
263
|
-
getSize(): number {
|
|
264
|
-
return this._size;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
259
|
protected set size(v: number) {
|
|
268
260
|
this._size = v;
|
|
269
261
|
}
|
|
@@ -274,15 +266,30 @@ export class BinaryTree<T> {
|
|
|
274
266
|
return this._count;
|
|
275
267
|
}
|
|
276
268
|
|
|
269
|
+
protected set count(v: number) {
|
|
270
|
+
this._count = v;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* 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.
|
|
275
|
+
* @returns The method is returning either a BinaryTreeNode object of type T or null.
|
|
276
|
+
*/
|
|
277
|
+
getRoot(): BinaryTreeNode<T> | null {
|
|
278
|
+
return this._root;
|
|
279
|
+
}
|
|
280
|
+
|
|
277
281
|
/**
|
|
278
282
|
* 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.
|
|
279
283
|
*/
|
|
280
|
-
|
|
281
|
-
return this.
|
|
284
|
+
getSize(): number {
|
|
285
|
+
return this._size;
|
|
282
286
|
}
|
|
283
287
|
|
|
284
|
-
|
|
285
|
-
|
|
288
|
+
/**
|
|
289
|
+
* 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.
|
|
290
|
+
*/
|
|
291
|
+
getCount(): number {
|
|
292
|
+
return this._count;
|
|
286
293
|
}
|
|
287
294
|
|
|
288
295
|
/**
|
|
@@ -20,85 +20,102 @@ export class SegmentTreeNode {
|
|
|
20
20
|
get start(): number {
|
|
21
21
|
return this._start;
|
|
22
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
|
-
}
|
|
23
|
+
|
|
29
24
|
set start(v: number) {
|
|
30
25
|
this._start = v;
|
|
31
26
|
}
|
|
32
27
|
|
|
33
28
|
protected _end = 0;
|
|
29
|
+
|
|
34
30
|
get end(): number {
|
|
35
31
|
return this._end;
|
|
36
32
|
}
|
|
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
|
-
}
|
|
33
|
+
|
|
43
34
|
set end(v: number) {
|
|
44
35
|
this._end = v;
|
|
45
36
|
}
|
|
46
37
|
|
|
47
38
|
protected _val: SegmentTreeNodeVal | null = null;
|
|
39
|
+
|
|
48
40
|
get val(): SegmentTreeNodeVal | null {
|
|
49
41
|
return this._val;
|
|
50
42
|
}
|
|
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
|
-
}
|
|
43
|
+
|
|
57
44
|
set val(v: SegmentTreeNodeVal | null) {
|
|
58
45
|
this._val = v;
|
|
59
46
|
}
|
|
60
47
|
|
|
61
48
|
protected _sum = 0;
|
|
49
|
+
|
|
62
50
|
get sum(): number {
|
|
63
51
|
return this._sum;
|
|
64
52
|
}
|
|
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
|
-
}
|
|
53
|
+
|
|
71
54
|
set sum(v: number) {
|
|
72
55
|
this._sum = v;
|
|
73
56
|
}
|
|
74
57
|
|
|
75
58
|
protected _left: SegmentTreeNode | null = null;
|
|
59
|
+
|
|
76
60
|
get left(): SegmentTreeNode | null {
|
|
77
61
|
return this._left;
|
|
78
62
|
}
|
|
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
|
-
}
|
|
63
|
+
|
|
85
64
|
set left(v: SegmentTreeNode | null) {
|
|
86
65
|
this._left = v;
|
|
87
66
|
}
|
|
88
67
|
|
|
89
68
|
protected _right: SegmentTreeNode | null = null;
|
|
69
|
+
|
|
90
70
|
get right(): SegmentTreeNode | null {
|
|
91
71
|
return this._right;
|
|
92
72
|
}
|
|
73
|
+
|
|
74
|
+
set right(v: SegmentTreeNode | null) {
|
|
75
|
+
this._right = v;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
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.
|
|
80
|
+
*/
|
|
81
|
+
getStart(): number {
|
|
82
|
+
return this._start;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* 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.
|
|
87
|
+
*/
|
|
88
|
+
getEnd(): number {
|
|
89
|
+
return this._end;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* 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.
|
|
94
|
+
*/
|
|
95
|
+
getVal(): SegmentTreeNodeVal | null {
|
|
96
|
+
return this._val;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* 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.
|
|
101
|
+
*/
|
|
102
|
+
getSum(): number {
|
|
103
|
+
return this._sum;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* 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.
|
|
108
|
+
*/
|
|
109
|
+
getLeft(): SegmentTreeNode | null {
|
|
110
|
+
return this._left;
|
|
111
|
+
}
|
|
112
|
+
|
|
93
113
|
/**
|
|
94
114
|
* 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
115
|
*/
|
|
96
116
|
getRight(): SegmentTreeNode | null {
|
|
97
117
|
return this._right;
|
|
98
118
|
}
|
|
99
|
-
set right(v: SegmentTreeNode | null) {
|
|
100
|
-
this._right = v;
|
|
101
|
-
}
|
|
102
119
|
}
|
|
103
120
|
|
|
104
121
|
export class SegmentTree {
|
|
@@ -128,15 +145,17 @@ export class SegmentTree {
|
|
|
128
145
|
get root(): SegmentTreeNode | null {
|
|
129
146
|
return this._root;
|
|
130
147
|
}
|
|
148
|
+
|
|
149
|
+
set root(v: SegmentTreeNode | null) {
|
|
150
|
+
this._root = v;
|
|
151
|
+
}
|
|
152
|
+
|
|
131
153
|
/**
|
|
132
154
|
* 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
155
|
*/
|
|
134
156
|
getRoot(): SegmentTreeNode | null {
|
|
135
157
|
return this._root;
|
|
136
158
|
}
|
|
137
|
-
set root(v: SegmentTreeNode | null) {
|
|
138
|
-
this._root = v;
|
|
139
|
-
}
|
|
140
159
|
|
|
141
160
|
/**
|
|
142
161
|
* The function builds a segment tree by recursively dividing the given range into smaller segments and creating nodes
|
|
@@ -10,25 +10,26 @@ import {PriorityQueue} from '../priority-queue';
|
|
|
10
10
|
import type {DijkstraResult, IGraph, VertexId} from '../types';
|
|
11
11
|
|
|
12
12
|
export class AbstractVertex {
|
|
13
|
+
constructor(id: VertexId) {
|
|
14
|
+
this._id = id;
|
|
15
|
+
}
|
|
16
|
+
|
|
13
17
|
protected _id: VertexId;
|
|
18
|
+
|
|
14
19
|
get id(): VertexId {
|
|
15
20
|
return this._id;
|
|
16
21
|
}
|
|
17
22
|
|
|
23
|
+
set id(v: VertexId) {
|
|
24
|
+
this._id = v;
|
|
25
|
+
}
|
|
26
|
+
|
|
18
27
|
/**
|
|
19
28
|
* 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.
|
|
20
29
|
*/
|
|
21
30
|
getId(): VertexId {
|
|
22
31
|
return this._id;
|
|
23
32
|
}
|
|
24
|
-
|
|
25
|
-
set id(v: VertexId) {
|
|
26
|
-
this._id = v;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
constructor(id: VertexId) {
|
|
30
|
-
this._id = id;
|
|
31
|
-
}
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
export abstract class AbstractEdge {
|
|
@@ -51,31 +52,32 @@ export abstract class AbstractEdge {
|
|
|
51
52
|
return this._weight;
|
|
52
53
|
}
|
|
53
54
|
|
|
54
|
-
/**
|
|
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.
|
|
56
|
-
*/
|
|
57
|
-
getWeight(): number {
|
|
58
|
-
return this._weight;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
55
|
set weight(v: number) {
|
|
62
56
|
this._weight = v;
|
|
63
57
|
}
|
|
64
58
|
|
|
65
59
|
private _hashCode: string;
|
|
60
|
+
|
|
66
61
|
get hashCode(): string {
|
|
67
62
|
return this._hashCode;
|
|
68
63
|
}
|
|
69
64
|
|
|
65
|
+
set hashCode(v: string) {
|
|
66
|
+
this._hashCode = v;
|
|
67
|
+
}
|
|
68
|
+
|
|
70
69
|
/**
|
|
71
70
|
* 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.
|
|
72
71
|
*/
|
|
73
|
-
|
|
74
|
-
return this.
|
|
72
|
+
getWeight(): number {
|
|
73
|
+
return this._weight;
|
|
75
74
|
}
|
|
76
75
|
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
/**
|
|
77
|
+
* 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
|
+
*/
|
|
79
|
+
getHashCode(): string {
|
|
80
|
+
return this._hashCode;
|
|
79
81
|
}
|
|
80
82
|
}
|
|
81
83
|
|
|
@@ -40,29 +40,34 @@ export class DirectedEdge extends AbstractEdge {
|
|
|
40
40
|
get src(): VertexId {
|
|
41
41
|
return this._src;
|
|
42
42
|
}
|
|
43
|
-
|
|
44
|
-
* 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.
|
|
45
|
-
*/
|
|
46
|
-
getSrc(): VertexId {
|
|
47
|
-
return this._src;
|
|
48
|
-
}
|
|
43
|
+
|
|
49
44
|
set src(v: VertexId) {
|
|
50
45
|
this._src = v;
|
|
51
46
|
}
|
|
52
47
|
|
|
53
48
|
private _dest: VertexId;
|
|
49
|
+
|
|
54
50
|
get dest(): VertexId {
|
|
55
51
|
return this._dest;
|
|
56
52
|
}
|
|
53
|
+
|
|
54
|
+
set dest(v: VertexId) {
|
|
55
|
+
this._dest = v;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
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.
|
|
60
|
+
*/
|
|
61
|
+
getSrc(): VertexId {
|
|
62
|
+
return this._src;
|
|
63
|
+
}
|
|
64
|
+
|
|
57
65
|
/**
|
|
58
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.
|
|
59
67
|
*/
|
|
60
68
|
getDest(): VertexId {
|
|
61
69
|
return this._dest;
|
|
62
70
|
}
|
|
63
|
-
set dest(v: VertexId) {
|
|
64
|
-
this._dest = v;
|
|
65
|
-
}
|
|
66
71
|
}
|
|
67
72
|
|
|
68
73
|
// Strongly connected, One direction connected, Weakly connected
|
|
@@ -159,14 +164,14 @@ export class DirectedGraph<V extends DirectedVertex, E extends DirectedEdge> ext
|
|
|
159
164
|
|
|
160
165
|
const srcOutEdges = this._outEdgeMap.get(src);
|
|
161
166
|
if (srcOutEdges) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
167
|
+
/**
|
|
168
|
+
* The removeEdge function removes an edge from a graph and returns the removed edge, or null if the edge was not
|
|
169
|
+
* found.
|
|
170
|
+
* @param {E} edge - The `edge` parameter represents the edge that you want to remove from the graph. It should be an
|
|
171
|
+
* object that has `src` and `dest` properties, which represent the source and destination vertices of the edge,
|
|
172
|
+
* respectively.
|
|
173
|
+
* @returns The method `removeEdge` returns the removed edge (`E`) if it exists, or `null` if the edge does not exist.
|
|
174
|
+
*/
|
|
170
175
|
arrayRemove<E>(srcOutEdges, (edge: DirectedEdge) => edge.dest === dest.id);
|
|
171
176
|
}
|
|
172
177
|
|
|
@@ -184,7 +189,7 @@ export class DirectedGraph<V extends DirectedVertex, E extends DirectedEdge> ext
|
|
|
184
189
|
* and `dest`, which represent the source and destination vertices of the edge, respectively.
|
|
185
190
|
* @returns The method `removeEdge` returns the removed edge (`E`) if it exists, or `null` if the edge does not exist.
|
|
186
191
|
*/
|
|
187
|
-
removeEdge(edge: E
|
|
192
|
+
removeEdge(edge: E): E | null {
|
|
188
193
|
let removed: E | null = null;
|
|
189
194
|
const src = this.getVertex(edge.src);
|
|
190
195
|
const dest = this.getVertex(edge.dest);
|
|
@@ -38,36 +38,41 @@ export class UndirectedEdge extends AbstractEdge {
|
|
|
38
38
|
get vertices() {
|
|
39
39
|
return this._vertices;
|
|
40
40
|
}
|
|
41
|
+
|
|
42
|
+
set vertices(v: [VertexId, VertexId]) {
|
|
43
|
+
this._vertices = v;
|
|
44
|
+
}
|
|
45
|
+
|
|
41
46
|
/**
|
|
42
47
|
* 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
48
|
*/
|
|
44
49
|
getVertices() {
|
|
45
50
|
return this._vertices;
|
|
46
51
|
}
|
|
47
|
-
set vertices(v: [VertexId, VertexId]) {
|
|
48
|
-
this._vertices = v;
|
|
49
|
-
}
|
|
50
52
|
}
|
|
51
53
|
|
|
52
54
|
export class UndirectedGraph<V extends UndirectedVertex, E extends UndirectedEdge> extends AbstractGraph<V, E> {
|
|
55
|
+
constructor() {
|
|
56
|
+
super();
|
|
57
|
+
this._edges = new Map<V, E[]>();
|
|
58
|
+
}
|
|
59
|
+
|
|
53
60
|
protected _edges: Map<V, E[]>;
|
|
61
|
+
|
|
54
62
|
get edges(): Map<V, E[]> {
|
|
55
63
|
return this._edges;
|
|
56
64
|
}
|
|
65
|
+
|
|
66
|
+
protected set edges(v: Map<V, E[]>) {
|
|
67
|
+
this._edges = v;
|
|
68
|
+
}
|
|
69
|
+
|
|
57
70
|
/**
|
|
58
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.
|
|
59
72
|
*/
|
|
60
73
|
getEdges(): Map<V, E[]> {
|
|
61
74
|
return this._edges;
|
|
62
75
|
}
|
|
63
|
-
protected set edges(v: Map<V, E[]>) {
|
|
64
|
-
this._edges = v;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
constructor() {
|
|
68
|
-
super();
|
|
69
|
-
this._edges = new Map<V, E[]>();
|
|
70
|
-
}
|
|
71
76
|
|
|
72
77
|
/**
|
|
73
78
|
* The function `getEdge` returns the first edge that connects two vertices, or null if no such edge exists.
|
|
@@ -6,24 +6,27 @@
|
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
export class CoordinateMap<V> extends Map<any, V> {
|
|
9
|
+
constructor(joint?: string) {
|
|
10
|
+
super();
|
|
11
|
+
if (joint !== undefined) this._joint = joint;
|
|
12
|
+
}
|
|
13
|
+
|
|
9
14
|
protected _joint: string = '_';
|
|
15
|
+
|
|
10
16
|
get joint(): string {
|
|
11
17
|
return this._joint;
|
|
12
18
|
}
|
|
19
|
+
|
|
20
|
+
protected set joint(v: string) {
|
|
21
|
+
this._joint = v;
|
|
22
|
+
}
|
|
23
|
+
|
|
13
24
|
/**
|
|
14
25
|
* 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.
|
|
15
26
|
*/
|
|
16
27
|
getJoint(): string {
|
|
17
28
|
return this._joint;
|
|
18
29
|
}
|
|
19
|
-
protected set joint(v: string) {
|
|
20
|
-
this._joint = v;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
constructor(joint?: string) {
|
|
24
|
-
super();
|
|
25
|
-
if (joint !== undefined) this._joint = joint;
|
|
26
|
-
}
|
|
27
30
|
|
|
28
31
|
/**
|
|
29
32
|
* The "has" function overrides the base class's "has" function and checks if a key exists in the map by joining the
|