deque-typed 2.1.2 → 2.2.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/dist/cjs/index.cjs +35 -33
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +1223 -0
- package/dist/cjs-legacy/index.cjs.map +1 -0
- package/dist/esm/index.mjs +35 -33
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +1219 -0
- package/dist/esm-legacy/index.mjs.map +1 -0
- package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +57 -3
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +65 -3
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +58 -4
- package/dist/types/data-structures/binary-tree/bst.d.ts +57 -3
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +58 -4
- package/dist/types/data-structures/binary-tree/tree-counter.d.ts +57 -3
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +65 -3
- package/package.json +20 -2
- package/src/data-structures/binary-tree/avl-tree-counter.ts +102 -11
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +115 -11
- package/src/data-structures/binary-tree/avl-tree.ts +105 -14
- package/src/data-structures/binary-tree/bst.ts +102 -11
- package/src/data-structures/binary-tree/red-black-tree.ts +108 -18
- package/src/data-structures/binary-tree/tree-counter.ts +101 -10
- package/src/data-structures/binary-tree/tree-multi-map.ts +122 -11
- package/src/data-structures/graph/abstract-graph.ts +5 -5
- package/src/data-structures/graph/directed-graph.ts +5 -5
- package/src/data-structures/graph/undirected-graph.ts +5 -5
- package/tsup.node.config.js +40 -6
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
5
4
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
7
5
|
|
|
8
6
|
// src/utils/utils.ts
|
|
9
7
|
var rangeCheck = /* @__PURE__ */ __name((index, min, max, message = "Index out of bounds.") => {
|
|
@@ -44,7 +42,10 @@ function isComparable(value, isForceObjectComparable = false) {
|
|
|
44
42
|
__name(isComparable, "isComparable");
|
|
45
43
|
|
|
46
44
|
// src/data-structures/base/iterable-element-base.ts
|
|
47
|
-
var
|
|
45
|
+
var IterableElementBase = class {
|
|
46
|
+
static {
|
|
47
|
+
__name(this, "IterableElementBase");
|
|
48
|
+
}
|
|
48
49
|
/**
|
|
49
50
|
* Create a new iterable base.
|
|
50
51
|
*
|
|
@@ -55,19 +56,19 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
55
56
|
* Time O(1), Space O(1).
|
|
56
57
|
*/
|
|
57
58
|
constructor(options) {
|
|
58
|
-
/**
|
|
59
|
-
* The converter used to transform a raw element (`R`) into a public element (`E`).
|
|
60
|
-
*
|
|
61
|
-
* @remarks
|
|
62
|
-
* Time O(1), Space O(1).
|
|
63
|
-
*/
|
|
64
|
-
__publicField(this, "_toElementFn");
|
|
65
59
|
if (options) {
|
|
66
60
|
const { toElementFn } = options;
|
|
67
61
|
if (typeof toElementFn === "function") this._toElementFn = toElementFn;
|
|
68
62
|
else if (toElementFn) throw new TypeError("toElementFn must be a function type");
|
|
69
63
|
}
|
|
70
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* The converter used to transform a raw element (`R`) into a public element (`E`).
|
|
67
|
+
*
|
|
68
|
+
* @remarks
|
|
69
|
+
* Time O(1), Space O(1).
|
|
70
|
+
*/
|
|
71
|
+
_toElementFn;
|
|
71
72
|
/**
|
|
72
73
|
* Exposes the current `toElementFn`, if configured.
|
|
73
74
|
*
|
|
@@ -262,11 +263,12 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
262
263
|
console.log(this.toVisual());
|
|
263
264
|
}
|
|
264
265
|
};
|
|
265
|
-
__name(_IterableElementBase, "IterableElementBase");
|
|
266
|
-
var IterableElementBase = _IterableElementBase;
|
|
267
266
|
|
|
268
267
|
// src/data-structures/base/linear-base.ts
|
|
269
|
-
var
|
|
268
|
+
var LinearBase = class _LinearBase extends IterableElementBase {
|
|
269
|
+
static {
|
|
270
|
+
__name(this, "LinearBase");
|
|
271
|
+
}
|
|
270
272
|
/**
|
|
271
273
|
* Construct a linear container with runtime options.
|
|
272
274
|
* @param options - `{ maxLen?, ... }` bounds/behavior options.
|
|
@@ -274,12 +276,12 @@ var _LinearBase = class _LinearBase extends IterableElementBase {
|
|
|
274
276
|
*/
|
|
275
277
|
constructor(options) {
|
|
276
278
|
super(options);
|
|
277
|
-
__publicField(this, "_maxLen", -1);
|
|
278
279
|
if (options) {
|
|
279
280
|
const { maxLen } = options;
|
|
280
281
|
if (typeof maxLen === "number" && maxLen > 0 && maxLen % 1 === 0) this._maxLen = maxLen;
|
|
281
282
|
}
|
|
282
283
|
}
|
|
284
|
+
_maxLen = -1;
|
|
283
285
|
/**
|
|
284
286
|
* Upper bound for length (if positive), or `-1` when unbounded.
|
|
285
287
|
* @returns Maximum allowed length.
|
|
@@ -412,7 +414,7 @@ var _LinearBase = class _LinearBase extends IterableElementBase {
|
|
|
412
414
|
return array;
|
|
413
415
|
}
|
|
414
416
|
reduceRight(callbackfn, initialValue) {
|
|
415
|
-
let accumulator = initialValue
|
|
417
|
+
let accumulator = initialValue ?? 0;
|
|
416
418
|
for (let i = this.length - 1; i >= 0; i--) {
|
|
417
419
|
accumulator = callbackfn(accumulator, this.at(i), i, this);
|
|
418
420
|
}
|
|
@@ -454,11 +456,13 @@ var _LinearBase = class _LinearBase extends IterableElementBase {
|
|
|
454
456
|
return this;
|
|
455
457
|
}
|
|
456
458
|
};
|
|
457
|
-
__name(_LinearBase, "LinearBase");
|
|
458
|
-
var LinearBase = _LinearBase;
|
|
459
459
|
|
|
460
460
|
// src/data-structures/queue/deque.ts
|
|
461
|
-
var
|
|
461
|
+
var Deque = class extends LinearBase {
|
|
462
|
+
static {
|
|
463
|
+
__name(this, "Deque");
|
|
464
|
+
}
|
|
465
|
+
_equals = Object.is;
|
|
462
466
|
/**
|
|
463
467
|
* Create a Deque and optionally bulk-insert elements.
|
|
464
468
|
* @remarks Time O(N), Space O(N)
|
|
@@ -468,15 +472,6 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
468
472
|
*/
|
|
469
473
|
constructor(elements = [], options) {
|
|
470
474
|
super(options);
|
|
471
|
-
__publicField(this, "_equals", Object.is);
|
|
472
|
-
__publicField(this, "_bucketSize", 1 << 12);
|
|
473
|
-
__publicField(this, "_bucketFirst", 0);
|
|
474
|
-
__publicField(this, "_firstInBucket", 0);
|
|
475
|
-
__publicField(this, "_bucketLast", 0);
|
|
476
|
-
__publicField(this, "_lastInBucket", 0);
|
|
477
|
-
__publicField(this, "_bucketCount", 0);
|
|
478
|
-
__publicField(this, "_buckets", []);
|
|
479
|
-
__publicField(this, "_length", 0);
|
|
480
475
|
if (options) {
|
|
481
476
|
const { bucketSize } = options;
|
|
482
477
|
if (typeof bucketSize === "number") this._bucketSize = bucketSize;
|
|
@@ -496,6 +491,7 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
496
491
|
this._firstInBucket = this._lastInBucket = this._bucketSize - _size % this._bucketSize >> 1;
|
|
497
492
|
this.pushMany(elements);
|
|
498
493
|
}
|
|
494
|
+
_bucketSize = 1 << 12;
|
|
499
495
|
/**
|
|
500
496
|
* Get the current bucket size.
|
|
501
497
|
* @remarks Time O(1), Space O(1)
|
|
@@ -504,6 +500,7 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
504
500
|
get bucketSize() {
|
|
505
501
|
return this._bucketSize;
|
|
506
502
|
}
|
|
503
|
+
_bucketFirst = 0;
|
|
507
504
|
/**
|
|
508
505
|
* Get the index of the first bucket in use.
|
|
509
506
|
* @remarks Time O(1), Space O(1)
|
|
@@ -512,6 +509,7 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
512
509
|
get bucketFirst() {
|
|
513
510
|
return this._bucketFirst;
|
|
514
511
|
}
|
|
512
|
+
_firstInBucket = 0;
|
|
515
513
|
/**
|
|
516
514
|
* Get the index inside the first bucket.
|
|
517
515
|
* @remarks Time O(1), Space O(1)
|
|
@@ -520,6 +518,7 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
520
518
|
get firstInBucket() {
|
|
521
519
|
return this._firstInBucket;
|
|
522
520
|
}
|
|
521
|
+
_bucketLast = 0;
|
|
523
522
|
/**
|
|
524
523
|
* Get the index of the last bucket in use.
|
|
525
524
|
* @remarks Time O(1), Space O(1)
|
|
@@ -528,6 +527,7 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
528
527
|
get bucketLast() {
|
|
529
528
|
return this._bucketLast;
|
|
530
529
|
}
|
|
530
|
+
_lastInBucket = 0;
|
|
531
531
|
/**
|
|
532
532
|
* Get the index inside the last bucket.
|
|
533
533
|
* @remarks Time O(1), Space O(1)
|
|
@@ -536,6 +536,7 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
536
536
|
get lastInBucket() {
|
|
537
537
|
return this._lastInBucket;
|
|
538
538
|
}
|
|
539
|
+
_bucketCount = 0;
|
|
539
540
|
/**
|
|
540
541
|
* Get the number of buckets allocated.
|
|
541
542
|
* @remarks Time O(1), Space O(1)
|
|
@@ -544,6 +545,7 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
544
545
|
get bucketCount() {
|
|
545
546
|
return this._bucketCount;
|
|
546
547
|
}
|
|
548
|
+
_buckets = [];
|
|
547
549
|
/**
|
|
548
550
|
* Get the internal buckets array.
|
|
549
551
|
* @remarks Time O(1), Space O(1)
|
|
@@ -552,6 +554,7 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
552
554
|
get buckets() {
|
|
553
555
|
return this._buckets;
|
|
554
556
|
}
|
|
557
|
+
_length = 0;
|
|
555
558
|
/**
|
|
556
559
|
* Get the number of elements in the deque.
|
|
557
560
|
* @remarks Time O(1), Space O(1)
|
|
@@ -1067,7 +1070,7 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1067
1070
|
*/
|
|
1068
1071
|
map(callback, options, thisArg) {
|
|
1069
1072
|
const out = this._createLike([], {
|
|
1070
|
-
...options
|
|
1073
|
+
...options ?? {},
|
|
1071
1074
|
bucketSize: this._bucketSize,
|
|
1072
1075
|
maxLen: this._maxLen
|
|
1073
1076
|
});
|
|
@@ -1181,8 +1184,6 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1181
1184
|
}
|
|
1182
1185
|
}
|
|
1183
1186
|
};
|
|
1184
|
-
__name(_Deque, "Deque");
|
|
1185
|
-
var Deque = _Deque;
|
|
1186
1187
|
|
|
1187
1188
|
// src/common/index.ts
|
|
1188
1189
|
var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
|
|
@@ -1190,7 +1191,7 @@ var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
|
|
|
1190
1191
|
DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
|
|
1191
1192
|
return DFSOperation2;
|
|
1192
1193
|
})(DFSOperation || {});
|
|
1193
|
-
var
|
|
1194
|
+
var Range = class {
|
|
1194
1195
|
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
1195
1196
|
this.low = low;
|
|
1196
1197
|
this.high = high;
|
|
@@ -1199,6 +1200,9 @@ var _Range = class _Range {
|
|
|
1199
1200
|
if (!(isComparable(low) && isComparable(high))) throw new RangeError("low or high is not comparable");
|
|
1200
1201
|
if (low > high) throw new RangeError("low must be less than or equal to high");
|
|
1201
1202
|
}
|
|
1203
|
+
static {
|
|
1204
|
+
__name(this, "Range");
|
|
1205
|
+
}
|
|
1202
1206
|
// Determine whether a key is within the range
|
|
1203
1207
|
isInRange(key, comparator) {
|
|
1204
1208
|
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
@@ -1206,8 +1210,6 @@ var _Range = class _Range {
|
|
|
1206
1210
|
return lowCheck && highCheck;
|
|
1207
1211
|
}
|
|
1208
1212
|
};
|
|
1209
|
-
__name(_Range, "Range");
|
|
1210
|
-
var Range = _Range;
|
|
1211
1213
|
/**
|
|
1212
1214
|
* data-structure-typed
|
|
1213
1215
|
*
|