data-structure-typed 2.6.1 → 2.6.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.
Files changed (116) hide show
  1. package/CHANGELOG.md +9 -1
  2. package/dist/cjs/binary-tree.cjs +2927 -23688
  3. package/dist/cjs/graph.cjs +845 -2634
  4. package/dist/cjs/hash.cjs +185 -616
  5. package/dist/cjs/heap.cjs +266 -818
  6. package/dist/cjs/index.cjs +5116 -31358
  7. package/dist/cjs/linked-list.cjs +644 -2615
  8. package/dist/cjs/matrix.cjs +220 -535
  9. package/dist/cjs/priority-queue.cjs +266 -818
  10. package/dist/cjs/queue.cjs +637 -2343
  11. package/dist/cjs/stack.cjs +124 -530
  12. package/dist/cjs/trie.cjs +145 -592
  13. package/dist/cjs-legacy/binary-tree.cjs +4352 -25113
  14. package/dist/cjs-legacy/graph.cjs +847 -2636
  15. package/dist/cjs-legacy/hash.cjs +181 -612
  16. package/dist/cjs-legacy/heap.cjs +266 -818
  17. package/dist/cjs-legacy/index.cjs +6657 -32899
  18. package/dist/cjs-legacy/linked-list.cjs +640 -2611
  19. package/dist/cjs-legacy/matrix.cjs +220 -535
  20. package/dist/cjs-legacy/priority-queue.cjs +266 -818
  21. package/dist/cjs-legacy/queue.cjs +634 -2340
  22. package/dist/cjs-legacy/stack.cjs +124 -530
  23. package/dist/cjs-legacy/trie.cjs +145 -592
  24. package/dist/esm/binary-tree.mjs +2927 -23688
  25. package/dist/esm/graph.mjs +845 -2634
  26. package/dist/esm/hash.mjs +185 -616
  27. package/dist/esm/heap.mjs +266 -818
  28. package/dist/esm/index.mjs +5116 -31358
  29. package/dist/esm/linked-list.mjs +644 -2615
  30. package/dist/esm/matrix.mjs +220 -535
  31. package/dist/esm/priority-queue.mjs +266 -818
  32. package/dist/esm/queue.mjs +637 -2343
  33. package/dist/esm/stack.mjs +124 -530
  34. package/dist/esm/trie.mjs +145 -592
  35. package/dist/esm-legacy/binary-tree.mjs +4352 -25113
  36. package/dist/esm-legacy/graph.mjs +847 -2636
  37. package/dist/esm-legacy/hash.mjs +181 -612
  38. package/dist/esm-legacy/heap.mjs +266 -818
  39. package/dist/esm-legacy/index.mjs +6657 -32899
  40. package/dist/esm-legacy/linked-list.mjs +640 -2611
  41. package/dist/esm-legacy/matrix.mjs +220 -535
  42. package/dist/esm-legacy/priority-queue.mjs +266 -818
  43. package/dist/esm-legacy/queue.mjs +634 -2340
  44. package/dist/esm-legacy/stack.mjs +124 -530
  45. package/dist/esm-legacy/trie.mjs +145 -592
  46. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +29 -500
  47. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +38 -563
  48. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +230 -1212
  49. package/dist/types/data-structures/binary-tree/bst.d.ts +124 -1063
  50. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +99 -854
  51. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +62 -314
  52. package/dist/types/data-structures/binary-tree/tree-map.d.ts +366 -5057
  53. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +277 -4885
  54. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +253 -3929
  55. package/dist/types/data-structures/binary-tree/tree-set.d.ts +261 -4782
  56. package/dist/types/data-structures/graph/abstract-graph.d.ts +44 -44
  57. package/dist/types/data-structures/graph/directed-graph.d.ts +130 -527
  58. package/dist/types/data-structures/graph/undirected-graph.d.ts +125 -482
  59. package/dist/types/data-structures/hash/hash-map.d.ts +132 -562
  60. package/dist/types/data-structures/heap/heap.d.ts +194 -746
  61. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +120 -809
  62. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +121 -733
  63. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +193 -863
  64. package/dist/types/data-structures/matrix/matrix.d.ts +159 -474
  65. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -6
  66. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +6 -11
  67. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  68. package/dist/types/data-structures/queue/deque.d.ts +196 -804
  69. package/dist/types/data-structures/queue/queue.d.ts +99 -585
  70. package/dist/types/data-structures/stack/stack.d.ts +75 -481
  71. package/dist/types/data-structures/trie/trie.d.ts +98 -584
  72. package/dist/umd/data-structure-typed.js +6580 -32822
  73. package/dist/umd/data-structure-typed.min.js +3 -3
  74. package/docs-site-docusaurus/docs/api/classes/AVLTree.md +162 -215
  75. package/docs-site-docusaurus/docs/api/classes/AVLTreeNode.md +9 -9
  76. package/docs-site-docusaurus/docs/api/classes/AbstractGraph.md +47 -47
  77. package/docs-site-docusaurus/docs/api/classes/BST.md +155 -208
  78. package/docs-site-docusaurus/docs/api/classes/BSTNode.md +7 -7
  79. package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +13 -29
  80. package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +104 -158
  81. package/docs-site-docusaurus/docs/api/classes/BinaryTreeNode.md +13 -13
  82. package/docs-site-docusaurus/docs/api/classes/Deque.md +72 -104
  83. package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +60 -80
  84. package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +67 -101
  85. package/docs-site-docusaurus/docs/api/classes/DoublyLinkedListNode.md +6 -6
  86. package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +9 -9
  87. package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +1 -1
  88. package/docs-site-docusaurus/docs/api/classes/HashMap.md +52 -48
  89. package/docs-site-docusaurus/docs/api/classes/Heap.md +40 -68
  90. package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +17 -17
  91. package/docs-site-docusaurus/docs/api/classes/LinearBase.md +38 -38
  92. package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +45 -45
  93. package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +23 -23
  94. package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +68 -96
  95. package/docs-site-docusaurus/docs/api/classes/MapGraph.md +60 -80
  96. package/docs-site-docusaurus/docs/api/classes/Matrix.md +57 -52
  97. package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +38 -66
  98. package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +41 -74
  99. package/docs-site-docusaurus/docs/api/classes/MinHeap.md +38 -66
  100. package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +46 -79
  101. package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +40 -68
  102. package/docs-site-docusaurus/docs/api/classes/Queue.md +54 -78
  103. package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +171 -225
  104. package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +10 -22
  105. package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +68 -98
  106. package/docs-site-docusaurus/docs/api/classes/SinglyLinkedListNode.md +4 -4
  107. package/docs-site-docusaurus/docs/api/classes/SkipList.md +98 -75
  108. package/docs-site-docusaurus/docs/api/classes/Stack.md +33 -53
  109. package/docs-site-docusaurus/docs/api/classes/TreeMap.md +104 -129
  110. package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +57 -124
  111. package/docs-site-docusaurus/docs/api/classes/TreeSet.md +45 -116
  112. package/docs-site-docusaurus/docs/api/classes/Trie.md +37 -61
  113. package/docs-site-docusaurus/docs/api/classes/TrieNode.md +8 -8
  114. package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +59 -77
  115. package/package.json +1 -1
  116. package/src/data-structures/binary-tree/tree-multi-set.ts +15 -11
@@ -322,61 +322,19 @@ var _Heap = class _Heap extends IterableElementBase {
322
322
  return this._elements;
323
323
  }
324
324
  /**
325
- * Get the number of elements.
326
- * @remarks Time O(1), Space O(1)
327
- * @returns Heap size.
328
-
329
-
330
-
331
-
332
-
333
-
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
-
359
-
360
-
361
-
362
-
363
-
364
-
365
-
366
-
367
-
368
-
369
-
370
- * @example
371
- * // Track heap capacity
372
- * const heap = new Heap<number>();
373
- * console.log(heap.size); // 0;
374
- * heap.add(10);
375
- * heap.add(20);
376
- * console.log(heap.size); // 2;
377
- * heap.poll();
378
- * console.log(heap.size); // 1;
379
- */
325
+ * Get the number of elements.
326
+ * @remarks Time O(1), Space O(1)
327
+ * @returns Heap size.
328
+ * @example
329
+ * // Track heap capacity
330
+ * const heap = new Heap<number>();
331
+ * console.log(heap.size); // 0;
332
+ * heap.add(10);
333
+ * heap.add(20);
334
+ * console.log(heap.size); // 2;
335
+ * heap.poll();
336
+ * console.log(heap.size); // 1;
337
+ */
380
338
  get size() {
381
339
  return this.elements.length;
382
340
  }
@@ -389,6 +347,14 @@ var _Heap = class _Heap extends IterableElementBase {
389
347
  var _a;
390
348
  return (_a = this.elements[this.size - 1]) != null ? _a : void 0;
391
349
  }
350
+ /**
351
+ * Get the comparator used to order elements.
352
+ * @remarks Time O(1), Space O(1)
353
+ * @returns Comparator function.
354
+ */
355
+ get comparator() {
356
+ return this._comparator;
357
+ }
392
358
  /**
393
359
  * Create a heap of the same class from an iterable.
394
360
  * @remarks Time O(N), Space O(N)
@@ -415,123 +381,42 @@ var _Heap = class _Heap extends IterableElementBase {
415
381
  return new _Heap(elements, options);
416
382
  }
417
383
  /**
418
- * Insert an element.
419
- * @remarks Time O(log N) amortized, Space O(1)
420
- * @param element - Element to insert.
421
- * @returns True.
422
-
423
-
424
-
425
-
426
-
427
-
428
-
429
-
430
-
431
-
432
-
433
-
434
-
435
-
436
-
437
-
438
-
439
-
440
-
441
-
442
-
443
-
444
-
445
-
446
-
447
-
448
-
449
-
450
-
451
-
452
-
453
-
454
-
455
-
456
-
457
-
458
-
459
-
460
-
461
-
462
-
463
-
464
- * @example
465
- * // basic Heap creation and add operation
466
- * // Create a min heap (default)
467
- * const minHeap = new Heap([5, 3, 7, 1, 9, 2]);
468
- *
469
- * // Verify size
470
- * console.log(minHeap.size); // 6;
471
- *
472
- * // Add new element
473
- * minHeap.add(4);
474
- * console.log(minHeap.size); // 7;
475
- *
476
- * // Min heap property: smallest element at root
477
- * const min = minHeap.peek();
478
- * console.log(min); // 1;
479
- */
384
+ * Insert an element.
385
+ * @remarks Time O(log N) amortized, Space O(1)
386
+ * @param element - Element to insert.
387
+ * @returns True.
388
+ * @example
389
+ * // basic Heap creation and add operation
390
+ * // Create a min heap (default)
391
+ * const minHeap = new Heap([5, 3, 7, 1, 9, 2]);
392
+ *
393
+ * // Verify size
394
+ * console.log(minHeap.size); // 6;
395
+ *
396
+ * // Add new element
397
+ * minHeap.add(4);
398
+ * console.log(minHeap.size); // 7;
399
+ *
400
+ * // Min heap property: smallest element at root
401
+ * const min = minHeap.peek();
402
+ * console.log(min); // 1;
403
+ */
480
404
  add(element) {
481
405
  this._elements.push(element);
482
406
  return this._bubbleUp(this.elements.length - 1);
483
407
  }
484
408
  /**
485
- * Insert many elements from an iterable.
486
- * @remarks Time O(N log N), Space O(1)
487
- * @param elements - Iterable of elements or raw values.
488
- * @returns Array of per-element success flags.
489
-
490
-
491
-
492
-
493
-
494
-
495
-
496
-
497
-
498
-
499
-
500
-
501
-
502
-
503
-
504
-
505
-
506
-
507
-
508
-
509
-
510
-
511
-
512
-
513
-
514
-
515
-
516
-
517
-
518
-
519
-
520
-
521
-
522
-
523
-
524
-
525
-
526
-
527
-
528
- * @example
529
- * // Add multiple elements
530
- * const heap = new Heap<number>([], { comparator: (a, b) => a - b });
531
- * heap.addMany([5, 3, 7, 1]);
532
- * console.log(heap.peek()); // 1;
533
- * console.log(heap.size); // 4;
534
- */
409
+ * Insert many elements from an iterable.
410
+ * @remarks Time O(N log N), Space O(1)
411
+ * @param elements - Iterable of elements or raw values.
412
+ * @returns Array of per-element success flags.
413
+ * @example
414
+ * // Add multiple elements
415
+ * const heap = new Heap<number>([], { comparator: (a, b) => a - b });
416
+ * heap.addMany([5, 3, 7, 1]);
417
+ * console.log(heap.peek()); // 1;
418
+ * console.log(heap.size); // 4;
419
+ */
535
420
  addMany(elements) {
536
421
  const flags = [];
537
422
  for (const el of elements) {
@@ -546,104 +431,63 @@ var _Heap = class _Heap extends IterableElementBase {
546
431
  return flags;
547
432
  }
548
433
  /**
549
- * Remove and return the top element.
550
- * @remarks Time O(log N), Space O(1)
551
- * @returns Top element or undefined.
552
-
553
-
554
-
555
-
556
-
557
-
558
-
559
-
560
-
561
-
562
-
563
-
564
-
565
-
566
-
567
-
568
-
569
-
570
-
571
-
572
-
573
-
574
-
575
-
576
-
577
-
578
-
579
-
580
-
581
-
582
-
583
-
584
-
585
-
586
-
587
-
588
-
589
-
590
- * @example
591
- * // Heap with custom comparator (MaxHeap behavior)
592
- * interface Task {
593
- * id: number;
594
- * priority: number;
595
- * name: string;
596
- * }
597
- *
598
- * // Custom comparator for max heap behavior (higher priority first)
599
- * const tasks: Task[] = [
600
- * { id: 1, priority: 5, name: 'Email' },
601
- * { id: 2, priority: 3, name: 'Chat' },
602
- * { id: 3, priority: 8, name: 'Alert' }
603
- * ];
604
- *
605
- * const maxHeap = new Heap(tasks, {
606
- * comparator: (a: Task, b: Task) => b.priority - a.priority
607
- * });
608
- *
609
- * console.log(maxHeap.size); // 3;
610
- *
611
- * // Peek returns highest priority task
612
- * const topTask = maxHeap.peek();
613
- * console.log(topTask?.priority); // 8;
614
- * console.log(topTask?.name); // 'Alert';
615
- */
434
+ * Remove and return the top element.
435
+ * @remarks Time O(log N), Space O(1)
436
+ * @returns Top element or undefined.
437
+ * @example
438
+ * // Heap with custom comparator (MaxHeap behavior)
439
+ * interface Task {
440
+ * id: number;
441
+ * priority: number;
442
+ * name: string;
443
+ * }
444
+ *
445
+ * // Custom comparator for max heap behavior (higher priority first)
446
+ * const tasks: Task[] = [
447
+ * { id: 1, priority: 5, name: 'Email' },
448
+ * { id: 2, priority: 3, name: 'Chat' },
449
+ * { id: 3, priority: 8, name: 'Alert' }
450
+ * ];
451
+ *
452
+ * const maxHeap = new Heap(tasks, {
453
+ * comparator: (a: Task, b: Task) => b.priority - a.priority
454
+ * });
455
+ *
456
+ * console.log(maxHeap.size); // 3;
457
+ *
458
+ * // Peek returns highest priority task
459
+ * const topTask = maxHeap.peek();
460
+ * console.log(topTask?.priority); // 8;
461
+ * console.log(topTask?.name); // 'Alert';
462
+ */
616
463
  /**
617
- * @deprecated Use `pop` instead. Will be removed in a future major version.
618
-
619
-
620
-
621
- * @example
622
- * // Heap with custom comparator (MaxHeap behavior)
623
- * interface Task {
624
- * id: number;
625
- * priority: number;
626
- * name: string;
627
- * }
628
- *
629
- * // Custom comparator for max heap behavior (higher priority first)
630
- * const tasks: Task[] = [
631
- * { id: 1, priority: 5, name: 'Email' },
632
- * { id: 2, priority: 3, name: 'Chat' },
633
- * { id: 3, priority: 8, name: 'Alert' }
634
- * ];
635
- *
636
- * const maxHeap = new Heap(tasks, {
637
- * comparator: (a: Task, b: Task) => b.priority - a.priority
638
- * });
639
- *
640
- * console.log(maxHeap.size); // 3;
641
- *
642
- * // Peek returns highest priority task
643
- * const topTask = maxHeap.peek();
644
- * console.log(topTask?.priority); // 8;
645
- * console.log(topTask?.name); // 'Alert';
646
- */
464
+ * @deprecated Use `pop` instead. Will be removed in a future major version.
465
+ * @example
466
+ * // Heap with custom comparator (MaxHeap behavior)
467
+ * interface Task {
468
+ * id: number;
469
+ * priority: number;
470
+ * name: string;
471
+ * }
472
+ *
473
+ * // Custom comparator for max heap behavior (higher priority first)
474
+ * const tasks: Task[] = [
475
+ * { id: 1, priority: 5, name: 'Email' },
476
+ * { id: 2, priority: 3, name: 'Chat' },
477
+ * { id: 3, priority: 8, name: 'Alert' }
478
+ * ];
479
+ *
480
+ * const maxHeap = new Heap(tasks, {
481
+ * comparator: (a: Task, b: Task) => b.priority - a.priority
482
+ * });
483
+ *
484
+ * console.log(maxHeap.size); // 3;
485
+ *
486
+ * // Peek returns highest priority task
487
+ * const topTask = maxHeap.peek();
488
+ * console.log(topTask?.priority); // 8;
489
+ * console.log(topTask?.name); // 'Alert';
490
+ */
647
491
  poll() {
648
492
  return this.pop();
649
493
  }
@@ -663,319 +507,125 @@ var _Heap = class _Heap extends IterableElementBase {
663
507
  return value;
664
508
  }
665
509
  /**
666
- * Get the current top element without removing it.
667
- * @remarks Time O(1), Space O(1)
668
- * @returns Top element or undefined.
669
-
670
-
671
-
672
-
673
-
674
-
675
-
676
-
677
-
678
-
679
-
680
-
681
-
682
-
683
-
684
-
685
-
686
-
687
-
688
-
689
-
690
-
691
-
692
-
693
-
694
-
695
-
696
-
697
-
698
-
699
-
700
-
701
-
702
-
703
-
704
-
705
-
706
-
707
-
708
-
709
-
710
-
711
- * @example
712
- * // Heap for event processing with priority
713
- * interface Event {
714
- * id: number;
715
- * type: 'critical' | 'warning' | 'info';
716
- * timestamp: number;
717
- * message: string;
718
- * }
719
- *
720
- * // Custom priority: critical > warning > info
721
- * const priorityMap = { critical: 3, warning: 2, info: 1 };
722
- *
723
- * const eventHeap = new Heap<Event>([], {
724
- * comparator: (a: Event, b: Event) => {
725
- * const priorityA = priorityMap[a.type];
726
- * const priorityB = priorityMap[b.type];
727
- * return priorityB - priorityA; // Higher priority first
728
- * }
729
- * });
730
- *
731
- * // Add events in random order
732
- * eventHeap.add({ id: 1, type: 'info', timestamp: 100, message: 'User logged in' });
733
- * eventHeap.add({ id: 2, type: 'critical', timestamp: 101, message: 'Server down' });
734
- * eventHeap.add({ id: 3, type: 'warning', timestamp: 102, message: 'High memory' });
735
- * eventHeap.add({ id: 4, type: 'info', timestamp: 103, message: 'Cache cleared' });
736
- * eventHeap.add({ id: 5, type: 'critical', timestamp: 104, message: 'Database error' });
737
- *
738
- * console.log(eventHeap.size); // 5;
739
- *
740
- * // Process events by priority (critical first)
741
- * const processedOrder: Event[] = [];
742
- * while (eventHeap.size > 0) {
743
- * const event = eventHeap.poll();
744
- * if (event) {
745
- * processedOrder.push(event);
746
- * }
747
- * }
748
- *
749
- * // Verify critical events came first
750
- * console.log(processedOrder[0].type); // 'critical';
751
- * console.log(processedOrder[1].type); // 'critical';
752
- * console.log(processedOrder[2].type); // 'warning';
753
- * console.log(processedOrder[3].type); // 'info';
754
- * console.log(processedOrder[4].type); // 'info';
755
- *
756
- * // Verify O(log n) operations
757
- * const newHeap = new Heap<number>([5, 3, 7, 1]);
758
- *
759
- * // Add - O(log n)
760
- * newHeap.add(2);
761
- * console.log(newHeap.size); // 5;
762
- *
763
- * // Poll - O(log n)
764
- * const removed = newHeap.poll();
765
- * console.log(removed); // 1;
766
- *
767
- * // Peek - O(1)
768
- * const top = newHeap.peek();
769
- * console.log(top); // 2;
770
- */
510
+ * Get the current top element without removing it.
511
+ * @remarks Time O(1), Space O(1)
512
+ * @returns Top element or undefined.
513
+ * @example
514
+ * // Heap for event processing with priority
515
+ * interface Event {
516
+ * id: number;
517
+ * type: 'critical' | 'warning' | 'info';
518
+ * timestamp: number;
519
+ * message: string;
520
+ * }
521
+ *
522
+ * // Custom priority: critical > warning > info
523
+ * const priorityMap = { critical: 3, warning: 2, info: 1 };
524
+ *
525
+ * const eventHeap = new Heap<Event>([], {
526
+ * comparator: (a: Event, b: Event) => {
527
+ * const priorityA = priorityMap[a.type];
528
+ * const priorityB = priorityMap[b.type];
529
+ * return priorityB - priorityA; // Higher priority first
530
+ * }
531
+ * });
532
+ *
533
+ * // Add events in random order
534
+ * eventHeap.add({ id: 1, type: 'info', timestamp: 100, message: 'User logged in' });
535
+ * eventHeap.add({ id: 2, type: 'critical', timestamp: 101, message: 'Server down' });
536
+ * eventHeap.add({ id: 3, type: 'warning', timestamp: 102, message: 'High memory' });
537
+ * eventHeap.add({ id: 4, type: 'info', timestamp: 103, message: 'Cache cleared' });
538
+ * eventHeap.add({ id: 5, type: 'critical', timestamp: 104, message: 'Database error' });
539
+ *
540
+ * console.log(eventHeap.size); // 5;
541
+ *
542
+ * // Process events by priority (critical first)
543
+ * const processedOrder: Event[] = [];
544
+ * while (eventHeap.size > 0) {
545
+ * const event = eventHeap.poll();
546
+ * if (event) {
547
+ * processedOrder.push(event);
548
+ * }
549
+ * }
550
+ *
551
+ * // Verify critical events came first
552
+ * console.log(processedOrder[0].type); // 'critical';
553
+ * console.log(processedOrder[1].type); // 'critical';
554
+ * console.log(processedOrder[2].type); // 'warning';
555
+ * console.log(processedOrder[3].type); // 'info';
556
+ * console.log(processedOrder[4].type); // 'info';
557
+ *
558
+ * // Verify O(log n) operations
559
+ * const newHeap = new Heap<number>([5, 3, 7, 1]);
560
+ *
561
+ * // Add - O(log n)
562
+ * newHeap.add(2);
563
+ * console.log(newHeap.size); // 5;
564
+ *
565
+ * // Poll - O(log n)
566
+ * const removed = newHeap.poll();
567
+ * console.log(removed); // 1;
568
+ *
569
+ * // Peek - O(1)
570
+ * const top = newHeap.peek();
571
+ * console.log(top); // 2;
572
+ */
771
573
  peek() {
772
574
  return this.elements[0];
773
575
  }
774
576
  /**
775
- * Check whether the heap is empty.
776
- * @remarks Time O(1), Space O(1)
777
- * @returns True if size is 0.
778
-
779
-
780
-
781
-
782
-
783
-
784
-
785
-
786
-
787
-
788
-
789
-
790
-
791
-
792
-
793
-
794
-
795
-
796
-
797
-
798
-
799
-
800
-
801
-
802
-
803
-
804
-
805
-
806
-
807
-
808
-
809
-
810
-
811
-
812
-
813
-
814
-
815
-
816
-
817
-
818
- * @example
819
- * // Check if heap is empty
820
- * const heap = new Heap<number>([], { comparator: (a, b) => a - b });
821
- * console.log(heap.isEmpty()); // true;
822
- * heap.add(1);
823
- * console.log(heap.isEmpty()); // false;
824
- */
577
+ * Check whether the heap is empty.
578
+ * @remarks Time O(1), Space O(1)
579
+ * @returns True if size is 0.
580
+ * @example
581
+ * // Check if heap is empty
582
+ * const heap = new Heap<number>([], { comparator: (a, b) => a - b });
583
+ * console.log(heap.isEmpty()); // true;
584
+ * heap.add(1);
585
+ * console.log(heap.isEmpty()); // false;
586
+ */
825
587
  isEmpty() {
826
588
  return this.size === 0;
827
589
  }
828
590
  /**
829
- * Remove all elements.
830
- * @remarks Time O(1), Space O(1)
831
- * @returns void
832
-
833
-
834
-
835
-
836
-
837
-
838
-
839
-
840
-
841
-
842
-
843
-
844
-
845
-
846
-
847
-
848
-
849
-
850
-
851
-
852
-
853
-
854
-
855
-
856
-
857
-
858
-
859
-
860
-
861
-
862
-
863
-
864
-
865
-
866
-
867
-
868
-
869
-
870
-
871
-
872
- * @example
873
- * // Remove all elements
874
- * const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
875
- * heap.clear();
876
- * console.log(heap.isEmpty()); // true;
877
- */
591
+ * Remove all elements.
592
+ * @remarks Time O(1), Space O(1)
593
+ * @returns void
594
+ * @example
595
+ * // Remove all elements
596
+ * const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
597
+ * heap.clear();
598
+ * console.log(heap.isEmpty()); // true;
599
+ */
878
600
  clear() {
879
601
  this._elements = [];
880
602
  }
881
603
  /**
882
- * Check if an equal element exists in the heap.
883
- * @remarks Time O(N), Space O(1)
884
- * @param element - Element to search for.
885
- * @returns True if found.
886
-
887
-
888
-
889
-
890
-
891
-
892
-
893
-
894
-
895
-
896
-
897
-
898
-
899
-
900
-
901
-
902
-
903
-
904
-
905
-
906
-
907
-
908
-
909
-
910
-
911
-
912
-
913
-
914
-
915
-
916
-
917
-
918
-
919
- * @example
920
- * // Check element existence
921
- * const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
922
- * console.log(heap.has(1)); // true;
923
- * console.log(heap.has(99)); // false;
924
- */
604
+ * Check if an equal element exists in the heap.
605
+ * @remarks Time O(N), Space O(1)
606
+ * @param element - Element to search for.
607
+ * @returns True if found.
608
+ * @example
609
+ * // Check element existence
610
+ * const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
611
+ * console.log(heap.has(1)); // true;
612
+ * console.log(heap.has(99)); // false;
613
+ */
925
614
  has(element) {
926
615
  for (const el of this.elements) if (this._equals(el, element)) return true;
927
616
  return false;
928
617
  }
929
618
  /**
930
- * Delete one occurrence of an element.
931
- * @remarks Time O(N), Space O(1)
932
- * @param element - Element to delete.
933
- * @returns True if an element was removed.
934
-
935
-
936
-
937
-
938
-
939
-
940
-
941
-
942
-
943
-
944
-
945
-
946
-
947
-
948
-
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
- * @example
974
- * // Remove specific element
975
- * const heap = new Heap<number>([3, 1, 4, 1, 5], { comparator: (a, b) => a - b });
976
- * heap.delete(4);
977
- * console.log(heap.toArray().includes(4)); // false;
978
- */
619
+ * Delete one occurrence of an element.
620
+ * @remarks Time O(N), Space O(1)
621
+ * @param element - Element to delete.
622
+ * @returns True if an element was removed.
623
+ * @example
624
+ * // Remove specific element
625
+ * const heap = new Heap<number>([3, 1, 4, 1, 5], { comparator: (a, b) => a - b });
626
+ * heap.delete(4);
627
+ * console.log(heap.toArray().includes(4)); // false;
628
+ */
979
629
  delete(element) {
980
630
  let index = -1;
981
631
  for (let i = 0; i < this.elements.length; i++) {
@@ -1039,49 +689,16 @@ var _Heap = class _Heap extends IterableElementBase {
1039
689
  return this;
1040
690
  }
1041
691
  /**
1042
- * Traverse the binary heap as a complete binary tree and collect elements.
1043
- * @remarks Time O(N), Space O(H)
1044
- * @param [order] - Traversal order: 'PRE' | 'IN' | 'POST'.
1045
- * @returns Array of visited elements.
1046
-
1047
-
1048
-
1049
-
1050
-
1051
-
1052
-
1053
-
1054
-
1055
-
1056
-
1057
-
1058
-
1059
-
1060
-
1061
-
1062
-
1063
-
1064
-
1065
-
1066
-
1067
-
1068
-
1069
-
1070
-
1071
-
1072
-
1073
-
1074
-
1075
-
1076
-
1077
-
1078
-
1079
- * @example
1080
- * // Depth-first traversal
1081
- * const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
1082
- * const result = heap.dfs('IN');
1083
- * console.log(result.length); // 3;
1084
- */
692
+ * Traverse the binary heap as a complete binary tree and collect elements.
693
+ * @remarks Time O(N), Space O(H)
694
+ * @param [order] - Traversal order: 'PRE' | 'IN' | 'POST'.
695
+ * @returns Array of visited elements.
696
+ * @example
697
+ * // Depth-first traversal
698
+ * const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
699
+ * const result = heap.dfs('IN');
700
+ * console.log(result.length); // 3;
701
+ */
1085
702
  dfs(order = "PRE") {
1086
703
  const result = [];
1087
704
  const _dfs = /* @__PURE__ */ __name((index) => {
@@ -1118,57 +735,15 @@ var _Heap = class _Heap extends IterableElementBase {
1118
735
  return results;
1119
736
  }
1120
737
  /**
1121
- * Return all elements in ascending order by repeatedly polling.
1122
- * @remarks Time O(N log N), Space O(N)
1123
- * @returns Sorted array of elements.
1124
-
1125
-
1126
-
1127
-
1128
-
1129
-
1130
-
1131
-
1132
-
1133
-
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
-
1159
-
1160
-
1161
-
1162
-
1163
-
1164
-
1165
-
1166
- * @example
1167
- * // Sort elements using heap
1168
- * const heap = new Heap<number>([5, 1, 3, 2, 4]);
1169
- * const sorted = heap.sort();
1170
- * console.log(sorted); // [1, 2, 3, 4, 5];
1171
- */
738
+ * Return all elements in ascending order by repeatedly polling.
739
+ * @remarks Time O(N log N), Space O(N)
740
+ * @returns Sorted array of elements.
741
+ * @example
742
+ * // Sort elements using heap
743
+ * const heap = new Heap<number>([5, 1, 3, 2, 4]);
744
+ * const sorted = heap.sort();
745
+ * console.log(sorted); // [1, 2, 3, 4, 5];
746
+ */
1172
747
  sort() {
1173
748
  const visited = [];
1174
749
  const cloned = this._createInstance();
@@ -1180,114 +755,34 @@ var _Heap = class _Heap extends IterableElementBase {
1180
755
  return visited;
1181
756
  }
1182
757
  /**
1183
- * Deep clone this heap.
1184
- * @remarks Time O(N), Space O(N)
1185
- * @returns A new heap with the same elements.
1186
-
1187
-
1188
-
1189
-
1190
-
1191
-
1192
-
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
-
1218
-
1219
-
1220
-
1221
-
1222
-
1223
-
1224
-
1225
-
1226
- * @example
1227
- * // Create independent copy
1228
- * const heap = new Heap<number>([3, 1, 4], { comparator: (a, b) => a - b });
1229
- * const copy = heap.clone();
1230
- * copy.poll();
1231
- * console.log(heap.size); // 3;
1232
- * console.log(copy.size); // 2;
1233
- */
758
+ * Deep clone this heap.
759
+ * @remarks Time O(N), Space O(N)
760
+ * @returns A new heap with the same elements.
761
+ * @example
762
+ * // Create independent copy
763
+ * const heap = new Heap<number>([3, 1, 4], { comparator: (a, b) => a - b });
764
+ * const copy = heap.clone();
765
+ * copy.poll();
766
+ * console.log(heap.size); // 3;
767
+ * console.log(copy.size); // 2;
768
+ */
1234
769
  clone() {
1235
770
  const next = this._createInstance();
1236
771
  for (const x of this.elements) next.add(x);
1237
772
  return next;
1238
773
  }
1239
774
  /**
1240
- * Filter elements into a new heap of the same class.
1241
- * @remarks Time O(N log N), Space O(N)
1242
- * @param callback - Predicate (element, index, heap) → boolean to keep element.
1243
- * @param [thisArg] - Value for `this` inside the callback.
1244
- * @returns A new heap with the kept elements.
1245
-
1246
-
1247
-
1248
-
1249
-
1250
-
1251
-
1252
-
1253
-
1254
-
1255
-
1256
-
1257
-
1258
-
1259
-
1260
-
1261
-
1262
-
1263
-
1264
-
1265
-
1266
-
1267
-
1268
-
1269
-
1270
-
1271
-
1272
-
1273
-
1274
-
1275
-
1276
-
1277
-
1278
-
1279
-
1280
-
1281
-
1282
-
1283
-
1284
-
1285
- * @example
1286
- * // Filter elements
1287
- * const heap = new Heap<number>([1, 2, 3, 4, 5], { comparator: (a, b) => a - b });
1288
- * const evens = heap.filter(x => x % 2 === 0);
1289
- * console.log(evens.size); // 2;
1290
- */
775
+ * Filter elements into a new heap of the same class.
776
+ * @remarks Time O(N log N), Space O(N)
777
+ * @param callback - Predicate (element, index, heap) → boolean to keep element.
778
+ * @param [thisArg] - Value for `this` inside the callback.
779
+ * @returns A new heap with the kept elements.
780
+ * @example
781
+ * // Filter elements
782
+ * const heap = new Heap<number>([1, 2, 3, 4, 5], { comparator: (a, b) => a - b });
783
+ * const evens = heap.filter(x => x % 2 === 0);
784
+ * console.log(evens.size); // 2;
785
+ */
1291
786
  filter(callback, thisArg) {
1292
787
  const out = this._createInstance();
1293
788
  let i = 0;
@@ -1301,59 +796,20 @@ var _Heap = class _Heap extends IterableElementBase {
1301
796
  return out;
1302
797
  }
1303
798
  /**
1304
- * Map elements into a new heap of possibly different element type.
1305
- * @remarks Time O(N log N), Space O(N)
1306
- * @template EM
1307
- * @template RM
1308
- * @param callback - Mapping function (element, index, heap) → newElement.
1309
- * @param options - Options for the output heap, including comparator for EM.
1310
- * @param [thisArg] - Value for `this` inside the callback.
1311
- * @returns A new heap with mapped elements.
1312
-
1313
-
1314
-
1315
-
1316
-
1317
-
1318
-
1319
-
1320
-
1321
-
1322
-
1323
-
1324
-
1325
-
1326
-
1327
-
1328
-
1329
-
1330
-
1331
-
1332
-
1333
-
1334
-
1335
-
1336
-
1337
-
1338
-
1339
-
1340
-
1341
-
1342
-
1343
-
1344
-
1345
-
1346
-
1347
-
1348
-
1349
-
1350
-
1351
- * @example
1352
- * // Transform elements
1353
- * const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
1354
- * const doubled = heap.map(x => x * 2, { comparator: (a, b) => a - b });
1355
- * console.log(doubled.peek()); // 2;
1356
- */
799
+ * Map elements into a new heap of possibly different element type.
800
+ * @remarks Time O(N log N), Space O(N)
801
+ * @template EM
802
+ * @template RM
803
+ * @param callback - Mapping function (element, index, heap) → newElement.
804
+ * @param options - Options for the output heap, including comparator for EM.
805
+ * @param [thisArg] - Value for `this` inside the callback.
806
+ * @returns A new heap with mapped elements.
807
+ * @example
808
+ * // Transform elements
809
+ * const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
810
+ * const doubled = heap.map(x => x * 2, { comparator: (a, b) => a - b });
811
+ * console.log(doubled.peek()); // 2;
812
+ */
1357
813
  map(callback, options, thisArg) {
1358
814
  const { comparator, toElementFn, ...rest } = options != null ? options : {};
1359
815
  if (!comparator) raise(TypeError, ERR.comparatorRequired("Heap.map"));
@@ -1381,14 +837,6 @@ var _Heap = class _Heap extends IterableElementBase {
1381
837
  }
1382
838
  return out;
1383
839
  }
1384
- /**
1385
- * Get the comparator used to order elements.
1386
- * @remarks Time O(1), Space O(1)
1387
- * @returns Comparator function.
1388
- */
1389
- get comparator() {
1390
- return this._comparator;
1391
- }
1392
840
  *_getIterator() {
1393
841
  for (const element of this.elements) yield element;
1394
842
  }
@@ -1482,10 +930,10 @@ var _FibonacciHeap = class _FibonacciHeap {
1482
930
  * @returns New FibonacciHeap instance.
1483
931
  */
1484
932
  constructor(comparator) {
933
+ __publicField(this, "_comparator");
1485
934
  __publicField(this, "_root");
1486
935
  __publicField(this, "_size", 0);
1487
936
  __publicField(this, "_min");
1488
- __publicField(this, "_comparator");
1489
937
  this.clear();
1490
938
  this._comparator = comparator || this._defaultComparator;
1491
939
  if (typeof this.comparator !== "function") raise(TypeError, ERR.notAFunction("comparator", "FibonacciHeap"));