min-heap-typed 1.50.4 → 1.50.6
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/base/iterable-base.d.ts +10 -8
- package/dist/data-structures/base/iterable-base.js +8 -12
- package/dist/data-structures/binary-tree/binary-tree.js +19 -19
- package/dist/data-structures/binary-tree/rb-tree.d.ts +158 -135
- package/dist/data-structures/binary-tree/rb-tree.js +415 -386
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +1 -0
- package/dist/data-structures/binary-tree/tree-multi-map.js +84 -76
- package/dist/data-structures/graph/abstract-graph.d.ts +1 -0
- package/dist/data-structures/graph/abstract-graph.js +3 -0
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +14 -76
- package/dist/data-structures/linked-list/doubly-linked-list.js +16 -86
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +27 -69
- package/dist/data-structures/linked-list/singly-linked-list.js +35 -79
- package/dist/data-structures/queue/deque.d.ts +0 -53
- package/dist/data-structures/queue/deque.js +0 -61
- package/dist/data-structures/queue/queue.d.ts +0 -70
- package/dist/data-structures/queue/queue.js +0 -87
- package/package.json +2 -2
- package/src/data-structures/base/iterable-base.ts +14 -10
- package/src/data-structures/binary-tree/binary-tree.ts +19 -19
- package/src/data-structures/binary-tree/rb-tree.ts +437 -395
- package/src/data-structures/binary-tree/tree-multi-map.ts +85 -82
- package/src/data-structures/graph/abstract-graph.ts +4 -0
- package/src/data-structures/heap/heap.ts +1 -1
- package/src/data-structures/linked-list/doubly-linked-list.ts +16 -94
- package/src/data-structures/linked-list/singly-linked-list.ts +35 -87
- package/src/data-structures/queue/deque.ts +0 -67
- package/src/data-structures/queue/queue.ts +0 -98
|
@@ -4,6 +4,7 @@ export declare abstract class IterableEntryBase<K = any, V = any> {
|
|
|
4
4
|
* Time Complexity: O(n)
|
|
5
5
|
* Space Complexity: O(1)
|
|
6
6
|
*/
|
|
7
|
+
abstract get size(): number;
|
|
7
8
|
/**
|
|
8
9
|
* Time Complexity: O(n)
|
|
9
10
|
* Space Complexity: O(1)
|
|
@@ -91,6 +92,10 @@ export declare abstract class IterableEntryBase<K = any, V = any> {
|
|
|
91
92
|
* Time Complexity: O(n)
|
|
92
93
|
* Space Complexity: O(1)
|
|
93
94
|
*/
|
|
95
|
+
/**
|
|
96
|
+
* Time Complexity: O(n)
|
|
97
|
+
* Space Complexity: O(1)
|
|
98
|
+
*/
|
|
94
99
|
/**
|
|
95
100
|
* Time Complexity: O(n)
|
|
96
101
|
* Space Complexity: O(1)
|
|
@@ -171,10 +176,6 @@ export declare abstract class IterableEntryBase<K = any, V = any> {
|
|
|
171
176
|
* collection, otherwise it returns `undefined`.
|
|
172
177
|
*/
|
|
173
178
|
get(key: K): V | undefined;
|
|
174
|
-
/**
|
|
175
|
-
* Time Complexity: O(n)
|
|
176
|
-
* Space Complexity: O(1)
|
|
177
|
-
*/
|
|
178
179
|
/**
|
|
179
180
|
* Time Complexity: O(n)
|
|
180
181
|
* Space Complexity: O(1)
|
|
@@ -205,6 +206,7 @@ export declare abstract class IterableEntryBase<K = any, V = any> {
|
|
|
205
206
|
protected abstract _getIterator(...args: any[]): IterableIterator<[K, V]>;
|
|
206
207
|
}
|
|
207
208
|
export declare abstract class IterableElementBase<E = any, C = any> {
|
|
209
|
+
abstract get size(): number;
|
|
208
210
|
/**
|
|
209
211
|
* Time Complexity: O(n)
|
|
210
212
|
* Space Complexity: O(1)
|
|
@@ -253,6 +255,10 @@ export declare abstract class IterableElementBase<E = any, C = any> {
|
|
|
253
255
|
* Time Complexity: O(n)
|
|
254
256
|
* Space Complexity: O(1)
|
|
255
257
|
*/
|
|
258
|
+
/**
|
|
259
|
+
* Time Complexity: O(n)
|
|
260
|
+
* Space Complexity: O(1)
|
|
261
|
+
*/
|
|
256
262
|
/**
|
|
257
263
|
* Time Complexity: O(n)
|
|
258
264
|
* Space Complexity: O(1)
|
|
@@ -307,10 +313,6 @@ export declare abstract class IterableElementBase<E = any, C = any> {
|
|
|
307
313
|
* callback function. If no element satisfies the callback function, `undefined` is returned.
|
|
308
314
|
*/
|
|
309
315
|
find(callbackfn: ElementCallback<E, boolean>, thisArg?: any): E | undefined;
|
|
310
|
-
/**
|
|
311
|
-
* Time Complexity: O(n)
|
|
312
|
-
* Space Complexity: O(1)
|
|
313
|
-
*/
|
|
314
316
|
/**
|
|
315
317
|
* Time Complexity: O(n)
|
|
316
318
|
* Space Complexity: O(1)
|
|
@@ -2,10 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.IterableElementBase = exports.IterableEntryBase = void 0;
|
|
4
4
|
class IterableEntryBase {
|
|
5
|
-
/**
|
|
6
|
-
* Time Complexity: O(n)
|
|
7
|
-
* Space Complexity: O(1)
|
|
8
|
-
*/
|
|
9
5
|
/**
|
|
10
6
|
* Time Complexity: O(n)
|
|
11
7
|
* Space Complexity: O(1)
|
|
@@ -123,6 +119,10 @@ class IterableEntryBase {
|
|
|
123
119
|
* Time Complexity: O(n)
|
|
124
120
|
* Space Complexity: O(1)
|
|
125
121
|
*/
|
|
122
|
+
/**
|
|
123
|
+
* Time Complexity: O(n)
|
|
124
|
+
* Space Complexity: O(1)
|
|
125
|
+
*/
|
|
126
126
|
/**
|
|
127
127
|
* Time Complexity: O(n)
|
|
128
128
|
* Space Complexity: O(1)
|
|
@@ -237,10 +237,6 @@ class IterableEntryBase {
|
|
|
237
237
|
}
|
|
238
238
|
return;
|
|
239
239
|
}
|
|
240
|
-
/**
|
|
241
|
-
* Time Complexity: O(n)
|
|
242
|
-
* Space Complexity: O(1)
|
|
243
|
-
*/
|
|
244
240
|
/**
|
|
245
241
|
* Time Complexity: O(n)
|
|
246
242
|
* Space Complexity: O(1)
|
|
@@ -338,6 +334,10 @@ class IterableElementBase {
|
|
|
338
334
|
* Time Complexity: O(n)
|
|
339
335
|
* Space Complexity: O(1)
|
|
340
336
|
*/
|
|
337
|
+
/**
|
|
338
|
+
* Time Complexity: O(n)
|
|
339
|
+
* Space Complexity: O(1)
|
|
340
|
+
*/
|
|
341
341
|
/**
|
|
342
342
|
* Time Complexity: O(n)
|
|
343
343
|
* Space Complexity: O(1)
|
|
@@ -412,10 +412,6 @@ class IterableElementBase {
|
|
|
412
412
|
}
|
|
413
413
|
return;
|
|
414
414
|
}
|
|
415
|
-
/**
|
|
416
|
-
* Time Complexity: O(n)
|
|
417
|
-
* Space Complexity: O(1)
|
|
418
|
-
*/
|
|
419
415
|
/**
|
|
420
416
|
* Time Complexity: O(n)
|
|
421
417
|
* Space Complexity: O(1)
|
|
@@ -736,7 +736,7 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
736
736
|
return true;
|
|
737
737
|
if (iterationType === types_1.IterationType.RECURSIVE) {
|
|
738
738
|
const dfs = (cur, min, max) => {
|
|
739
|
-
if (!cur)
|
|
739
|
+
if (!this.isRealNode(cur))
|
|
740
740
|
return true;
|
|
741
741
|
const numKey = this.extractor(cur.key);
|
|
742
742
|
if (numKey <= min || numKey >= max)
|
|
@@ -753,14 +753,14 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
753
753
|
let prev = checkMax ? Number.MAX_SAFE_INTEGER : Number.MIN_SAFE_INTEGER;
|
|
754
754
|
// @ts-ignore
|
|
755
755
|
let curr = beginRoot;
|
|
756
|
-
while (curr || stack.length > 0) {
|
|
757
|
-
while (curr) {
|
|
756
|
+
while (this.isRealNode(curr) || stack.length > 0) {
|
|
757
|
+
while (this.isRealNode(curr)) {
|
|
758
758
|
stack.push(curr);
|
|
759
759
|
curr = curr.left;
|
|
760
760
|
}
|
|
761
761
|
curr = stack.pop();
|
|
762
762
|
const numKey = this.extractor(curr.key);
|
|
763
|
-
if (!curr || (!checkMax && prev >= numKey) || (checkMax && prev <= numKey))
|
|
763
|
+
if (!this.isRealNode(curr) || (!checkMax && prev >= numKey) || (checkMax && prev <= numKey))
|
|
764
764
|
return false;
|
|
765
765
|
prev = numKey;
|
|
766
766
|
curr = curr.right;
|
|
@@ -825,7 +825,7 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
825
825
|
return -1;
|
|
826
826
|
if (iterationType === types_1.IterationType.RECURSIVE) {
|
|
827
827
|
const _getMaxHeight = (cur) => {
|
|
828
|
-
if (!cur)
|
|
828
|
+
if (!this.isRealNode(cur))
|
|
829
829
|
return -1;
|
|
830
830
|
const leftHeight = _getMaxHeight(cur.left);
|
|
831
831
|
const rightHeight = _getMaxHeight(cur.right);
|
|
@@ -838,9 +838,9 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
838
838
|
let maxHeight = 0;
|
|
839
839
|
while (stack.length > 0) {
|
|
840
840
|
const { node, depth } = stack.pop();
|
|
841
|
-
if (node.left)
|
|
841
|
+
if (this.isRealNode(node.left))
|
|
842
842
|
stack.push({ node: node.left, depth: depth + 1 });
|
|
843
|
-
if (node.right)
|
|
843
|
+
if (this.isRealNode(node.right))
|
|
844
844
|
stack.push({ node: node.right, depth: depth + 1 });
|
|
845
845
|
maxHeight = Math.max(maxHeight, depth);
|
|
846
846
|
}
|
|
@@ -1117,48 +1117,48 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
1117
1117
|
switch (pattern) {
|
|
1118
1118
|
case 'in':
|
|
1119
1119
|
if (includeNull) {
|
|
1120
|
-
if (node && this.isNodeOrNull(node.left))
|
|
1120
|
+
if (this.isRealNode(node) && this.isNodeOrNull(node.left))
|
|
1121
1121
|
_traverse(node.left);
|
|
1122
1122
|
this.isNodeOrNull(node) && ans.push(callback(node));
|
|
1123
|
-
if (node && this.isNodeOrNull(node.right))
|
|
1123
|
+
if (this.isRealNode(node) && this.isNodeOrNull(node.right))
|
|
1124
1124
|
_traverse(node.right);
|
|
1125
1125
|
}
|
|
1126
1126
|
else {
|
|
1127
|
-
if (node && node.left)
|
|
1127
|
+
if (this.isRealNode(node) && this.isRealNode(node.left))
|
|
1128
1128
|
_traverse(node.left);
|
|
1129
1129
|
this.isRealNode(node) && ans.push(callback(node));
|
|
1130
|
-
if (node && node.right)
|
|
1130
|
+
if (this.isRealNode(node) && this.isRealNode(node.right))
|
|
1131
1131
|
_traverse(node.right);
|
|
1132
1132
|
}
|
|
1133
1133
|
break;
|
|
1134
1134
|
case 'pre':
|
|
1135
1135
|
if (includeNull) {
|
|
1136
1136
|
this.isNodeOrNull(node) && ans.push(callback(node));
|
|
1137
|
-
if (node && this.isNodeOrNull(node.left))
|
|
1137
|
+
if (this.isRealNode(node) && this.isNodeOrNull(node.left))
|
|
1138
1138
|
_traverse(node.left);
|
|
1139
|
-
if (node && this.isNodeOrNull(node.right))
|
|
1139
|
+
if (this.isRealNode(node) && this.isNodeOrNull(node.right))
|
|
1140
1140
|
_traverse(node.right);
|
|
1141
1141
|
}
|
|
1142
1142
|
else {
|
|
1143
1143
|
this.isRealNode(node) && ans.push(callback(node));
|
|
1144
|
-
if (node && node.left)
|
|
1144
|
+
if (this.isRealNode(node) && this.isRealNode(node.left))
|
|
1145
1145
|
_traverse(node.left);
|
|
1146
|
-
if (node && node.right)
|
|
1146
|
+
if (this.isRealNode(node) && this.isRealNode(node.right))
|
|
1147
1147
|
_traverse(node.right);
|
|
1148
1148
|
}
|
|
1149
1149
|
break;
|
|
1150
1150
|
case 'post':
|
|
1151
1151
|
if (includeNull) {
|
|
1152
|
-
if (node && this.isNodeOrNull(node.left))
|
|
1152
|
+
if (this.isRealNode(node) && this.isNodeOrNull(node.left))
|
|
1153
1153
|
_traverse(node.left);
|
|
1154
|
-
if (node && this.isNodeOrNull(node.right))
|
|
1154
|
+
if (this.isRealNode(node) && this.isNodeOrNull(node.right))
|
|
1155
1155
|
_traverse(node.right);
|
|
1156
1156
|
this.isNodeOrNull(node) && ans.push(callback(node));
|
|
1157
1157
|
}
|
|
1158
1158
|
else {
|
|
1159
|
-
if (node && node.left)
|
|
1159
|
+
if (this.isRealNode(node) && this.isRealNode(node.left))
|
|
1160
1160
|
_traverse(node.left);
|
|
1161
|
-
if (node && node.right)
|
|
1161
|
+
if (this.isRealNode(node) && this.isRealNode(node.right))
|
|
1162
1162
|
_traverse(node.right);
|
|
1163
1163
|
this.isRealNode(node) && ans.push(callback(node));
|
|
1164
1164
|
}
|