max-priority-queue-typed 2.5.0 → 2.5.2
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 +398 -55
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +397 -54
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +398 -56
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +397 -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/base/index.d.ts +1 -0
- package/dist/types/data-structures/base/iterable-entry-base.d.ts +8 -8
- package/dist/types/data-structures/base/linear-base.d.ts +3 -3
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +288 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +336 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +618 -18
- package/dist/types/data-structures/binary-tree/bst.d.ts +676 -1
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +456 -0
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +144 -1
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +3307 -399
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3285 -360
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2674 -325
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +3072 -287
- package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
- package/dist/types/data-structures/graph/directed-graph.d.ts +240 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +216 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +274 -10
- package/dist/types/data-structures/heap/heap.d.ts +336 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +411 -3
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +363 -3
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +434 -2
- package/dist/types/data-structures/matrix/matrix.d.ts +192 -0
- package/dist/types/data-structures/queue/deque.d.ts +364 -4
- package/dist/types/data-structures/queue/queue.d.ts +288 -0
- package/dist/types/data-structures/stack/stack.d.ts +240 -0
- package/dist/types/data-structures/trie/trie.d.ts +292 -4
- package/dist/types/interfaces/graph.d.ts +1 -1
- package/dist/types/types/common.d.ts +2 -2
- 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/types/types/data-structures/heap/heap.d.ts +1 -0
- package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
- package/dist/types/types/utils/validate-type.d.ts +4 -4
- package/dist/umd/max-priority-queue-typed.js +395 -53
- package/dist/umd/max-priority-queue-typed.js.map +1 -1
- package/dist/umd/max-priority-queue-typed.min.js +1 -1
- package/dist/umd/max-priority-queue-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/index.ts +1 -0
- package/src/data-structures/base/iterable-element-base.ts +3 -2
- package/src/data-structures/base/iterable-entry-base.ts +8 -8
- package/src/data-structures/base/linear-base.ts +3 -3
- package/src/data-structures/binary-tree/avl-tree.ts +299 -0
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +341 -5
- package/src/data-structures/binary-tree/binary-tree.ts +606 -6
- package/src/data-structures/binary-tree/bst.ts +946 -7
- package/src/data-structures/binary-tree/red-black-tree.ts +472 -0
- package/src/data-structures/binary-tree/segment-tree.ts +145 -2
- package/src/data-structures/binary-tree/tree-map.ts +3423 -499
- package/src/data-structures/binary-tree/tree-multi-map.ts +3537 -596
- package/src/data-structures/binary-tree/tree-multi-set.ts +2855 -495
- package/src/data-structures/binary-tree/tree-set.ts +3209 -413
- package/src/data-structures/graph/abstract-graph.ts +6 -6
- package/src/data-structures/graph/directed-graph.ts +240 -0
- package/src/data-structures/graph/undirected-graph.ts +216 -0
- package/src/data-structures/hash/hash-map.ts +281 -19
- package/src/data-structures/heap/heap.ts +340 -4
- package/src/data-structures/heap/max-heap.ts +2 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +411 -3
- package/src/data-structures/linked-list/singly-linked-list.ts +363 -3
- package/src/data-structures/linked-list/skip-linked-list.ts +439 -7
- package/src/data-structures/matrix/matrix.ts +202 -10
- package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
- package/src/data-structures/queue/deque.ts +365 -5
- package/src/data-structures/queue/queue.ts +288 -0
- package/src/data-structures/stack/stack.ts +240 -0
- package/src/data-structures/trie/trie.ts +295 -7
- package/src/interfaces/graph.ts +1 -1
- package/src/types/common.ts +2 -2
- 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
- package/src/types/data-structures/heap/heap.ts +1 -0
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
- package/src/types/utils/validate-type.ts +4 -4
|
@@ -5,6 +5,60 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
|
|
|
5
5
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
6
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
7
7
|
|
|
8
|
+
// src/common/error.ts
|
|
9
|
+
function raise(ErrorClass, message) {
|
|
10
|
+
throw new ErrorClass(message);
|
|
11
|
+
}
|
|
12
|
+
__name(raise, "raise");
|
|
13
|
+
var ERR = {
|
|
14
|
+
// Range / index
|
|
15
|
+
indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
|
|
16
|
+
invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
|
|
17
|
+
// Type / argument
|
|
18
|
+
invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
|
|
19
|
+
comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
|
|
20
|
+
invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
|
|
21
|
+
notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
|
|
22
|
+
invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
|
|
23
|
+
invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
|
|
24
|
+
invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
|
|
25
|
+
reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
|
|
26
|
+
callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
|
|
27
|
+
// State / operation
|
|
28
|
+
invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
|
|
29
|
+
// Matrix
|
|
30
|
+
matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
|
|
31
|
+
matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
|
|
32
|
+
matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
|
|
33
|
+
matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
|
|
34
|
+
matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch"),
|
|
35
|
+
// Order statistic
|
|
36
|
+
orderStatisticNotEnabled: /* @__PURE__ */ __name((method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`, "orderStatisticNotEnabled")
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// src/common/index.ts
|
|
40
|
+
var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
|
|
41
|
+
DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
|
|
42
|
+
DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
|
|
43
|
+
return DFSOperation2;
|
|
44
|
+
})(DFSOperation || {});
|
|
45
|
+
var _Range = class _Range {
|
|
46
|
+
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
47
|
+
this.low = low;
|
|
48
|
+
this.high = high;
|
|
49
|
+
this.includeLow = includeLow;
|
|
50
|
+
this.includeHigh = includeHigh;
|
|
51
|
+
}
|
|
52
|
+
// Determine whether a key is within the range
|
|
53
|
+
isInRange(key, comparator) {
|
|
54
|
+
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
55
|
+
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
56
|
+
return lowCheck && highCheck;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
__name(_Range, "Range");
|
|
60
|
+
var Range = _Range;
|
|
61
|
+
|
|
8
62
|
// src/data-structures/base/iterable-element-base.ts
|
|
9
63
|
var _IterableElementBase = class _IterableElementBase {
|
|
10
64
|
/**
|
|
@@ -27,7 +81,7 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
27
81
|
if (options) {
|
|
28
82
|
const { toElementFn } = options;
|
|
29
83
|
if (typeof toElementFn === "function") this._toElementFn = toElementFn;
|
|
30
|
-
else if (toElementFn)
|
|
84
|
+
else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
|
|
31
85
|
}
|
|
32
86
|
}
|
|
33
87
|
/**
|
|
@@ -183,7 +237,7 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
183
237
|
acc = initialValue;
|
|
184
238
|
} else {
|
|
185
239
|
const first = iter.next();
|
|
186
|
-
if (first.done)
|
|
240
|
+
if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
|
|
187
241
|
acc = first.value;
|
|
188
242
|
index = 1;
|
|
189
243
|
}
|
|
@@ -227,54 +281,6 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
227
281
|
__name(_IterableElementBase, "IterableElementBase");
|
|
228
282
|
var IterableElementBase = _IterableElementBase;
|
|
229
283
|
|
|
230
|
-
// src/common/error.ts
|
|
231
|
-
var ERR = {
|
|
232
|
-
// Range / index
|
|
233
|
-
indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
|
|
234
|
-
invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
|
|
235
|
-
// Type / argument
|
|
236
|
-
invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
|
|
237
|
-
comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
|
|
238
|
-
invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
|
|
239
|
-
notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
|
|
240
|
-
invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
|
|
241
|
-
invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
|
|
242
|
-
invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
|
|
243
|
-
reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
|
|
244
|
-
callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
|
|
245
|
-
// State / operation
|
|
246
|
-
invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
|
|
247
|
-
// Matrix
|
|
248
|
-
matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
|
|
249
|
-
matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
|
|
250
|
-
matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
|
|
251
|
-
matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
|
|
252
|
-
matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
|
|
253
|
-
};
|
|
254
|
-
|
|
255
|
-
// src/common/index.ts
|
|
256
|
-
var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
|
|
257
|
-
DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
|
|
258
|
-
DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
|
|
259
|
-
return DFSOperation2;
|
|
260
|
-
})(DFSOperation || {});
|
|
261
|
-
var _Range = class _Range {
|
|
262
|
-
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
263
|
-
this.low = low;
|
|
264
|
-
this.high = high;
|
|
265
|
-
this.includeLow = includeLow;
|
|
266
|
-
this.includeHigh = includeHigh;
|
|
267
|
-
}
|
|
268
|
-
// Determine whether a key is within the range
|
|
269
|
-
isInRange(key, comparator) {
|
|
270
|
-
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
271
|
-
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
272
|
-
return lowCheck && highCheck;
|
|
273
|
-
}
|
|
274
|
-
};
|
|
275
|
-
__name(_Range, "Range");
|
|
276
|
-
var Range = _Range;
|
|
277
|
-
|
|
278
284
|
// src/data-structures/heap/heap.ts
|
|
279
285
|
var _Heap = class _Heap extends IterableElementBase {
|
|
280
286
|
/**
|
|
@@ -290,7 +296,7 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
290
296
|
__publicField(this, "_elements", []);
|
|
291
297
|
__publicField(this, "_DEFAULT_COMPARATOR", /* @__PURE__ */ __name((a, b) => {
|
|
292
298
|
if (typeof a === "object" || typeof b === "object") {
|
|
293
|
-
|
|
299
|
+
raise(TypeError, ERR.comparatorRequired("Heap"));
|
|
294
300
|
}
|
|
295
301
|
if (a > b) return 1;
|
|
296
302
|
if (a < b) return -1;
|
|
@@ -326,6 +332,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
326
332
|
|
|
327
333
|
|
|
328
334
|
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
|
|
329
359
|
* @example
|
|
330
360
|
* // Track heap capacity
|
|
331
361
|
* const heap = new Heap<number>();
|
|
@@ -389,6 +419,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
389
419
|
|
|
390
420
|
|
|
391
421
|
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
|
|
392
446
|
* @example
|
|
393
447
|
* // basic Heap creation and add operation
|
|
394
448
|
* // Create a min heap (default)
|
|
@@ -422,6 +476,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
422
476
|
|
|
423
477
|
|
|
424
478
|
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
|
|
425
503
|
* @example
|
|
426
504
|
* // Add multiple elements
|
|
427
505
|
* const heap = new Heap<number>([], { comparator: (a, b) => a - b });
|
|
@@ -457,6 +535,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
457
535
|
|
|
458
536
|
|
|
459
537
|
|
|
538
|
+
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
|
|
552
|
+
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
|
|
460
562
|
* @example
|
|
461
563
|
* // Heap with custom comparator (MaxHeap behavior)
|
|
462
564
|
* interface Task {
|
|
@@ -508,6 +610,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
508
610
|
|
|
509
611
|
|
|
510
612
|
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
|
|
622
|
+
|
|
623
|
+
|
|
624
|
+
|
|
625
|
+
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
|
|
629
|
+
|
|
630
|
+
|
|
631
|
+
|
|
632
|
+
|
|
633
|
+
|
|
634
|
+
|
|
635
|
+
|
|
636
|
+
|
|
511
637
|
* @example
|
|
512
638
|
* // Heap for event processing with priority
|
|
513
639
|
* interface Event {
|
|
@@ -584,6 +710,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
584
710
|
|
|
585
711
|
|
|
586
712
|
|
|
713
|
+
|
|
714
|
+
|
|
715
|
+
|
|
716
|
+
|
|
717
|
+
|
|
718
|
+
|
|
719
|
+
|
|
720
|
+
|
|
721
|
+
|
|
722
|
+
|
|
723
|
+
|
|
724
|
+
|
|
725
|
+
|
|
726
|
+
|
|
727
|
+
|
|
728
|
+
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+
|
|
732
|
+
|
|
733
|
+
|
|
734
|
+
|
|
735
|
+
|
|
736
|
+
|
|
587
737
|
* @example
|
|
588
738
|
* // Check if heap is empty
|
|
589
739
|
* const heap = new Heap<number>([], { comparator: (a, b) => a - b });
|
|
@@ -607,6 +757,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
607
757
|
|
|
608
758
|
|
|
609
759
|
|
|
760
|
+
|
|
761
|
+
|
|
762
|
+
|
|
763
|
+
|
|
764
|
+
|
|
765
|
+
|
|
766
|
+
|
|
767
|
+
|
|
768
|
+
|
|
769
|
+
|
|
770
|
+
|
|
771
|
+
|
|
772
|
+
|
|
773
|
+
|
|
774
|
+
|
|
775
|
+
|
|
776
|
+
|
|
777
|
+
|
|
778
|
+
|
|
779
|
+
|
|
780
|
+
|
|
781
|
+
|
|
782
|
+
|
|
783
|
+
|
|
610
784
|
* @example
|
|
611
785
|
* // Remove all elements
|
|
612
786
|
* const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
|
|
@@ -633,6 +807,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
633
807
|
* @returns True if found.
|
|
634
808
|
|
|
635
809
|
|
|
810
|
+
|
|
811
|
+
|
|
812
|
+
|
|
813
|
+
|
|
814
|
+
|
|
815
|
+
|
|
816
|
+
|
|
817
|
+
|
|
818
|
+
|
|
819
|
+
|
|
820
|
+
|
|
821
|
+
|
|
822
|
+
|
|
823
|
+
|
|
824
|
+
|
|
825
|
+
|
|
826
|
+
|
|
827
|
+
|
|
828
|
+
|
|
829
|
+
|
|
830
|
+
|
|
831
|
+
|
|
832
|
+
|
|
833
|
+
|
|
636
834
|
* @example
|
|
637
835
|
* // Check element existence
|
|
638
836
|
* const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
|
|
@@ -656,6 +854,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
656
854
|
|
|
657
855
|
|
|
658
856
|
|
|
857
|
+
|
|
858
|
+
|
|
859
|
+
|
|
860
|
+
|
|
861
|
+
|
|
862
|
+
|
|
863
|
+
|
|
864
|
+
|
|
865
|
+
|
|
866
|
+
|
|
867
|
+
|
|
868
|
+
|
|
869
|
+
|
|
870
|
+
|
|
871
|
+
|
|
872
|
+
|
|
873
|
+
|
|
874
|
+
|
|
875
|
+
|
|
876
|
+
|
|
877
|
+
|
|
878
|
+
|
|
879
|
+
|
|
880
|
+
|
|
659
881
|
* @example
|
|
660
882
|
* // Remove specific element
|
|
661
883
|
* const heap = new Heap<number>([3, 1, 4, 1, 5], { comparator: (a, b) => a - b });
|
|
@@ -725,6 +947,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
725
947
|
* @returns Array of visited elements.
|
|
726
948
|
|
|
727
949
|
|
|
950
|
+
|
|
951
|
+
|
|
952
|
+
|
|
953
|
+
|
|
954
|
+
|
|
955
|
+
|
|
956
|
+
|
|
957
|
+
|
|
958
|
+
|
|
959
|
+
|
|
960
|
+
|
|
961
|
+
|
|
962
|
+
|
|
963
|
+
|
|
964
|
+
|
|
965
|
+
|
|
966
|
+
|
|
967
|
+
|
|
968
|
+
|
|
969
|
+
|
|
970
|
+
|
|
971
|
+
|
|
972
|
+
|
|
973
|
+
|
|
728
974
|
* @example
|
|
729
975
|
* // Depth-first traversal
|
|
730
976
|
* const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
|
|
@@ -781,6 +1027,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
781
1027
|
|
|
782
1028
|
|
|
783
1029
|
|
|
1030
|
+
|
|
1031
|
+
|
|
1032
|
+
|
|
1033
|
+
|
|
1034
|
+
|
|
1035
|
+
|
|
1036
|
+
|
|
1037
|
+
|
|
1038
|
+
|
|
1039
|
+
|
|
1040
|
+
|
|
1041
|
+
|
|
1042
|
+
|
|
1043
|
+
|
|
1044
|
+
|
|
1045
|
+
|
|
1046
|
+
|
|
1047
|
+
|
|
1048
|
+
|
|
1049
|
+
|
|
1050
|
+
|
|
1051
|
+
|
|
1052
|
+
|
|
1053
|
+
|
|
784
1054
|
* @example
|
|
785
1055
|
* // Sort elements using heap
|
|
786
1056
|
* const heap = new Heap<number>([5, 1, 3, 2, 4]);
|
|
@@ -810,6 +1080,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
810
1080
|
|
|
811
1081
|
|
|
812
1082
|
|
|
1083
|
+
|
|
1084
|
+
|
|
1085
|
+
|
|
1086
|
+
|
|
1087
|
+
|
|
1088
|
+
|
|
1089
|
+
|
|
1090
|
+
|
|
1091
|
+
|
|
1092
|
+
|
|
1093
|
+
|
|
1094
|
+
|
|
1095
|
+
|
|
1096
|
+
|
|
1097
|
+
|
|
1098
|
+
|
|
1099
|
+
|
|
1100
|
+
|
|
1101
|
+
|
|
1102
|
+
|
|
1103
|
+
|
|
1104
|
+
|
|
1105
|
+
|
|
1106
|
+
|
|
813
1107
|
* @example
|
|
814
1108
|
* // Create independent copy
|
|
815
1109
|
* const heap = new Heap<number>([3, 1, 4], { comparator: (a, b) => a - b });
|
|
@@ -838,6 +1132,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
838
1132
|
|
|
839
1133
|
|
|
840
1134
|
|
|
1135
|
+
|
|
1136
|
+
|
|
1137
|
+
|
|
1138
|
+
|
|
1139
|
+
|
|
1140
|
+
|
|
1141
|
+
|
|
1142
|
+
|
|
1143
|
+
|
|
1144
|
+
|
|
1145
|
+
|
|
1146
|
+
|
|
1147
|
+
|
|
1148
|
+
|
|
1149
|
+
|
|
1150
|
+
|
|
1151
|
+
|
|
1152
|
+
|
|
1153
|
+
|
|
1154
|
+
|
|
1155
|
+
|
|
1156
|
+
|
|
1157
|
+
|
|
1158
|
+
|
|
841
1159
|
* @example
|
|
842
1160
|
* // Filter elements
|
|
843
1161
|
* const heap = new Heap<number>([1, 2, 3, 4, 5], { comparator: (a, b) => a - b });
|
|
@@ -873,6 +1191,30 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
873
1191
|
|
|
874
1192
|
|
|
875
1193
|
|
|
1194
|
+
|
|
1195
|
+
|
|
1196
|
+
|
|
1197
|
+
|
|
1198
|
+
|
|
1199
|
+
|
|
1200
|
+
|
|
1201
|
+
|
|
1202
|
+
|
|
1203
|
+
|
|
1204
|
+
|
|
1205
|
+
|
|
1206
|
+
|
|
1207
|
+
|
|
1208
|
+
|
|
1209
|
+
|
|
1210
|
+
|
|
1211
|
+
|
|
1212
|
+
|
|
1213
|
+
|
|
1214
|
+
|
|
1215
|
+
|
|
1216
|
+
|
|
1217
|
+
|
|
876
1218
|
* @example
|
|
877
1219
|
* // Transform elements
|
|
878
1220
|
* const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
|
|
@@ -881,7 +1223,7 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
881
1223
|
*/
|
|
882
1224
|
map(callback, options, thisArg) {
|
|
883
1225
|
const { comparator, toElementFn, ...rest } = options != null ? options : {};
|
|
884
|
-
if (!comparator)
|
|
1226
|
+
if (!comparator) raise(TypeError, ERR.comparatorRequired("Heap.map"));
|
|
885
1227
|
const out = this._createLike([], { ...rest, comparator, toElementFn });
|
|
886
1228
|
let i = 0;
|
|
887
1229
|
for (const x of this) {
|
|
@@ -1013,7 +1355,7 @@ var _FibonacciHeap = class _FibonacciHeap {
|
|
|
1013
1355
|
__publicField(this, "_comparator");
|
|
1014
1356
|
this.clear();
|
|
1015
1357
|
this._comparator = comparator || this._defaultComparator;
|
|
1016
|
-
if (typeof this.comparator !== "function")
|
|
1358
|
+
if (typeof this.comparator !== "function") raise(TypeError, ERR.notAFunction("comparator", "FibonacciHeap"));
|
|
1017
1359
|
}
|
|
1018
1360
|
/**
|
|
1019
1361
|
* Get the circular root list head.
|
|
@@ -1235,7 +1577,7 @@ var _MaxPriorityQueue = class _MaxPriorityQueue extends PriorityQueue {
|
|
|
1235
1577
|
super(elements, {
|
|
1236
1578
|
comparator: /* @__PURE__ */ __name((a, b) => {
|
|
1237
1579
|
if (typeof a === "object" || typeof b === "object") {
|
|
1238
|
-
|
|
1580
|
+
raise(TypeError, ERR.comparatorRequired("MaxPriorityQueue"));
|
|
1239
1581
|
}
|
|
1240
1582
|
if (a < b) return 1;
|
|
1241
1583
|
if (a > b) return -1;
|
|
@@ -1270,5 +1612,6 @@ exports.Heap = Heap;
|
|
|
1270
1612
|
exports.MaxPriorityQueue = MaxPriorityQueue;
|
|
1271
1613
|
exports.PriorityQueue = PriorityQueue;
|
|
1272
1614
|
exports.Range = Range;
|
|
1615
|
+
exports.raise = raise;
|
|
1273
1616
|
//# sourceMappingURL=index.cjs.map
|
|
1274
1617
|
//# sourceMappingURL=index.cjs.map
|