stack-typed 2.5.1 → 2.5.3
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/cjs/index.cjs +132 -55
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +131 -54
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +132 -56
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +131 -55
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/common/error.d.ts +9 -0
- package/dist/types/common/index.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +86 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +98 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +189 -13
- package/dist/types/data-structures/binary-tree/bst.d.ts +270 -3
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +136 -8
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +42 -0
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +1089 -161
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1243 -350
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +980 -255
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +1174 -284
- package/dist/types/data-structures/graph/directed-graph.d.ts +70 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +63 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +84 -6
- package/dist/types/data-structures/heap/heap.d.ts +140 -12
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +126 -0
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +106 -1
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +126 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +56 -0
- package/dist/types/data-structures/queue/deque.d.ts +127 -0
- package/dist/types/data-structures/queue/queue.d.ts +97 -0
- package/dist/types/data-structures/stack/stack.d.ts +72 -2
- package/dist/types/data-structures/trie/trie.d.ts +84 -0
- package/dist/types/interfaces/binary-tree.d.ts +2 -3
- package/dist/types/types/data-structures/binary-tree/bst.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
- package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
- package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
- package/dist/umd/stack-typed.js +129 -53
- package/dist/umd/stack-typed.js.map +1 -1
- package/dist/umd/stack-typed.min.js +1 -1
- package/dist/umd/stack-typed.min.js.map +1 -1
- package/package.json +2 -2
- package/src/common/error.ts +19 -1
- package/src/common/index.ts +1 -1
- package/src/data-structures/base/iterable-element-base.ts +3 -2
- package/src/data-structures/binary-tree/avl-tree.ts +99 -5
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +102 -4
- package/src/data-structures/binary-tree/binary-tree.ts +239 -78
- package/src/data-structures/binary-tree/bst.ts +542 -13
- package/src/data-structures/binary-tree/red-black-tree.ts +155 -15
- package/src/data-structures/binary-tree/segment-tree.ts +42 -0
- package/src/data-structures/binary-tree/tree-map.ts +1223 -261
- package/src/data-structures/binary-tree/tree-multi-map.ts +939 -30
- package/src/data-structures/binary-tree/tree-multi-set.ts +746 -10
- package/src/data-structures/binary-tree/tree-set.ts +1018 -99
- package/src/data-structures/graph/abstract-graph.ts +2 -2
- package/src/data-structures/graph/directed-graph.ts +71 -1
- package/src/data-structures/graph/undirected-graph.ts +64 -1
- package/src/data-structures/hash/hash-map.ts +102 -16
- package/src/data-structures/heap/heap.ts +153 -23
- package/src/data-structures/heap/max-heap.ts +2 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +139 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +106 -1
- package/src/data-structures/linked-list/skip-linked-list.ts +131 -5
- package/src/data-structures/matrix/matrix.ts +65 -9
- package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
- package/src/data-structures/queue/deque.ts +130 -0
- package/src/data-structures/queue/queue.ts +109 -0
- package/src/data-structures/stack/stack.ts +75 -5
- package/src/data-structures/trie/trie.ts +86 -2
- package/src/interfaces/binary-tree.ts +1 -9
- package/src/types/data-structures/binary-tree/bst.ts +1 -0
- package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
- package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
- package/src/types/data-structures/binary-tree/tree-set.ts +5 -0
|
@@ -242,6 +242,13 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
242
242
|
|
|
243
243
|
|
|
244
244
|
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
|
|
245
252
|
|
|
246
253
|
|
|
247
254
|
|
|
@@ -293,6 +300,13 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
293
300
|
|
|
294
301
|
|
|
295
302
|
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
|
|
296
310
|
|
|
297
311
|
|
|
298
312
|
|
|
@@ -339,6 +353,13 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
339
353
|
|
|
340
354
|
|
|
341
355
|
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
|
|
342
363
|
|
|
343
364
|
|
|
344
365
|
|
|
@@ -381,6 +402,13 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
381
402
|
|
|
382
403
|
|
|
383
404
|
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
|
|
384
412
|
|
|
385
413
|
|
|
386
414
|
|
|
@@ -422,6 +450,13 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
422
450
|
|
|
423
451
|
|
|
424
452
|
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
|
|
425
460
|
|
|
426
461
|
|
|
427
462
|
|
|
@@ -466,6 +501,13 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
466
501
|
|
|
467
502
|
|
|
468
503
|
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
|
|
469
511
|
|
|
470
512
|
|
|
471
513
|
|
|
@@ -535,6 +577,13 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
535
577
|
|
|
536
578
|
|
|
537
579
|
|
|
580
|
+
|
|
581
|
+
|
|
582
|
+
|
|
583
|
+
|
|
584
|
+
|
|
585
|
+
|
|
586
|
+
|
|
538
587
|
|
|
539
588
|
|
|
540
589
|
|
|
@@ -587,6 +636,13 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
587
636
|
|
|
588
637
|
|
|
589
638
|
|
|
639
|
+
|
|
640
|
+
|
|
641
|
+
|
|
642
|
+
|
|
643
|
+
|
|
644
|
+
|
|
645
|
+
|
|
590
646
|
|
|
591
647
|
|
|
592
648
|
|
|
@@ -633,6 +689,13 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
633
689
|
|
|
634
690
|
|
|
635
691
|
|
|
692
|
+
|
|
693
|
+
|
|
694
|
+
|
|
695
|
+
|
|
696
|
+
|
|
697
|
+
|
|
698
|
+
|
|
636
699
|
|
|
637
700
|
|
|
638
701
|
|
|
@@ -679,6 +742,13 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
679
742
|
|
|
680
743
|
|
|
681
744
|
|
|
745
|
+
|
|
746
|
+
|
|
747
|
+
|
|
748
|
+
|
|
749
|
+
|
|
750
|
+
|
|
751
|
+
|
|
682
752
|
|
|
683
753
|
|
|
684
754
|
|
|
@@ -722,6 +792,13 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
722
792
|
|
|
723
793
|
|
|
724
794
|
|
|
795
|
+
|
|
796
|
+
|
|
797
|
+
|
|
798
|
+
|
|
799
|
+
|
|
800
|
+
|
|
801
|
+
|
|
725
802
|
|
|
726
803
|
|
|
727
804
|
|
|
@@ -760,6 +837,13 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
760
837
|
|
|
761
838
|
|
|
762
839
|
|
|
840
|
+
|
|
841
|
+
|
|
842
|
+
|
|
843
|
+
|
|
844
|
+
|
|
845
|
+
|
|
846
|
+
|
|
763
847
|
|
|
764
848
|
|
|
765
849
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BinaryTreeNode } from '../data-structures';
|
|
2
|
-
import type {
|
|
2
|
+
import type { BinaryTreeOptions, BTNRep, DFSOrderPattern, EntryCallback, IterationType, NodeCallback, NodePredicate, OptNodeOrNull, ReduceEntryCallback, ToEntryFn } from '../types';
|
|
3
3
|
/**
|
|
4
4
|
* Public, implementation-agnostic binary tree API.
|
|
5
5
|
* K = key, V = value, R = raw/record used with toEntryFn (optional).
|
|
@@ -19,7 +19,7 @@ export interface IBinaryTree<K = any, V = any, R = any> {
|
|
|
19
19
|
add(keyOrNodeOrEntryOrRawElement: BTNRep<K, V, BinaryTreeNode<K, V>>, value?: V, count?: number): boolean;
|
|
20
20
|
set(keyOrNodeOrEntryOrRawElement: BTNRep<K, V, BinaryTreeNode<K, V>>, value?: V, count?: number): boolean;
|
|
21
21
|
addMany(keysNodesEntriesOrRaws: Iterable<K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, values?: Iterable<V | undefined>): boolean[];
|
|
22
|
-
delete(keyNodeEntryRawOrPredicate: BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V> | null>):
|
|
22
|
+
delete(keyNodeEntryRawOrPredicate: BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V> | null>): boolean;
|
|
23
23
|
clear(): void;
|
|
24
24
|
isEmpty(): boolean;
|
|
25
25
|
get(keyNodeEntryOrPredicate: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): V | undefined;
|
|
@@ -56,5 +56,4 @@ export interface IBinaryTree<K = any, V = any, R = any> {
|
|
|
56
56
|
filter(predicate: EntryCallback<K, V | undefined, boolean>, thisArg?: unknown): this;
|
|
57
57
|
map<MK = K, MV = V, MR = any>(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: Partial<BinaryTreeOptions<MK, MV, MR>>, thisArg?: unknown): IBinaryTree<MK, MV, MR>;
|
|
58
58
|
merge(anotherTree: IBinaryTree<K, V, R>): void;
|
|
59
|
-
refill(keysNodesEntriesOrRaws: Iterable<K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, values?: Iterable<V | undefined>): void;
|
|
60
59
|
}
|
|
@@ -3,6 +3,7 @@ import type { Comparator, OptValue } from '../../common';
|
|
|
3
3
|
type BSTBaseOptions<K, V, R> = Omit<BinaryTreeOptions<K, V, R>, 'isDuplicate'>;
|
|
4
4
|
export type BSTOptions<K, V, R> = BSTBaseOptions<K, V, R> & {
|
|
5
5
|
comparator?: Comparator<K>;
|
|
6
|
+
enableOrderStatistic?: boolean;
|
|
6
7
|
};
|
|
7
8
|
export type BSTNOptKey<K> = K | undefined;
|
|
8
9
|
export type OptNode<NODE> = NODE | undefined;
|
|
@@ -8,6 +8,11 @@ export interface TreeMapOptions<K, V, R = [K, V]> {
|
|
|
8
8
|
* - `false`: store values on tree nodes (Node Mode).
|
|
9
9
|
*/
|
|
10
10
|
isMapMode?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Enable order-statistic operations (select, rank, rangeByRank).
|
|
13
|
+
* When true, subtree counts are maintained on every node.
|
|
14
|
+
*/
|
|
15
|
+
enableOrderStatistic?: boolean;
|
|
11
16
|
/**
|
|
12
17
|
* Transform raw elements into `[key, value]` entries.
|
|
13
18
|
* When provided, the constructor accepts `Iterable<R>` instead of `Iterable<[K, V]>`.
|
|
@@ -8,6 +8,10 @@ export interface TreeMultiSetOptions<K, R = K> {
|
|
|
8
8
|
* - `false`: Node Mode.
|
|
9
9
|
*/
|
|
10
10
|
isMapMode?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Enable order-statistic operations (select, rank, rangeByRank).
|
|
13
|
+
*/
|
|
14
|
+
enableOrderStatistic?: boolean;
|
|
11
15
|
/**
|
|
12
16
|
* Transform raw elements into keys.
|
|
13
17
|
* When provided, the constructor accepts `Iterable<R>` instead of `Iterable<K>`.
|
|
@@ -8,6 +8,10 @@ export interface TreeSetOptions<K, R = K> {
|
|
|
8
8
|
* - `false`: store values on tree nodes (Node Mode).
|
|
9
9
|
*/
|
|
10
10
|
isMapMode?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Enable order-statistic operations (select, rank, rangeByRank).
|
|
13
|
+
*/
|
|
14
|
+
enableOrderStatistic?: boolean;
|
|
11
15
|
/**
|
|
12
16
|
* Transform raw elements into keys.
|
|
13
17
|
* When provided, the constructor accepts `Iterable<R>` instead of `Iterable<K>`.
|
package/dist/umd/stack-typed.js
CHANGED
|
@@ -26,9 +26,61 @@ var stackTyped = (() => {
|
|
|
26
26
|
DFSOperation: () => DFSOperation,
|
|
27
27
|
ERR: () => ERR,
|
|
28
28
|
Range: () => Range,
|
|
29
|
-
Stack: () => Stack
|
|
29
|
+
Stack: () => Stack,
|
|
30
|
+
raise: () => raise
|
|
30
31
|
});
|
|
31
32
|
|
|
33
|
+
// src/common/error.ts
|
|
34
|
+
function raise(ErrorClass, message) {
|
|
35
|
+
throw new ErrorClass(message);
|
|
36
|
+
}
|
|
37
|
+
var ERR = {
|
|
38
|
+
// Range / index
|
|
39
|
+
indexOutOfRange: (index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`,
|
|
40
|
+
invalidIndex: (ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`,
|
|
41
|
+
// Type / argument
|
|
42
|
+
invalidArgument: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
|
|
43
|
+
comparatorRequired: (ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`,
|
|
44
|
+
invalidKey: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
|
|
45
|
+
notAFunction: (name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`,
|
|
46
|
+
invalidEntry: (ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`,
|
|
47
|
+
invalidNaN: (ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`,
|
|
48
|
+
invalidDate: (ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`,
|
|
49
|
+
reduceEmpty: (ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`,
|
|
50
|
+
callbackReturnType: (expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`,
|
|
51
|
+
// State / operation
|
|
52
|
+
invalidOperation: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
|
|
53
|
+
// Matrix
|
|
54
|
+
matrixDimensionMismatch: (op) => `Matrix: Dimensions must be compatible for ${op}.`,
|
|
55
|
+
matrixSingular: () => "Matrix: Singular matrix, inverse does not exist.",
|
|
56
|
+
matrixNotSquare: () => "Matrix: Must be square for inversion.",
|
|
57
|
+
matrixNotRectangular: () => "Matrix: Must be rectangular for transposition.",
|
|
58
|
+
matrixRowMismatch: (expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`,
|
|
59
|
+
// Order statistic
|
|
60
|
+
orderStatisticNotEnabled: (method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// src/common/index.ts
|
|
64
|
+
var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
|
|
65
|
+
DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
|
|
66
|
+
DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
|
|
67
|
+
return DFSOperation2;
|
|
68
|
+
})(DFSOperation || {});
|
|
69
|
+
var Range = class {
|
|
70
|
+
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
71
|
+
this.low = low;
|
|
72
|
+
this.high = high;
|
|
73
|
+
this.includeLow = includeLow;
|
|
74
|
+
this.includeHigh = includeHigh;
|
|
75
|
+
}
|
|
76
|
+
// Determine whether a key is within the range
|
|
77
|
+
isInRange(key, comparator) {
|
|
78
|
+
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
79
|
+
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
80
|
+
return lowCheck && highCheck;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
32
84
|
// src/data-structures/base/iterable-element-base.ts
|
|
33
85
|
var IterableElementBase = class {
|
|
34
86
|
/**
|
|
@@ -51,7 +103,7 @@ var stackTyped = (() => {
|
|
|
51
103
|
if (options) {
|
|
52
104
|
const { toElementFn } = options;
|
|
53
105
|
if (typeof toElementFn === "function") this._toElementFn = toElementFn;
|
|
54
|
-
else if (toElementFn)
|
|
106
|
+
else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
|
|
55
107
|
}
|
|
56
108
|
}
|
|
57
109
|
/**
|
|
@@ -207,7 +259,7 @@ var stackTyped = (() => {
|
|
|
207
259
|
acc = initialValue;
|
|
208
260
|
} else {
|
|
209
261
|
const first = iter.next();
|
|
210
|
-
if (first.done)
|
|
262
|
+
if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
|
|
211
263
|
acc = first.value;
|
|
212
264
|
index = 1;
|
|
213
265
|
}
|
|
@@ -298,6 +350,13 @@ var stackTyped = (() => {
|
|
|
298
350
|
|
|
299
351
|
|
|
300
352
|
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
|
|
301
360
|
|
|
302
361
|
|
|
303
362
|
|
|
@@ -355,6 +414,13 @@ var stackTyped = (() => {
|
|
|
355
414
|
|
|
356
415
|
|
|
357
416
|
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
|
|
358
424
|
|
|
359
425
|
|
|
360
426
|
|
|
@@ -401,6 +467,13 @@ var stackTyped = (() => {
|
|
|
401
467
|
|
|
402
468
|
|
|
403
469
|
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
|
|
404
477
|
|
|
405
478
|
|
|
406
479
|
|
|
@@ -447,6 +520,13 @@ var stackTyped = (() => {
|
|
|
447
520
|
|
|
448
521
|
|
|
449
522
|
|
|
523
|
+
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
|
|
450
530
|
|
|
451
531
|
|
|
452
532
|
|
|
@@ -502,6 +582,13 @@ var stackTyped = (() => {
|
|
|
502
582
|
|
|
503
583
|
|
|
504
584
|
|
|
585
|
+
|
|
586
|
+
|
|
587
|
+
|
|
588
|
+
|
|
589
|
+
|
|
590
|
+
|
|
591
|
+
|
|
505
592
|
|
|
506
593
|
|
|
507
594
|
|
|
@@ -572,6 +659,13 @@ var stackTyped = (() => {
|
|
|
572
659
|
|
|
573
660
|
|
|
574
661
|
|
|
662
|
+
|
|
663
|
+
|
|
664
|
+
|
|
665
|
+
|
|
666
|
+
|
|
667
|
+
|
|
668
|
+
|
|
575
669
|
|
|
576
670
|
|
|
577
671
|
|
|
@@ -588,18 +682,18 @@ var stackTyped = (() => {
|
|
|
588
682
|
*/
|
|
589
683
|
delete(element) {
|
|
590
684
|
const idx = this._indexOfByEquals(element);
|
|
591
|
-
return this.deleteAt(idx);
|
|
685
|
+
return this.deleteAt(idx) !== void 0;
|
|
592
686
|
}
|
|
593
687
|
/**
|
|
594
688
|
* Delete the element at an index.
|
|
595
689
|
* @remarks Time O(N), Space O(1)
|
|
596
690
|
* @param index - Zero-based index from the bottom.
|
|
597
|
-
* @returns
|
|
691
|
+
* @returns The removed element, or undefined if the index is out of range.
|
|
598
692
|
*/
|
|
599
693
|
deleteAt(index) {
|
|
600
|
-
if (index < 0 || index >= this.elements.length) return
|
|
694
|
+
if (index < 0 || index >= this.elements.length) return void 0;
|
|
601
695
|
const spliced = this.elements.splice(index, 1);
|
|
602
|
-
return spliced
|
|
696
|
+
return spliced[0];
|
|
603
697
|
}
|
|
604
698
|
/**
|
|
605
699
|
* Delete the first element that satisfies a predicate.
|
|
@@ -642,6 +736,13 @@ var stackTyped = (() => {
|
|
|
642
736
|
|
|
643
737
|
|
|
644
738
|
|
|
739
|
+
|
|
740
|
+
|
|
741
|
+
|
|
742
|
+
|
|
743
|
+
|
|
744
|
+
|
|
745
|
+
|
|
645
746
|
|
|
646
747
|
|
|
647
748
|
|
|
@@ -685,6 +786,13 @@ var stackTyped = (() => {
|
|
|
685
786
|
|
|
686
787
|
|
|
687
788
|
|
|
789
|
+
|
|
790
|
+
|
|
791
|
+
|
|
792
|
+
|
|
793
|
+
|
|
794
|
+
|
|
795
|
+
|
|
688
796
|
|
|
689
797
|
|
|
690
798
|
|
|
@@ -734,6 +842,13 @@ var stackTyped = (() => {
|
|
|
734
842
|
|
|
735
843
|
|
|
736
844
|
|
|
845
|
+
|
|
846
|
+
|
|
847
|
+
|
|
848
|
+
|
|
849
|
+
|
|
850
|
+
|
|
851
|
+
|
|
737
852
|
|
|
738
853
|
|
|
739
854
|
|
|
@@ -803,6 +918,13 @@ var stackTyped = (() => {
|
|
|
803
918
|
|
|
804
919
|
|
|
805
920
|
|
|
921
|
+
|
|
922
|
+
|
|
923
|
+
|
|
924
|
+
|
|
925
|
+
|
|
926
|
+
|
|
927
|
+
|
|
806
928
|
|
|
807
929
|
|
|
808
930
|
|
|
@@ -878,52 +1000,6 @@ var stackTyped = (() => {
|
|
|
878
1000
|
for (let i = 0; i < this.elements.length; i++) yield this.elements[i];
|
|
879
1001
|
}
|
|
880
1002
|
};
|
|
881
|
-
|
|
882
|
-
// src/common/error.ts
|
|
883
|
-
var ERR = {
|
|
884
|
-
// Range / index
|
|
885
|
-
indexOutOfRange: (index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`,
|
|
886
|
-
invalidIndex: (ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`,
|
|
887
|
-
// Type / argument
|
|
888
|
-
invalidArgument: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
|
|
889
|
-
comparatorRequired: (ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`,
|
|
890
|
-
invalidKey: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
|
|
891
|
-
notAFunction: (name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`,
|
|
892
|
-
invalidEntry: (ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`,
|
|
893
|
-
invalidNaN: (ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`,
|
|
894
|
-
invalidDate: (ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`,
|
|
895
|
-
reduceEmpty: (ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`,
|
|
896
|
-
callbackReturnType: (expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`,
|
|
897
|
-
// State / operation
|
|
898
|
-
invalidOperation: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
|
|
899
|
-
// Matrix
|
|
900
|
-
matrixDimensionMismatch: (op) => `Matrix: Dimensions must be compatible for ${op}.`,
|
|
901
|
-
matrixSingular: () => "Matrix: Singular matrix, inverse does not exist.",
|
|
902
|
-
matrixNotSquare: () => "Matrix: Must be square for inversion.",
|
|
903
|
-
matrixNotRectangular: () => "Matrix: Must be rectangular for transposition.",
|
|
904
|
-
matrixRowMismatch: (expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`
|
|
905
|
-
};
|
|
906
|
-
|
|
907
|
-
// src/common/index.ts
|
|
908
|
-
var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
|
|
909
|
-
DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
|
|
910
|
-
DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
|
|
911
|
-
return DFSOperation2;
|
|
912
|
-
})(DFSOperation || {});
|
|
913
|
-
var Range = class {
|
|
914
|
-
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
915
|
-
this.low = low;
|
|
916
|
-
this.high = high;
|
|
917
|
-
this.includeLow = includeLow;
|
|
918
|
-
this.includeHigh = includeHigh;
|
|
919
|
-
}
|
|
920
|
-
// Determine whether a key is within the range
|
|
921
|
-
isInRange(key, comparator) {
|
|
922
|
-
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
923
|
-
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
924
|
-
return lowCheck && highCheck;
|
|
925
|
-
}
|
|
926
|
-
};
|
|
927
1003
|
return __toCommonJS(src_exports);
|
|
928
1004
|
})();
|
|
929
1005
|
/**
|