data-structure-typed 1.19.2 → 1.19.4
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/dist/data-structures/binary-tree/aa-tree.js +2 -5
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +361 -488
- package/dist/data-structures/binary-tree/avl-tree.js +46 -90
- package/dist/data-structures/binary-tree/b-tree.js +2 -5
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +17 -22
- package/dist/data-structures/binary-tree/binary-tree.js +9 -31
- package/dist/data-structures/binary-tree/bst.js +96 -139
- package/dist/data-structures/binary-tree/rb-tree.js +32 -56
- package/dist/data-structures/binary-tree/segment-tree.js +78 -120
- package/dist/data-structures/binary-tree/splay-tree.js +2 -5
- package/dist/data-structures/binary-tree/tree-multiset.js +176 -253
- package/dist/data-structures/binary-tree/two-three-tree.js +2 -5
- package/dist/data-structures/graph/abstract-graph.js +340 -574
- package/dist/data-structures/graph/directed-graph.js +146 -276
- package/dist/data-structures/graph/undirected-graph.js +87 -176
- package/dist/data-structures/hash/coordinate-map.js +23 -45
- package/dist/data-structures/hash/coordinate-set.js +20 -42
- package/dist/data-structures/hash/hash-table.js +2 -5
- package/dist/data-structures/hash/pair.js +2 -5
- package/dist/data-structures/hash/tree-map.js +2 -5
- package/dist/data-structures/hash/tree-set.js +2 -5
- package/dist/data-structures/heap/heap.js +53 -77
- package/dist/data-structures/heap/max-heap.js +8 -26
- package/dist/data-structures/heap/min-heap.js +8 -26
- package/dist/data-structures/linked-list/doubly-linked-list.js +132 -197
- package/dist/data-structures/linked-list/singly-linked-list.js +112 -173
- package/dist/data-structures/linked-list/skip-linked-list.js +2 -5
- package/dist/data-structures/matrix/matrix.js +7 -8
- package/dist/data-structures/matrix/matrix2d.js +76 -93
- package/dist/data-structures/matrix/navigator.js +18 -37
- package/dist/data-structures/matrix/vector2d.js +80 -101
- package/dist/data-structures/priority-queue/max-priority-queue.js +11 -39
- package/dist/data-structures/priority-queue/min-priority-queue.js +11 -39
- package/dist/data-structures/priority-queue/priority-queue.js +93 -139
- package/dist/data-structures/queue/deque.js +82 -128
- package/dist/data-structures/queue/queue.js +24 -25
- package/dist/data-structures/stack/stack.js +21 -22
- package/dist/data-structures/tree/tree.js +32 -45
- package/dist/data-structures/trie/trie.js +93 -200
- package/dist/utils/utils.js +22 -107
- package/dist/utils/validate-type.js +2 -2
- package/package.json +1 -1
- package/src/assets/complexities-diff.jpg +0 -0
- package/src/assets/data-structure-complexities.jpg +0 -0
- package/src/assets/logo.png +0 -0
- package/src/assets/overview-diagram-of-data-structures.png +0 -0
- package/src/data-structures/binary-tree/aa-tree.ts +3 -0
- package/src/data-structures/binary-tree/abstract-binary-tree.ts +1528 -0
- package/src/data-structures/binary-tree/avl-tree.ts +297 -0
- package/src/data-structures/binary-tree/b-tree.ts +3 -0
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +78 -0
- package/src/data-structures/binary-tree/binary-tree.ts +40 -0
- package/src/data-structures/binary-tree/bst.ts +435 -0
- 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/index.ts +12 -0
- package/src/data-structures/binary-tree/rb-tree.ts +102 -0
- package/src/data-structures/binary-tree/segment-tree.ts +243 -0
- package/src/data-structures/binary-tree/splay-tree.ts +3 -0
- package/src/data-structures/binary-tree/tree-multiset.ts +694 -0
- package/src/data-structures/binary-tree/two-three-tree.ts +3 -0
- package/src/data-structures/diagrams/README.md +5 -0
- package/src/data-structures/graph/abstract-graph.ts +1032 -0
- package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
- package/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
- package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
- package/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
- package/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
- package/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
- package/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
- package/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
- package/src/data-structures/graph/diagrams/mst.jpg +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/diagrams/tarjan.webp +0 -0
- package/src/data-structures/graph/directed-graph.ts +472 -0
- package/src/data-structures/graph/index.ts +3 -0
- package/src/data-structures/graph/undirected-graph.ts +270 -0
- package/src/data-structures/hash/coordinate-map.ts +67 -0
- package/src/data-structures/hash/coordinate-set.ts +56 -0
- package/src/data-structures/hash/hash-table.ts +3 -0
- package/src/data-structures/hash/index.ts +6 -0
- package/src/data-structures/hash/pair.ts +3 -0
- package/src/data-structures/hash/tree-map.ts +3 -0
- package/src/data-structures/hash/tree-set.ts +3 -0
- package/src/data-structures/heap/heap.ts +183 -0
- package/src/data-structures/heap/index.ts +3 -0
- package/src/data-structures/heap/max-heap.ts +31 -0
- package/src/data-structures/heap/min-heap.ts +34 -0
- package/src/data-structures/index.ts +15 -0
- package/src/data-structures/interfaces/abstract-binary-tree.ts +231 -0
- package/src/data-structures/interfaces/abstract-graph.ts +40 -0
- package/src/data-structures/interfaces/avl-tree.ts +28 -0
- package/src/data-structures/interfaces/binary-tree.ts +8 -0
- package/src/data-structures/interfaces/bst.ts +32 -0
- package/src/data-structures/interfaces/directed-graph.ts +20 -0
- package/src/data-structures/interfaces/doubly-linked-list.ts +1 -0
- package/src/data-structures/interfaces/heap.ts +1 -0
- package/src/data-structures/interfaces/index.ts +15 -0
- package/src/data-structures/interfaces/navigator.ts +1 -0
- package/src/data-structures/interfaces/priority-queue.ts +1 -0
- package/src/data-structures/interfaces/rb-tree.ts +11 -0
- package/src/data-structures/interfaces/segment-tree.ts +1 -0
- package/src/data-structures/interfaces/singly-linked-list.ts +1 -0
- package/src/data-structures/interfaces/tree-multiset.ts +12 -0
- package/src/data-structures/interfaces/undirected-graph.ts +6 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +573 -0
- package/src/data-structures/linked-list/index.ts +3 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +490 -0
- package/src/data-structures/linked-list/skip-linked-list.ts +3 -0
- package/src/data-structures/matrix/index.ts +4 -0
- package/src/data-structures/matrix/matrix.ts +27 -0
- package/src/data-structures/matrix/matrix2d.ts +208 -0
- package/src/data-structures/matrix/navigator.ts +122 -0
- package/src/data-structures/matrix/vector2d.ts +316 -0
- package/src/data-structures/priority-queue/index.ts +3 -0
- package/src/data-structures/priority-queue/max-priority-queue.ts +49 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +50 -0
- package/src/data-structures/priority-queue/priority-queue.ts +354 -0
- package/src/data-structures/queue/deque.ts +251 -0
- package/src/data-structures/queue/index.ts +2 -0
- package/src/data-structures/queue/queue.ts +120 -0
- package/src/data-structures/stack/index.ts +1 -0
- package/src/data-structures/stack/stack.ts +98 -0
- package/src/data-structures/tree/index.ts +1 -0
- package/src/data-structures/tree/tree.ts +69 -0
- package/src/data-structures/trie/index.ts +1 -0
- package/src/data-structures/trie/trie.ts +227 -0
- package/src/data-structures/types/abstract-binary-tree.ts +42 -0
- package/src/data-structures/types/abstract-graph.ts +5 -0
- package/src/data-structures/types/avl-tree.ts +5 -0
- package/src/data-structures/types/binary-tree.ts +9 -0
- package/src/data-structures/types/bst.ts +12 -0
- package/src/data-structures/types/directed-graph.ts +8 -0
- package/src/data-structures/types/doubly-linked-list.ts +1 -0
- package/src/data-structures/types/heap.ts +5 -0
- package/src/data-structures/types/helpers.ts +1 -0
- package/src/data-structures/types/index.ts +15 -0
- package/src/data-structures/types/navigator.ts +13 -0
- package/src/data-structures/types/priority-queue.ts +9 -0
- package/src/data-structures/types/rb-tree.ts +8 -0
- package/src/data-structures/types/segment-tree.ts +1 -0
- package/src/data-structures/types/singly-linked-list.ts +1 -0
- package/src/data-structures/types/tree-multiset.ts +8 -0
- package/src/index.ts +2 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/types/index.ts +2 -0
- package/src/utils/types/utils.ts +6 -0
- package/src/utils/types/validate-type.ts +25 -0
- package/src/utils/utils.ts +78 -0
- package/src/utils/validate-type.ts +69 -0
- package/tsconfig.json +1 -1
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.SegmentTree = exports.SegmentTreeNode = void 0;
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
class SegmentTreeNode {
|
|
12
|
+
constructor(start, end, sum, val) {
|
|
13
13
|
this._start = 0;
|
|
14
14
|
this._end = 0;
|
|
15
15
|
this._val = null;
|
|
@@ -21,70 +21,45 @@ var SegmentTreeNode = /** @class */ (function () {
|
|
|
21
21
|
this._sum = sum;
|
|
22
22
|
this._val = val || null;
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
enumerable: false,
|
|
62
|
-
configurable: true
|
|
63
|
-
});
|
|
64
|
-
Object.defineProperty(SegmentTreeNode.prototype, "left", {
|
|
65
|
-
get: function () {
|
|
66
|
-
return this._left;
|
|
67
|
-
},
|
|
68
|
-
set: function (v) {
|
|
69
|
-
this._left = v;
|
|
70
|
-
},
|
|
71
|
-
enumerable: false,
|
|
72
|
-
configurable: true
|
|
73
|
-
});
|
|
74
|
-
Object.defineProperty(SegmentTreeNode.prototype, "right", {
|
|
75
|
-
get: function () {
|
|
76
|
-
return this._right;
|
|
77
|
-
},
|
|
78
|
-
set: function (v) {
|
|
79
|
-
this._right = v;
|
|
80
|
-
},
|
|
81
|
-
enumerable: false,
|
|
82
|
-
configurable: true
|
|
83
|
-
});
|
|
84
|
-
return SegmentTreeNode;
|
|
85
|
-
}());
|
|
24
|
+
get start() {
|
|
25
|
+
return this._start;
|
|
26
|
+
}
|
|
27
|
+
set start(v) {
|
|
28
|
+
this._start = v;
|
|
29
|
+
}
|
|
30
|
+
get end() {
|
|
31
|
+
return this._end;
|
|
32
|
+
}
|
|
33
|
+
set end(v) {
|
|
34
|
+
this._end = v;
|
|
35
|
+
}
|
|
36
|
+
get val() {
|
|
37
|
+
return this._val;
|
|
38
|
+
}
|
|
39
|
+
set val(v) {
|
|
40
|
+
this._val = v;
|
|
41
|
+
}
|
|
42
|
+
get sum() {
|
|
43
|
+
return this._sum;
|
|
44
|
+
}
|
|
45
|
+
set sum(v) {
|
|
46
|
+
this._sum = v;
|
|
47
|
+
}
|
|
48
|
+
get left() {
|
|
49
|
+
return this._left;
|
|
50
|
+
}
|
|
51
|
+
set left(v) {
|
|
52
|
+
this._left = v;
|
|
53
|
+
}
|
|
54
|
+
get right() {
|
|
55
|
+
return this._right;
|
|
56
|
+
}
|
|
57
|
+
set right(v) {
|
|
58
|
+
this._right = v;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
86
61
|
exports.SegmentTreeNode = SegmentTreeNode;
|
|
87
|
-
|
|
62
|
+
class SegmentTree {
|
|
88
63
|
/**
|
|
89
64
|
* The constructor initializes the values, start, end, and root properties of an object.
|
|
90
65
|
* @param {number[]} values - An array of numbers that will be used to build a binary search tree.
|
|
@@ -94,7 +69,7 @@ var SegmentTree = /** @class */ (function () {
|
|
|
94
69
|
* @param {number} [end] - The "end" parameter is the index of the last element in the "values" array that should be
|
|
95
70
|
* included in the range. If not provided, it defaults to the index of the last element in the "values" array.
|
|
96
71
|
*/
|
|
97
|
-
|
|
72
|
+
constructor(values, start, end) {
|
|
98
73
|
this._values = [];
|
|
99
74
|
this._start = 0;
|
|
100
75
|
start = start || 0;
|
|
@@ -104,34 +79,18 @@ var SegmentTree = /** @class */ (function () {
|
|
|
104
79
|
this._end = end;
|
|
105
80
|
this._root = this.build(start, end);
|
|
106
81
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
configurable: true
|
|
120
|
-
});
|
|
121
|
-
Object.defineProperty(SegmentTree.prototype, "end", {
|
|
122
|
-
get: function () {
|
|
123
|
-
return this._end;
|
|
124
|
-
},
|
|
125
|
-
enumerable: false,
|
|
126
|
-
configurable: true
|
|
127
|
-
});
|
|
128
|
-
Object.defineProperty(SegmentTree.prototype, "root", {
|
|
129
|
-
get: function () {
|
|
130
|
-
return this._root;
|
|
131
|
-
},
|
|
132
|
-
enumerable: false,
|
|
133
|
-
configurable: true
|
|
134
|
-
});
|
|
82
|
+
get values() {
|
|
83
|
+
return this._values;
|
|
84
|
+
}
|
|
85
|
+
get start() {
|
|
86
|
+
return this._start;
|
|
87
|
+
}
|
|
88
|
+
get end() {
|
|
89
|
+
return this._end;
|
|
90
|
+
}
|
|
91
|
+
get root() {
|
|
92
|
+
return this._root;
|
|
93
|
+
}
|
|
135
94
|
/**
|
|
136
95
|
* The function builds a segment tree by recursively dividing the given range into smaller segments and creating nodes
|
|
137
96
|
* for each segment.
|
|
@@ -141,17 +100,17 @@ var SegmentTree = /** @class */ (function () {
|
|
|
141
100
|
* building the segment tree.
|
|
142
101
|
* @returns a SegmentTreeNode object.
|
|
143
102
|
*/
|
|
144
|
-
|
|
103
|
+
build(start, end) {
|
|
145
104
|
if (start === end)
|
|
146
105
|
return new SegmentTreeNode(start, end, this._values[start]);
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
106
|
+
const mid = start + Math.floor((end - start) / 2);
|
|
107
|
+
const left = this.build(start, mid);
|
|
108
|
+
const right = this.build(mid + 1, end);
|
|
109
|
+
const cur = new SegmentTreeNode(start, end, left.sum + right.sum);
|
|
151
110
|
cur.left = left;
|
|
152
111
|
cur.right = right;
|
|
153
112
|
return cur;
|
|
154
|
-
}
|
|
113
|
+
}
|
|
155
114
|
/**
|
|
156
115
|
* The function updates the value of a node in a segment tree and recalculates the sum of its children if they exist.
|
|
157
116
|
* @param {number} index - The index parameter represents the index of the node in the segment tree that needs to be
|
|
@@ -163,18 +122,18 @@ var SegmentTree = /** @class */ (function () {
|
|
|
163
122
|
* cur.val = val;` and pass a value for `val` in the
|
|
164
123
|
* @returns The function does not return anything.
|
|
165
124
|
*/
|
|
166
|
-
|
|
167
|
-
|
|
125
|
+
updateNode(index, sum, val) {
|
|
126
|
+
const root = this.root || null;
|
|
168
127
|
if (!root) {
|
|
169
128
|
return;
|
|
170
129
|
}
|
|
171
|
-
|
|
130
|
+
const dfs = (cur, index, sum, val) => {
|
|
172
131
|
if (cur.start === cur.end && cur.start === index) {
|
|
173
132
|
cur.sum = sum;
|
|
174
133
|
// cur.val = val;
|
|
175
134
|
return;
|
|
176
135
|
}
|
|
177
|
-
|
|
136
|
+
const mid = cur.start + Math.floor((cur.end - cur.start) / 2);
|
|
178
137
|
if (index <= mid) {
|
|
179
138
|
if (cur.left) {
|
|
180
139
|
dfs(cur.left, index, sum, val);
|
|
@@ -190,7 +149,7 @@ var SegmentTree = /** @class */ (function () {
|
|
|
190
149
|
}
|
|
191
150
|
};
|
|
192
151
|
dfs(root, index, sum);
|
|
193
|
-
}
|
|
152
|
+
}
|
|
194
153
|
/**
|
|
195
154
|
* The function `querySumByRange` calculates the sum of values within a given range in a segment tree.
|
|
196
155
|
* @param {number} indexA - The starting index of the range for which you want to calculate the sum.
|
|
@@ -198,16 +157,16 @@ var SegmentTree = /** @class */ (function () {
|
|
|
198
157
|
* calculate the sum.
|
|
199
158
|
* @returns The function `querySumByRange` returns a number.
|
|
200
159
|
*/
|
|
201
|
-
|
|
202
|
-
|
|
160
|
+
querySumByRange(indexA, indexB) {
|
|
161
|
+
const root = this.root || null;
|
|
203
162
|
if (!root) {
|
|
204
163
|
return 0;
|
|
205
164
|
}
|
|
206
|
-
|
|
165
|
+
const dfs = (cur, i, j) => {
|
|
207
166
|
if (cur.start === i && cur.end === j) {
|
|
208
167
|
return cur.sum;
|
|
209
168
|
}
|
|
210
|
-
|
|
169
|
+
const mid = cur.start + Math.floor((cur.end - cur.start) / 2);
|
|
211
170
|
if (j <= mid) {
|
|
212
171
|
// TODO after no-non-null-assertion not ensure the logic
|
|
213
172
|
if (cur.left) {
|
|
@@ -238,19 +197,18 @@ var SegmentTree = /** @class */ (function () {
|
|
|
238
197
|
}
|
|
239
198
|
};
|
|
240
199
|
return dfs(root, indexA, indexB);
|
|
241
|
-
}
|
|
242
|
-
|
|
200
|
+
}
|
|
201
|
+
_setValues(value) {
|
|
243
202
|
this._values = value;
|
|
244
|
-
}
|
|
245
|
-
|
|
203
|
+
}
|
|
204
|
+
_setStart(value) {
|
|
246
205
|
this._start = value;
|
|
247
|
-
}
|
|
248
|
-
|
|
206
|
+
}
|
|
207
|
+
_setEnd(value) {
|
|
249
208
|
this._end = value;
|
|
250
|
-
}
|
|
251
|
-
|
|
209
|
+
}
|
|
210
|
+
_setRoot(v) {
|
|
252
211
|
this._root = v;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
}());
|
|
212
|
+
}
|
|
213
|
+
}
|
|
256
214
|
exports.SegmentTree = SegmentTree;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SplayTree = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
return SplayTree;
|
|
8
|
-
}());
|
|
4
|
+
class SplayTree {
|
|
5
|
+
}
|
|
9
6
|
exports.SplayTree = SplayTree;
|