max-priority-queue-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 +207 -71
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +206 -70
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +207 -72
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +206 -71
- 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/max-priority-queue-typed.js +204 -69
- 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/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
|
@@ -178,6 +178,13 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
178
178
|
|
|
179
179
|
|
|
180
180
|
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
181
188
|
|
|
182
189
|
|
|
183
190
|
|
|
@@ -234,6 +241,13 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
234
241
|
|
|
235
242
|
|
|
236
243
|
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
|
|
237
251
|
|
|
238
252
|
|
|
239
253
|
|
|
@@ -292,6 +306,13 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
292
306
|
|
|
293
307
|
|
|
294
308
|
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
|
|
295
316
|
|
|
296
317
|
|
|
297
318
|
|
|
@@ -338,6 +359,13 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
338
359
|
|
|
339
360
|
|
|
340
361
|
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
|
|
341
369
|
|
|
342
370
|
|
|
343
371
|
|
|
@@ -383,6 +411,13 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
383
411
|
|
|
384
412
|
|
|
385
413
|
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
|
|
386
421
|
|
|
387
422
|
|
|
388
423
|
|
|
@@ -456,6 +491,13 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
456
491
|
|
|
457
492
|
|
|
458
493
|
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
|
|
459
501
|
|
|
460
502
|
|
|
461
503
|
|
|
@@ -511,6 +553,13 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
511
553
|
|
|
512
554
|
|
|
513
555
|
|
|
556
|
+
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
|
|
562
|
+
|
|
514
563
|
|
|
515
564
|
|
|
516
565
|
|
|
@@ -552,6 +601,13 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
552
601
|
|
|
553
602
|
|
|
554
603
|
|
|
604
|
+
|
|
605
|
+
|
|
606
|
+
|
|
607
|
+
|
|
608
|
+
|
|
609
|
+
|
|
610
|
+
|
|
555
611
|
|
|
556
612
|
|
|
557
613
|
|
|
@@ -620,6 +676,13 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
620
676
|
|
|
621
677
|
|
|
622
678
|
|
|
679
|
+
|
|
680
|
+
|
|
681
|
+
|
|
682
|
+
|
|
683
|
+
|
|
684
|
+
|
|
685
|
+
|
|
623
686
|
|
|
624
687
|
|
|
625
688
|
|
|
@@ -684,6 +747,13 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
684
747
|
|
|
685
748
|
|
|
686
749
|
|
|
750
|
+
|
|
751
|
+
|
|
752
|
+
|
|
753
|
+
|
|
754
|
+
|
|
755
|
+
|
|
756
|
+
|
|
687
757
|
|
|
688
758
|
|
|
689
759
|
|
|
@@ -195,6 +195,13 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
195
195
|
|
|
196
196
|
|
|
197
197
|
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
|
|
198
205
|
|
|
199
206
|
|
|
200
207
|
|
|
@@ -250,6 +257,13 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
250
257
|
|
|
251
258
|
|
|
252
259
|
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
|
|
253
267
|
|
|
254
268
|
|
|
255
269
|
|
|
@@ -313,6 +327,13 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
313
327
|
|
|
314
328
|
|
|
315
329
|
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
|
|
316
337
|
|
|
317
338
|
|
|
318
339
|
|
|
@@ -370,6 +391,13 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
370
391
|
|
|
371
392
|
|
|
372
393
|
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
|
|
373
401
|
|
|
374
402
|
|
|
375
403
|
|
|
@@ -413,6 +441,13 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
413
441
|
|
|
414
442
|
|
|
415
443
|
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
|
|
416
451
|
|
|
417
452
|
|
|
418
453
|
|
|
@@ -503,6 +538,13 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
503
538
|
|
|
504
539
|
|
|
505
540
|
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+
|
|
506
548
|
|
|
507
549
|
|
|
508
550
|
|
|
@@ -561,6 +603,13 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
561
603
|
|
|
562
604
|
|
|
563
605
|
|
|
606
|
+
|
|
607
|
+
|
|
608
|
+
|
|
609
|
+
|
|
610
|
+
|
|
611
|
+
|
|
612
|
+
|
|
564
613
|
|
|
565
614
|
|
|
566
615
|
|
|
@@ -607,6 +656,13 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
607
656
|
|
|
608
657
|
|
|
609
658
|
|
|
659
|
+
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
|
|
663
|
+
|
|
664
|
+
|
|
665
|
+
|
|
610
666
|
|
|
611
667
|
|
|
612
668
|
|
|
@@ -652,6 +708,13 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
652
708
|
|
|
653
709
|
|
|
654
710
|
|
|
711
|
+
|
|
712
|
+
|
|
713
|
+
|
|
714
|
+
|
|
715
|
+
|
|
716
|
+
|
|
717
|
+
|
|
655
718
|
|
|
656
719
|
|
|
657
720
|
|
|
@@ -158,6 +158,13 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
158
158
|
|
|
159
159
|
|
|
160
160
|
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
161
168
|
|
|
162
169
|
|
|
163
170
|
|
|
@@ -198,6 +205,13 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
198
205
|
|
|
199
206
|
|
|
200
207
|
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
|
|
201
215
|
|
|
202
216
|
|
|
203
217
|
|
|
@@ -274,6 +288,20 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
274
288
|
|
|
275
289
|
|
|
276
290
|
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
|
|
277
305
|
|
|
278
306
|
|
|
279
307
|
|
|
@@ -308,7 +336,7 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
308
336
|
* // Verify entries
|
|
309
337
|
* console.log([...map.entries()]); // length: 4;
|
|
310
338
|
*/
|
|
311
|
-
set(key: K, value: V):
|
|
339
|
+
set(key: K, value: V): this;
|
|
312
340
|
/**
|
|
313
341
|
* Insert many entries from an iterable.
|
|
314
342
|
* @remarks Time O(N), Space O(N)
|
|
@@ -336,6 +364,13 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
336
364
|
|
|
337
365
|
|
|
338
366
|
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
|
|
339
374
|
|
|
340
375
|
|
|
341
376
|
|
|
@@ -380,6 +415,13 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
380
415
|
|
|
381
416
|
|
|
382
417
|
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
|
|
383
425
|
|
|
384
426
|
|
|
385
427
|
|
|
@@ -440,6 +482,13 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
440
482
|
|
|
441
483
|
|
|
442
484
|
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
|
|
443
492
|
|
|
444
493
|
|
|
445
494
|
|
|
@@ -485,6 +534,13 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
485
534
|
|
|
486
535
|
|
|
487
536
|
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
|
|
488
544
|
|
|
489
545
|
|
|
490
546
|
|
|
@@ -535,6 +591,13 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
535
591
|
|
|
536
592
|
|
|
537
593
|
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
|
|
600
|
+
|
|
538
601
|
|
|
539
602
|
|
|
540
603
|
|
|
@@ -582,6 +645,13 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
582
645
|
|
|
583
646
|
|
|
584
647
|
|
|
648
|
+
|
|
649
|
+
|
|
650
|
+
|
|
651
|
+
|
|
652
|
+
|
|
653
|
+
|
|
654
|
+
|
|
585
655
|
|
|
586
656
|
|
|
587
657
|
|
|
@@ -629,6 +699,13 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
629
699
|
|
|
630
700
|
|
|
631
701
|
|
|
702
|
+
|
|
703
|
+
|
|
704
|
+
|
|
705
|
+
|
|
706
|
+
|
|
707
|
+
|
|
708
|
+
|
|
632
709
|
|
|
633
710
|
|
|
634
711
|
|
|
@@ -663,7 +740,7 @@ export declare class HashMap<K = any, V = any, R = [K, V]> extends IterableEntry
|
|
|
663
740
|
* console.log(values); // contains 3; // 'Bob', 'Eve'
|
|
664
741
|
* console.log(values); // contains 7;
|
|
665
742
|
*/
|
|
666
|
-
filter(predicate: EntryCallback<K, V, boolean>, thisArg?: unknown):
|
|
743
|
+
filter(predicate: EntryCallback<K, V, boolean>, thisArg?: unknown): this;
|
|
667
744
|
/**
|
|
668
745
|
* (Protected) Create a like-kind instance and seed it from an iterable.
|
|
669
746
|
* @remarks Time O(N), Space O(N)
|
|
@@ -763,9 +840,9 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
763
840
|
* @remarks Time O(1), Space O(1)
|
|
764
841
|
* @param key - Key.
|
|
765
842
|
* @param [value] - Value.
|
|
766
|
-
* @returns
|
|
843
|
+
* @returns This map (for chaining).
|
|
767
844
|
*/
|
|
768
|
-
set(key: K, value?: V):
|
|
845
|
+
set(key: K, value?: V): this;
|
|
769
846
|
setMany(entryOrRawElements: Iterable<R | [K, V]>): boolean[];
|
|
770
847
|
has(key: K): boolean;
|
|
771
848
|
get(key: K): V | undefined;
|
|
@@ -788,9 +865,10 @@ export declare class LinkedHashMap<K = any, V = any, R = [K, V]> extends Iterabl
|
|
|
788
865
|
* Delete the entry at a given index.
|
|
789
866
|
* @remarks Time O(N), Space O(1)
|
|
790
867
|
* @param index - Zero-based index.
|
|
791
|
-
* @returns
|
|
868
|
+
* @returns The removed entry [key, value].
|
|
869
|
+
* @throws {RangeError} If index is out of bounds.
|
|
792
870
|
*/
|
|
793
|
-
deleteAt(index: number):
|
|
871
|
+
deleteAt(index: number): [K, V | undefined];
|
|
794
872
|
isEmpty(): boolean;
|
|
795
873
|
isEntry(rawElement: unknown): rawElement is [K, V];
|
|
796
874
|
clear(): void;
|
|
@@ -9,7 +9,7 @@ import type { Comparator, DFSOrderPattern, ElementCallback, HeapOptions } from '
|
|
|
9
9
|
import { IterableElementBase } from '../base';
|
|
10
10
|
/**
|
|
11
11
|
* Binary heap with pluggable comparator; supports fast insertion and removal of the top element.
|
|
12
|
-
* @remarks
|
|
12
|
+
* @remarks Typical operations: O(log N) insert/remove, O(1) peek. Space O(N).
|
|
13
13
|
* @template E
|
|
14
14
|
* @template R
|
|
15
15
|
* 1. Complete Binary Tree: Heaps are typically complete binary trees, meaning every level is fully filled except possibly for the last level, which has nodes as far left as possible.
|
|
@@ -189,6 +189,13 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
189
189
|
|
|
190
190
|
|
|
191
191
|
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
192
199
|
|
|
193
200
|
|
|
194
201
|
|
|
@@ -237,7 +244,7 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
237
244
|
static heapify<EE = any, RR = any>(elements: Iterable<EE>, options: HeapOptions<EE, RR>): Heap<EE, RR>;
|
|
238
245
|
/**
|
|
239
246
|
* Insert an element.
|
|
240
|
-
* @remarks Time O(
|
|
247
|
+
* @remarks Time O(log N) amortized, Space O(1)
|
|
241
248
|
* @param element - Element to insert.
|
|
242
249
|
* @returns True.
|
|
243
250
|
|
|
@@ -264,6 +271,13 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
264
271
|
|
|
265
272
|
|
|
266
273
|
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
|
|
267
281
|
|
|
268
282
|
|
|
269
283
|
|
|
@@ -315,6 +329,13 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
315
329
|
|
|
316
330
|
|
|
317
331
|
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
|
|
318
339
|
|
|
319
340
|
|
|
320
341
|
|
|
@@ -367,6 +388,40 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
367
388
|
|
|
368
389
|
|
|
369
390
|
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
* @example
|
|
398
|
+
* // Heap with custom comparator (MaxHeap behavior)
|
|
399
|
+
* interface Task {
|
|
400
|
+
* id: number;
|
|
401
|
+
* priority: number;
|
|
402
|
+
* name: string;
|
|
403
|
+
* }
|
|
404
|
+
*
|
|
405
|
+
* // Custom comparator for max heap behavior (higher priority first)
|
|
406
|
+
* const tasks: Task[] = [
|
|
407
|
+
* { id: 1, priority: 5, name: 'Email' },
|
|
408
|
+
* { id: 2, priority: 3, name: 'Chat' },
|
|
409
|
+
* { id: 3, priority: 8, name: 'Alert' }
|
|
410
|
+
* ];
|
|
411
|
+
*
|
|
412
|
+
* const maxHeap = new Heap(tasks, {
|
|
413
|
+
* comparator: (a: Task, b: Task) => b.priority - a.priority
|
|
414
|
+
* });
|
|
415
|
+
*
|
|
416
|
+
* console.log(maxHeap.size); // 3;
|
|
417
|
+
*
|
|
418
|
+
* // Peek returns highest priority task
|
|
419
|
+
* const topTask = maxHeap.peek();
|
|
420
|
+
* console.log(topTask?.priority); // 8;
|
|
421
|
+
* console.log(topTask?.name); // 'Alert';
|
|
422
|
+
*/
|
|
423
|
+
/**
|
|
424
|
+
* @deprecated Use `pop` instead. Will be removed in a future major version.
|
|
370
425
|
* @example
|
|
371
426
|
* // Heap with custom comparator (MaxHeap behavior)
|
|
372
427
|
* interface Task {
|
|
@@ -394,6 +449,12 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
394
449
|
* console.log(topTask?.name); // 'Alert';
|
|
395
450
|
*/
|
|
396
451
|
poll(): E | undefined;
|
|
452
|
+
/**
|
|
453
|
+
* Remove and return the top element (min or max depending on comparator).
|
|
454
|
+
* @remarks Time O(log N) amortized, Space O(1)
|
|
455
|
+
* @returns The removed top element, or undefined if empty.
|
|
456
|
+
*/
|
|
457
|
+
pop(): E | undefined;
|
|
397
458
|
/**
|
|
398
459
|
* Get the current top element without removing it.
|
|
399
460
|
* @remarks Time O(1), Space O(1)
|
|
@@ -422,6 +483,13 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
422
483
|
|
|
423
484
|
|
|
424
485
|
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
|
|
425
493
|
|
|
426
494
|
|
|
427
495
|
|
|
@@ -517,6 +585,13 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
517
585
|
|
|
518
586
|
|
|
519
587
|
|
|
588
|
+
|
|
589
|
+
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
|
|
593
|
+
|
|
594
|
+
|
|
520
595
|
|
|
521
596
|
|
|
522
597
|
|
|
@@ -559,6 +634,13 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
559
634
|
|
|
560
635
|
|
|
561
636
|
|
|
637
|
+
|
|
638
|
+
|
|
639
|
+
|
|
640
|
+
|
|
641
|
+
|
|
642
|
+
|
|
643
|
+
|
|
562
644
|
|
|
563
645
|
|
|
564
646
|
|
|
@@ -574,13 +656,6 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
574
656
|
* console.log(heap.isEmpty()); // true;
|
|
575
657
|
*/
|
|
576
658
|
clear(): void;
|
|
577
|
-
/**
|
|
578
|
-
* Replace the backing array and rebuild the heap.
|
|
579
|
-
* @remarks Time O(N), Space O(N)
|
|
580
|
-
* @param elements - Iterable used to refill the heap.
|
|
581
|
-
* @returns Array of per-node results from fixing steps.
|
|
582
|
-
*/
|
|
583
|
-
refill(elements: Iterable<E>): boolean[];
|
|
584
659
|
/**
|
|
585
660
|
* Check if an equal element exists in the heap.
|
|
586
661
|
* @remarks Time O(N), Space O(1)
|
|
@@ -601,6 +676,13 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
601
676
|
|
|
602
677
|
|
|
603
678
|
|
|
679
|
+
|
|
680
|
+
|
|
681
|
+
|
|
682
|
+
|
|
683
|
+
|
|
684
|
+
|
|
685
|
+
|
|
604
686
|
|
|
605
687
|
|
|
606
688
|
|
|
@@ -642,6 +724,13 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
642
724
|
|
|
643
725
|
|
|
644
726
|
|
|
727
|
+
|
|
728
|
+
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+
|
|
732
|
+
|
|
733
|
+
|
|
645
734
|
|
|
646
735
|
|
|
647
736
|
|
|
@@ -657,13 +746,17 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
657
746
|
* console.log(heap.toArray().includes(4)); // false;
|
|
658
747
|
*/
|
|
659
748
|
delete(element: E): boolean;
|
|
749
|
+
/**
|
|
750
|
+
* @deprecated Use `deleteWhere` instead. Will be removed in a future major version.
|
|
751
|
+
*/
|
|
752
|
+
deleteBy(predicate: (element: E, index: number, heap: this) => boolean): boolean;
|
|
660
753
|
/**
|
|
661
754
|
* Delete the first element that matches a predicate.
|
|
662
755
|
* @remarks Time O(N), Space O(1)
|
|
663
756
|
* @param predicate - Function (element, index, heap) → boolean.
|
|
664
757
|
* @returns True if an element was removed.
|
|
665
758
|
*/
|
|
666
|
-
|
|
759
|
+
deleteWhere(predicate: (element: E, index: number, heap: this) => boolean): boolean;
|
|
667
760
|
/**
|
|
668
761
|
* Set the equality comparator used by has/delete operations.
|
|
669
762
|
* @remarks Time O(1), Space O(1)
|
|
@@ -691,6 +784,13 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
691
784
|
|
|
692
785
|
|
|
693
786
|
|
|
787
|
+
|
|
788
|
+
|
|
789
|
+
|
|
790
|
+
|
|
791
|
+
|
|
792
|
+
|
|
793
|
+
|
|
694
794
|
|
|
695
795
|
|
|
696
796
|
|
|
@@ -740,6 +840,13 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
740
840
|
|
|
741
841
|
|
|
742
842
|
|
|
843
|
+
|
|
844
|
+
|
|
845
|
+
|
|
846
|
+
|
|
847
|
+
|
|
848
|
+
|
|
849
|
+
|
|
743
850
|
|
|
744
851
|
|
|
745
852
|
|
|
@@ -781,6 +888,13 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
781
888
|
|
|
782
889
|
|
|
783
890
|
|
|
891
|
+
|
|
892
|
+
|
|
893
|
+
|
|
894
|
+
|
|
895
|
+
|
|
896
|
+
|
|
897
|
+
|
|
784
898
|
|
|
785
899
|
|
|
786
900
|
|
|
@@ -826,6 +940,13 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
826
940
|
|
|
827
941
|
|
|
828
942
|
|
|
943
|
+
|
|
944
|
+
|
|
945
|
+
|
|
946
|
+
|
|
947
|
+
|
|
948
|
+
|
|
949
|
+
|
|
829
950
|
|
|
830
951
|
|
|
831
952
|
|
|
@@ -871,6 +992,13 @@ export declare class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
871
992
|
|
|
872
993
|
|
|
873
994
|
|
|
995
|
+
|
|
996
|
+
|
|
997
|
+
|
|
998
|
+
|
|
999
|
+
|
|
1000
|
+
|
|
1001
|
+
|
|
874
1002
|
|
|
875
1003
|
|
|
876
1004
|
|
|
@@ -987,9 +1115,9 @@ export declare class FibonacciHeap<E> {
|
|
|
987
1115
|
* Push an element into the root list.
|
|
988
1116
|
* @remarks Time O(1) amortized, Space O(1)
|
|
989
1117
|
* @param element - Element to insert.
|
|
990
|
-
* @returns
|
|
1118
|
+
* @returns True when the element is added.
|
|
991
1119
|
*/
|
|
992
|
-
push(element: E):
|
|
1120
|
+
push(element: E): boolean;
|
|
993
1121
|
peek(): E | undefined;
|
|
994
1122
|
/**
|
|
995
1123
|
* Collect nodes from a circular doubly linked list starting at head.
|