stack-typed 2.4.5 → 2.5.0
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 +6 -36
- package/dist/cjs/index.cjs +270 -100
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +269 -99
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +270 -100
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +269 -99
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/data-structures/base/iterable-element-base.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +128 -51
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +210 -164
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +429 -78
- package/dist/types/data-structures/binary-tree/bst.d.ts +311 -28
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +212 -32
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +218 -152
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +1281 -5
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1087 -201
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +858 -65
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +1133 -5
- package/dist/types/data-structures/graph/directed-graph.d.ts +219 -47
- package/dist/types/data-structures/graph/map-graph.d.ts +59 -1
- package/dist/types/data-structures/graph/undirected-graph.d.ts +204 -59
- package/dist/types/data-structures/hash/hash-map.d.ts +230 -77
- package/dist/types/data-structures/heap/heap.d.ts +287 -99
- package/dist/types/data-structures/heap/max-heap.d.ts +46 -0
- package/dist/types/data-structures/heap/min-heap.d.ts +59 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +286 -44
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +278 -65
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +415 -12
- package/dist/types/data-structures/matrix/matrix.d.ts +331 -0
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +57 -0
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +60 -0
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +60 -0
- package/dist/types/data-structures/queue/deque.d.ts +272 -65
- package/dist/types/data-structures/queue/queue.d.ts +211 -42
- package/dist/types/data-structures/stack/stack.d.ts +174 -32
- package/dist/types/data-structures/trie/trie.d.ts +213 -43
- package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -1
- package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +1 -4
- package/dist/umd/stack-typed.js +267 -97
- 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/data-structures/base/iterable-element-base.ts +4 -5
- package/src/data-structures/binary-tree/avl-tree.ts +134 -51
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +302 -247
- package/src/data-structures/binary-tree/binary-tree.ts +429 -79
- package/src/data-structures/binary-tree/bst.ts +335 -34
- package/src/data-structures/binary-tree/red-black-tree.ts +290 -97
- package/src/data-structures/binary-tree/segment-tree.ts +372 -248
- package/src/data-structures/binary-tree/tree-map.ts +1284 -6
- package/src/data-structures/binary-tree/tree-multi-map.ts +1094 -211
- package/src/data-structures/binary-tree/tree-multi-set.ts +858 -65
- package/src/data-structures/binary-tree/tree-set.ts +1136 -9
- package/src/data-structures/graph/directed-graph.ts +219 -47
- package/src/data-structures/graph/map-graph.ts +59 -1
- package/src/data-structures/graph/undirected-graph.ts +204 -59
- package/src/data-structures/hash/hash-map.ts +230 -77
- package/src/data-structures/heap/heap.ts +287 -99
- package/src/data-structures/heap/max-heap.ts +46 -0
- package/src/data-structures/heap/min-heap.ts +59 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +286 -44
- package/src/data-structures/linked-list/singly-linked-list.ts +278 -65
- package/src/data-structures/linked-list/skip-linked-list.ts +689 -90
- package/src/data-structures/matrix/matrix.ts +416 -12
- package/src/data-structures/priority-queue/max-priority-queue.ts +57 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +60 -0
- package/src/data-structures/priority-queue/priority-queue.ts +60 -0
- package/src/data-structures/queue/deque.ts +272 -65
- package/src/data-structures/queue/queue.ts +211 -42
- package/src/data-structures/stack/stack.ts +174 -32
- package/src/data-structures/trie/trie.ts +213 -43
- package/src/types/data-structures/binary-tree/segment-tree.ts +1 -1
- package/src/types/data-structures/linked-list/skip-linked-list.ts +2 -1
package/dist/esm/index.mjs
CHANGED
|
@@ -1,55 +1,6 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
|
|
4
|
-
// src/common/error.ts
|
|
5
|
-
var ERR = {
|
|
6
|
-
// Range / index
|
|
7
|
-
indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
|
|
8
|
-
invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
|
|
9
|
-
// Type / argument
|
|
10
|
-
invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
|
|
11
|
-
comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
|
|
12
|
-
invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
|
|
13
|
-
notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
|
|
14
|
-
invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
|
|
15
|
-
invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
|
|
16
|
-
invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
|
|
17
|
-
reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
|
|
18
|
-
callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
|
|
19
|
-
// State / operation
|
|
20
|
-
invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
|
|
21
|
-
// Matrix
|
|
22
|
-
matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
|
|
23
|
-
matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
|
|
24
|
-
matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
|
|
25
|
-
matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
|
|
26
|
-
matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
// src/common/index.ts
|
|
30
|
-
var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
|
|
31
|
-
DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
|
|
32
|
-
DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
|
|
33
|
-
return DFSOperation2;
|
|
34
|
-
})(DFSOperation || {});
|
|
35
|
-
var Range = class {
|
|
36
|
-
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
37
|
-
this.low = low;
|
|
38
|
-
this.high = high;
|
|
39
|
-
this.includeLow = includeLow;
|
|
40
|
-
this.includeHigh = includeHigh;
|
|
41
|
-
}
|
|
42
|
-
static {
|
|
43
|
-
__name(this, "Range");
|
|
44
|
-
}
|
|
45
|
-
// Determine whether a key is within the range
|
|
46
|
-
isInRange(key, comparator) {
|
|
47
|
-
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
48
|
-
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
49
|
-
return lowCheck && highCheck;
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
|
|
53
4
|
// src/data-structures/base/iterable-element-base.ts
|
|
54
5
|
var IterableElementBase = class {
|
|
55
6
|
static {
|
|
@@ -68,7 +19,7 @@ var IterableElementBase = class {
|
|
|
68
19
|
if (options) {
|
|
69
20
|
const { toElementFn } = options;
|
|
70
21
|
if (typeof toElementFn === "function") this._toElementFn = toElementFn;
|
|
71
|
-
else if (toElementFn) throw new TypeError(
|
|
22
|
+
else if (toElementFn) throw new TypeError("toElementFn must be a function type");
|
|
72
23
|
}
|
|
73
24
|
}
|
|
74
25
|
/**
|
|
@@ -231,7 +182,7 @@ var IterableElementBase = class {
|
|
|
231
182
|
acc = initialValue;
|
|
232
183
|
} else {
|
|
233
184
|
const first = iter.next();
|
|
234
|
-
if (first.done) throw new TypeError(
|
|
185
|
+
if (first.done) throw new TypeError("Reduce of empty structure with no initial value");
|
|
235
186
|
acc = first.value;
|
|
236
187
|
index = 1;
|
|
237
188
|
}
|
|
@@ -300,10 +251,23 @@ var Stack = class extends IterableElementBase {
|
|
|
300
251
|
return this._elements;
|
|
301
252
|
}
|
|
302
253
|
/**
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
254
|
+
* Get the number of stored elements.
|
|
255
|
+
* @remarks Time O(1), Space O(1)
|
|
256
|
+
* @returns Current size.
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
* @example
|
|
267
|
+
* // Get number of elements
|
|
268
|
+
* const stack = new Stack<number>([1, 2, 3]);
|
|
269
|
+
* console.log(stack.size); // 3;
|
|
270
|
+
*/
|
|
307
271
|
get size() {
|
|
308
272
|
return this.elements.length;
|
|
309
273
|
}
|
|
@@ -321,36 +285,123 @@ var Stack = class extends IterableElementBase {
|
|
|
321
285
|
return new this(elements, options);
|
|
322
286
|
}
|
|
323
287
|
/**
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
288
|
+
* Check whether the stack is empty.
|
|
289
|
+
* @remarks Time O(1), Space O(1)
|
|
290
|
+
* @returns True if size is 0.
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
* @example
|
|
303
|
+
* // Check if stack has elements
|
|
304
|
+
* const stack = new Stack<number>();
|
|
305
|
+
* console.log(stack.isEmpty()); // true;
|
|
306
|
+
* stack.push(1);
|
|
307
|
+
* console.log(stack.isEmpty()); // false;
|
|
308
|
+
*/
|
|
328
309
|
isEmpty() {
|
|
329
310
|
return this.elements.length === 0;
|
|
330
311
|
}
|
|
331
312
|
/**
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
313
|
+
* Get the top element without removing it.
|
|
314
|
+
* @remarks Time O(1), Space O(1)
|
|
315
|
+
* @returns Top element or undefined.
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
* @example
|
|
328
|
+
* // View the top element without removing it
|
|
329
|
+
* const stack = new Stack<string>(['a', 'b', 'c']);
|
|
330
|
+
* console.log(stack.peek()); // 'c';
|
|
331
|
+
* console.log(stack.size); // 3;
|
|
332
|
+
*/
|
|
336
333
|
peek() {
|
|
337
334
|
return this.isEmpty() ? void 0 : this.elements[this.elements.length - 1];
|
|
338
335
|
}
|
|
339
336
|
/**
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
337
|
+
* Push one element onto the top.
|
|
338
|
+
* @remarks Time O(1), Space O(1)
|
|
339
|
+
* @param element - Element to push.
|
|
340
|
+
* @returns True when pushed.
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
* @example
|
|
353
|
+
* // basic Stack creation and push operation
|
|
354
|
+
* // Create a simple Stack with initial values
|
|
355
|
+
* const stack = new Stack([1, 2, 3, 4, 5]);
|
|
356
|
+
*
|
|
357
|
+
* // Verify the stack maintains insertion order (LIFO will be shown in pop)
|
|
358
|
+
* console.log([...stack]); // [1, 2, 3, 4, 5];
|
|
359
|
+
*
|
|
360
|
+
* // Check length
|
|
361
|
+
* console.log(stack.size); // 5;
|
|
362
|
+
*
|
|
363
|
+
* // Push a new element to the top
|
|
364
|
+
* stack.push(6);
|
|
365
|
+
* console.log(stack.size); // 6;
|
|
366
|
+
*/
|
|
345
367
|
push(element) {
|
|
346
368
|
this.elements.push(element);
|
|
347
369
|
return true;
|
|
348
370
|
}
|
|
349
371
|
/**
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
372
|
+
* Pop and return the top element.
|
|
373
|
+
* @remarks Time O(1), Space O(1)
|
|
374
|
+
* @returns Removed element or undefined.
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
* @example
|
|
387
|
+
* // Stack pop operation (LIFO - Last In First Out)
|
|
388
|
+
* const stack = new Stack<number>([10, 20, 30, 40, 50]);
|
|
389
|
+
*
|
|
390
|
+
* // Peek at the top element without removing
|
|
391
|
+
* const top = stack.peek();
|
|
392
|
+
* console.log(top); // 50;
|
|
393
|
+
*
|
|
394
|
+
* // Pop removes from the top (LIFO order)
|
|
395
|
+
* const popped = stack.pop();
|
|
396
|
+
* console.log(popped); // 50;
|
|
397
|
+
*
|
|
398
|
+
* // Next pop gets the previous element
|
|
399
|
+
* const next = stack.pop();
|
|
400
|
+
* console.log(next); // 40;
|
|
401
|
+
*
|
|
402
|
+
* // Verify length decreased
|
|
403
|
+
* console.log(stack.size); // 3;
|
|
404
|
+
*/
|
|
354
405
|
pop() {
|
|
355
406
|
return this.isEmpty() ? void 0 : this.elements.pop();
|
|
356
407
|
}
|
|
@@ -369,11 +420,24 @@ var Stack = class extends IterableElementBase {
|
|
|
369
420
|
return ans;
|
|
370
421
|
}
|
|
371
422
|
/**
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
423
|
+
* Delete the first occurrence of a specific element.
|
|
424
|
+
* @remarks Time O(N), Space O(1)
|
|
425
|
+
* @param element - Element to remove (using the configured equality).
|
|
426
|
+
* @returns True if an element was removed.
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
* @example
|
|
436
|
+
* // Remove element
|
|
437
|
+
* const stack = new Stack<number>([1, 2, 3]);
|
|
438
|
+
* stack.delete(2);
|
|
439
|
+
* console.log(stack.toArray()); // [1, 3];
|
|
440
|
+
*/
|
|
377
441
|
delete(element) {
|
|
378
442
|
const idx = this._indexOfByEquals(element);
|
|
379
443
|
return this.deleteAt(idx);
|
|
@@ -405,30 +469,74 @@ var Stack = class extends IterableElementBase {
|
|
|
405
469
|
return false;
|
|
406
470
|
}
|
|
407
471
|
/**
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
472
|
+
* Remove all elements and reset storage.
|
|
473
|
+
* @remarks Time O(1), Space O(1)
|
|
474
|
+
* @returns void
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
|
|
484
|
+
* @example
|
|
485
|
+
* // Remove all elements
|
|
486
|
+
* const stack = new Stack<number>([1, 2, 3]);
|
|
487
|
+
* stack.clear();
|
|
488
|
+
* console.log(stack.isEmpty()); // true;
|
|
489
|
+
*/
|
|
412
490
|
clear() {
|
|
413
491
|
this._elements = [];
|
|
414
492
|
}
|
|
415
493
|
/**
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
494
|
+
* Deep clone this stack.
|
|
495
|
+
* @remarks Time O(N), Space O(N)
|
|
496
|
+
* @returns A new stack with the same content.
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
* @example
|
|
507
|
+
* // Create independent copy
|
|
508
|
+
* const stack = new Stack<number>([1, 2, 3]);
|
|
509
|
+
* const copy = stack.clone();
|
|
510
|
+
* copy.pop();
|
|
511
|
+
* console.log(stack.size); // 3;
|
|
512
|
+
* console.log(copy.size); // 2;
|
|
513
|
+
*/
|
|
420
514
|
clone() {
|
|
421
515
|
const out = this._createInstance({ toElementFn: this.toElementFn });
|
|
422
516
|
for (const v of this) out.push(v);
|
|
423
517
|
return out;
|
|
424
518
|
}
|
|
425
519
|
/**
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
520
|
+
* Filter elements into a new stack of the same class.
|
|
521
|
+
* @remarks Time O(N), Space O(N)
|
|
522
|
+
* @param predicate - Predicate (value, index, stack) → boolean to keep value.
|
|
523
|
+
* @param [thisArg] - Value for `this` inside the predicate.
|
|
524
|
+
* @returns A new stack with kept values.
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
* @example
|
|
535
|
+
* // Filter elements
|
|
536
|
+
* const stack = new Stack<number>([1, 2, 3, 4, 5]);
|
|
537
|
+
* const evens = stack.filter(x => x % 2 === 0);
|
|
538
|
+
* console.log(evens.toArray()); // [2, 4];
|
|
539
|
+
*/
|
|
432
540
|
filter(predicate, thisArg) {
|
|
433
541
|
const out = this._createInstance({ toElementFn: this.toElementFn });
|
|
434
542
|
let index = 0;
|
|
@@ -455,15 +563,28 @@ var Stack = class extends IterableElementBase {
|
|
|
455
563
|
return out;
|
|
456
564
|
}
|
|
457
565
|
/**
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
566
|
+
* Map values into a new stack (possibly different element type).
|
|
567
|
+
* @remarks Time O(N), Space O(N)
|
|
568
|
+
* @template EM
|
|
569
|
+
* @template RM
|
|
570
|
+
* @param callback - Mapping function (value, index, stack) → newElement.
|
|
571
|
+
* @param [options] - Options for the output stack (e.g., toElementFn).
|
|
572
|
+
* @param [thisArg] - Value for `this` inside the callback.
|
|
573
|
+
* @returns A new Stack with mapped elements.
|
|
574
|
+
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
|
|
581
|
+
|
|
582
|
+
* @example
|
|
583
|
+
* // Transform elements
|
|
584
|
+
* const stack = new Stack<number>([1, 2, 3]);
|
|
585
|
+
* const doubled = stack.map(x => x * 2);
|
|
586
|
+
* console.log(doubled.toArray()); // [2, 4, 6];
|
|
587
|
+
*/
|
|
467
588
|
map(callback, options, thisArg) {
|
|
468
589
|
const out = this._createLike([], { ...options ?? {} });
|
|
469
590
|
let index = 0;
|
|
@@ -525,6 +646,55 @@ var Stack = class extends IterableElementBase {
|
|
|
525
646
|
for (let i = 0; i < this.elements.length; i++) yield this.elements[i];
|
|
526
647
|
}
|
|
527
648
|
};
|
|
649
|
+
|
|
650
|
+
// src/common/error.ts
|
|
651
|
+
var ERR = {
|
|
652
|
+
// Range / index
|
|
653
|
+
indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
|
|
654
|
+
invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
|
|
655
|
+
// Type / argument
|
|
656
|
+
invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
|
|
657
|
+
comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
|
|
658
|
+
invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
|
|
659
|
+
notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
|
|
660
|
+
invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
|
|
661
|
+
invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
|
|
662
|
+
invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
|
|
663
|
+
reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
|
|
664
|
+
callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
|
|
665
|
+
// State / operation
|
|
666
|
+
invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
|
|
667
|
+
// Matrix
|
|
668
|
+
matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
|
|
669
|
+
matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
|
|
670
|
+
matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
|
|
671
|
+
matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
|
|
672
|
+
matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
|
|
673
|
+
};
|
|
674
|
+
|
|
675
|
+
// src/common/index.ts
|
|
676
|
+
var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
|
|
677
|
+
DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
|
|
678
|
+
DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
|
|
679
|
+
return DFSOperation2;
|
|
680
|
+
})(DFSOperation || {});
|
|
681
|
+
var Range = class {
|
|
682
|
+
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
683
|
+
this.low = low;
|
|
684
|
+
this.high = high;
|
|
685
|
+
this.includeLow = includeLow;
|
|
686
|
+
this.includeHigh = includeHigh;
|
|
687
|
+
}
|
|
688
|
+
static {
|
|
689
|
+
__name(this, "Range");
|
|
690
|
+
}
|
|
691
|
+
// Determine whether a key is within the range
|
|
692
|
+
isInRange(key, comparator) {
|
|
693
|
+
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
694
|
+
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
695
|
+
return lowCheck && highCheck;
|
|
696
|
+
}
|
|
697
|
+
};
|
|
528
698
|
/**
|
|
529
699
|
* data-structure-typed
|
|
530
700
|
*
|