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
@@ -324,61 +324,19 @@ var _Heap = class _Heap extends IterableElementBase {
324
324
  return this._elements;
325
325
  }
326
326
  /**
327
- * Get the number of elements.
328
- * @remarks Time O(1), Space O(1)
329
- * @returns Heap size.
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
-
371
-
372
- * @example
373
- * // Track heap capacity
374
- * const heap = new Heap<number>();
375
- * console.log(heap.size); // 0;
376
- * heap.add(10);
377
- * heap.add(20);
378
- * console.log(heap.size); // 2;
379
- * heap.poll();
380
- * console.log(heap.size); // 1;
381
- */
327
+ * Get the number of elements.
328
+ * @remarks Time O(1), Space O(1)
329
+ * @returns Heap size.
330
+ * @example
331
+ * // Track heap capacity
332
+ * const heap = new Heap<number>();
333
+ * console.log(heap.size); // 0;
334
+ * heap.add(10);
335
+ * heap.add(20);
336
+ * console.log(heap.size); // 2;
337
+ * heap.poll();
338
+ * console.log(heap.size); // 1;
339
+ */
382
340
  get size() {
383
341
  return this.elements.length;
384
342
  }
@@ -391,6 +349,14 @@ var _Heap = class _Heap extends IterableElementBase {
391
349
  var _a;
392
350
  return (_a = this.elements[this.size - 1]) != null ? _a : void 0;
393
351
  }
352
+ /**
353
+ * Get the comparator used to order elements.
354
+ * @remarks Time O(1), Space O(1)
355
+ * @returns Comparator function.
356
+ */
357
+ get comparator() {
358
+ return this._comparator;
359
+ }
394
360
  /**
395
361
  * Create a heap of the same class from an iterable.
396
362
  * @remarks Time O(N), Space O(N)
@@ -417,123 +383,42 @@ var _Heap = class _Heap extends IterableElementBase {
417
383
  return new _Heap(elements, options);
418
384
  }
419
385
  /**
420
- * Insert an element.
421
- * @remarks Time O(log N) amortized, Space O(1)
422
- * @param element - Element to insert.
423
- * @returns True.
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
-
465
-
466
- * @example
467
- * // basic Heap creation and add operation
468
- * // Create a min heap (default)
469
- * const minHeap = new Heap([5, 3, 7, 1, 9, 2]);
470
- *
471
- * // Verify size
472
- * console.log(minHeap.size); // 6;
473
- *
474
- * // Add new element
475
- * minHeap.add(4);
476
- * console.log(minHeap.size); // 7;
477
- *
478
- * // Min heap property: smallest element at root
479
- * const min = minHeap.peek();
480
- * console.log(min); // 1;
481
- */
386
+ * Insert an element.
387
+ * @remarks Time O(log N) amortized, Space O(1)
388
+ * @param element - Element to insert.
389
+ * @returns True.
390
+ * @example
391
+ * // basic Heap creation and add operation
392
+ * // Create a min heap (default)
393
+ * const minHeap = new Heap([5, 3, 7, 1, 9, 2]);
394
+ *
395
+ * // Verify size
396
+ * console.log(minHeap.size); // 6;
397
+ *
398
+ * // Add new element
399
+ * minHeap.add(4);
400
+ * console.log(minHeap.size); // 7;
401
+ *
402
+ * // Min heap property: smallest element at root
403
+ * const min = minHeap.peek();
404
+ * console.log(min); // 1;
405
+ */
482
406
  add(element) {
483
407
  this._elements.push(element);
484
408
  return this._bubbleUp(this.elements.length - 1);
485
409
  }
486
410
  /**
487
- * Insert many elements from an iterable.
488
- * @remarks Time O(N log N), Space O(1)
489
- * @param elements - Iterable of elements or raw values.
490
- * @returns Array of per-element success flags.
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
-
529
-
530
- * @example
531
- * // Add multiple elements
532
- * const heap = new Heap<number>([], { comparator: (a, b) => a - b });
533
- * heap.addMany([5, 3, 7, 1]);
534
- * console.log(heap.peek()); // 1;
535
- * console.log(heap.size); // 4;
536
- */
411
+ * Insert many elements from an iterable.
412
+ * @remarks Time O(N log N), Space O(1)
413
+ * @param elements - Iterable of elements or raw values.
414
+ * @returns Array of per-element success flags.
415
+ * @example
416
+ * // Add multiple elements
417
+ * const heap = new Heap<number>([], { comparator: (a, b) => a - b });
418
+ * heap.addMany([5, 3, 7, 1]);
419
+ * console.log(heap.peek()); // 1;
420
+ * console.log(heap.size); // 4;
421
+ */
537
422
  addMany(elements) {
538
423
  const flags = [];
539
424
  for (const el of elements) {
@@ -548,104 +433,63 @@ var _Heap = class _Heap extends IterableElementBase {
548
433
  return flags;
549
434
  }
550
435
  /**
551
- * Remove and return the top element.
552
- * @remarks Time O(log N), Space O(1)
553
- * @returns Top element or undefined.
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
-
591
-
592
- * @example
593
- * // Heap with custom comparator (MaxHeap behavior)
594
- * interface Task {
595
- * id: number;
596
- * priority: number;
597
- * name: string;
598
- * }
599
- *
600
- * // Custom comparator for max heap behavior (higher priority first)
601
- * const tasks: Task[] = [
602
- * { id: 1, priority: 5, name: 'Email' },
603
- * { id: 2, priority: 3, name: 'Chat' },
604
- * { id: 3, priority: 8, name: 'Alert' }
605
- * ];
606
- *
607
- * const maxHeap = new Heap(tasks, {
608
- * comparator: (a: Task, b: Task) => b.priority - a.priority
609
- * });
610
- *
611
- * console.log(maxHeap.size); // 3;
612
- *
613
- * // Peek returns highest priority task
614
- * const topTask = maxHeap.peek();
615
- * console.log(topTask?.priority); // 8;
616
- * console.log(topTask?.name); // 'Alert';
617
- */
436
+ * Remove and return the top element.
437
+ * @remarks Time O(log N), Space O(1)
438
+ * @returns Top element or undefined.
439
+ * @example
440
+ * // Heap with custom comparator (MaxHeap behavior)
441
+ * interface Task {
442
+ * id: number;
443
+ * priority: number;
444
+ * name: string;
445
+ * }
446
+ *
447
+ * // Custom comparator for max heap behavior (higher priority first)
448
+ * const tasks: Task[] = [
449
+ * { id: 1, priority: 5, name: 'Email' },
450
+ * { id: 2, priority: 3, name: 'Chat' },
451
+ * { id: 3, priority: 8, name: 'Alert' }
452
+ * ];
453
+ *
454
+ * const maxHeap = new Heap(tasks, {
455
+ * comparator: (a: Task, b: Task) => b.priority - a.priority
456
+ * });
457
+ *
458
+ * console.log(maxHeap.size); // 3;
459
+ *
460
+ * // Peek returns highest priority task
461
+ * const topTask = maxHeap.peek();
462
+ * console.log(topTask?.priority); // 8;
463
+ * console.log(topTask?.name); // 'Alert';
464
+ */
618
465
  /**
619
- * @deprecated Use `pop` instead. Will be removed in a future major version.
620
-
621
-
622
-
623
- * @example
624
- * // Heap with custom comparator (MaxHeap behavior)
625
- * interface Task {
626
- * id: number;
627
- * priority: number;
628
- * name: string;
629
- * }
630
- *
631
- * // Custom comparator for max heap behavior (higher priority first)
632
- * const tasks: Task[] = [
633
- * { id: 1, priority: 5, name: 'Email' },
634
- * { id: 2, priority: 3, name: 'Chat' },
635
- * { id: 3, priority: 8, name: 'Alert' }
636
- * ];
637
- *
638
- * const maxHeap = new Heap(tasks, {
639
- * comparator: (a: Task, b: Task) => b.priority - a.priority
640
- * });
641
- *
642
- * console.log(maxHeap.size); // 3;
643
- *
644
- * // Peek returns highest priority task
645
- * const topTask = maxHeap.peek();
646
- * console.log(topTask?.priority); // 8;
647
- * console.log(topTask?.name); // 'Alert';
648
- */
466
+ * @deprecated Use `pop` instead. Will be removed in a future major version.
467
+ * @example
468
+ * // Heap with custom comparator (MaxHeap behavior)
469
+ * interface Task {
470
+ * id: number;
471
+ * priority: number;
472
+ * name: string;
473
+ * }
474
+ *
475
+ * // Custom comparator for max heap behavior (higher priority first)
476
+ * const tasks: Task[] = [
477
+ * { id: 1, priority: 5, name: 'Email' },
478
+ * { id: 2, priority: 3, name: 'Chat' },
479
+ * { id: 3, priority: 8, name: 'Alert' }
480
+ * ];
481
+ *
482
+ * const maxHeap = new Heap(tasks, {
483
+ * comparator: (a: Task, b: Task) => b.priority - a.priority
484
+ * });
485
+ *
486
+ * console.log(maxHeap.size); // 3;
487
+ *
488
+ * // Peek returns highest priority task
489
+ * const topTask = maxHeap.peek();
490
+ * console.log(topTask?.priority); // 8;
491
+ * console.log(topTask?.name); // 'Alert';
492
+ */
649
493
  poll() {
650
494
  return this.pop();
651
495
  }
@@ -665,319 +509,125 @@ var _Heap = class _Heap extends IterableElementBase {
665
509
  return value;
666
510
  }
667
511
  /**
668
- * Get the current top element without removing it.
669
- * @remarks Time O(1), Space O(1)
670
- * @returns Top element or undefined.
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
-
712
-
713
- * @example
714
- * // Heap for event processing with priority
715
- * interface Event {
716
- * id: number;
717
- * type: 'critical' | 'warning' | 'info';
718
- * timestamp: number;
719
- * message: string;
720
- * }
721
- *
722
- * // Custom priority: critical > warning > info
723
- * const priorityMap = { critical: 3, warning: 2, info: 1 };
724
- *
725
- * const eventHeap = new Heap<Event>([], {
726
- * comparator: (a: Event, b: Event) => {
727
- * const priorityA = priorityMap[a.type];
728
- * const priorityB = priorityMap[b.type];
729
- * return priorityB - priorityA; // Higher priority first
730
- * }
731
- * });
732
- *
733
- * // Add events in random order
734
- * eventHeap.add({ id: 1, type: 'info', timestamp: 100, message: 'User logged in' });
735
- * eventHeap.add({ id: 2, type: 'critical', timestamp: 101, message: 'Server down' });
736
- * eventHeap.add({ id: 3, type: 'warning', timestamp: 102, message: 'High memory' });
737
- * eventHeap.add({ id: 4, type: 'info', timestamp: 103, message: 'Cache cleared' });
738
- * eventHeap.add({ id: 5, type: 'critical', timestamp: 104, message: 'Database error' });
739
- *
740
- * console.log(eventHeap.size); // 5;
741
- *
742
- * // Process events by priority (critical first)
743
- * const processedOrder: Event[] = [];
744
- * while (eventHeap.size > 0) {
745
- * const event = eventHeap.poll();
746
- * if (event) {
747
- * processedOrder.push(event);
748
- * }
749
- * }
750
- *
751
- * // Verify critical events came first
752
- * console.log(processedOrder[0].type); // 'critical';
753
- * console.log(processedOrder[1].type); // 'critical';
754
- * console.log(processedOrder[2].type); // 'warning';
755
- * console.log(processedOrder[3].type); // 'info';
756
- * console.log(processedOrder[4].type); // 'info';
757
- *
758
- * // Verify O(log n) operations
759
- * const newHeap = new Heap<number>([5, 3, 7, 1]);
760
- *
761
- * // Add - O(log n)
762
- * newHeap.add(2);
763
- * console.log(newHeap.size); // 5;
764
- *
765
- * // Poll - O(log n)
766
- * const removed = newHeap.poll();
767
- * console.log(removed); // 1;
768
- *
769
- * // Peek - O(1)
770
- * const top = newHeap.peek();
771
- * console.log(top); // 2;
772
- */
512
+ * Get the current top element without removing it.
513
+ * @remarks Time O(1), Space O(1)
514
+ * @returns Top element or undefined.
515
+ * @example
516
+ * // Heap for event processing with priority
517
+ * interface Event {
518
+ * id: number;
519
+ * type: 'critical' | 'warning' | 'info';
520
+ * timestamp: number;
521
+ * message: string;
522
+ * }
523
+ *
524
+ * // Custom priority: critical > warning > info
525
+ * const priorityMap = { critical: 3, warning: 2, info: 1 };
526
+ *
527
+ * const eventHeap = new Heap<Event>([], {
528
+ * comparator: (a: Event, b: Event) => {
529
+ * const priorityA = priorityMap[a.type];
530
+ * const priorityB = priorityMap[b.type];
531
+ * return priorityB - priorityA; // Higher priority first
532
+ * }
533
+ * });
534
+ *
535
+ * // Add events in random order
536
+ * eventHeap.add({ id: 1, type: 'info', timestamp: 100, message: 'User logged in' });
537
+ * eventHeap.add({ id: 2, type: 'critical', timestamp: 101, message: 'Server down' });
538
+ * eventHeap.add({ id: 3, type: 'warning', timestamp: 102, message: 'High memory' });
539
+ * eventHeap.add({ id: 4, type: 'info', timestamp: 103, message: 'Cache cleared' });
540
+ * eventHeap.add({ id: 5, type: 'critical', timestamp: 104, message: 'Database error' });
541
+ *
542
+ * console.log(eventHeap.size); // 5;
543
+ *
544
+ * // Process events by priority (critical first)
545
+ * const processedOrder: Event[] = [];
546
+ * while (eventHeap.size > 0) {
547
+ * const event = eventHeap.poll();
548
+ * if (event) {
549
+ * processedOrder.push(event);
550
+ * }
551
+ * }
552
+ *
553
+ * // Verify critical events came first
554
+ * console.log(processedOrder[0].type); // 'critical';
555
+ * console.log(processedOrder[1].type); // 'critical';
556
+ * console.log(processedOrder[2].type); // 'warning';
557
+ * console.log(processedOrder[3].type); // 'info';
558
+ * console.log(processedOrder[4].type); // 'info';
559
+ *
560
+ * // Verify O(log n) operations
561
+ * const newHeap = new Heap<number>([5, 3, 7, 1]);
562
+ *
563
+ * // Add - O(log n)
564
+ * newHeap.add(2);
565
+ * console.log(newHeap.size); // 5;
566
+ *
567
+ * // Poll - O(log n)
568
+ * const removed = newHeap.poll();
569
+ * console.log(removed); // 1;
570
+ *
571
+ * // Peek - O(1)
572
+ * const top = newHeap.peek();
573
+ * console.log(top); // 2;
574
+ */
773
575
  peek() {
774
576
  return this.elements[0];
775
577
  }
776
578
  /**
777
- * Check whether the heap is empty.
778
- * @remarks Time O(1), Space O(1)
779
- * @returns True if size is 0.
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
-
819
-
820
- * @example
821
- * // Check if heap is empty
822
- * const heap = new Heap<number>([], { comparator: (a, b) => a - b });
823
- * console.log(heap.isEmpty()); // true;
824
- * heap.add(1);
825
- * console.log(heap.isEmpty()); // false;
826
- */
579
+ * Check whether the heap is empty.
580
+ * @remarks Time O(1), Space O(1)
581
+ * @returns True if size is 0.
582
+ * @example
583
+ * // Check if heap is empty
584
+ * const heap = new Heap<number>([], { comparator: (a, b) => a - b });
585
+ * console.log(heap.isEmpty()); // true;
586
+ * heap.add(1);
587
+ * console.log(heap.isEmpty()); // false;
588
+ */
827
589
  isEmpty() {
828
590
  return this.size === 0;
829
591
  }
830
592
  /**
831
- * Remove all elements.
832
- * @remarks Time O(1), Space O(1)
833
- * @returns void
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
-
873
-
874
- * @example
875
- * // Remove all elements
876
- * const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
877
- * heap.clear();
878
- * console.log(heap.isEmpty()); // true;
879
- */
593
+ * Remove all elements.
594
+ * @remarks Time O(1), Space O(1)
595
+ * @returns void
596
+ * @example
597
+ * // Remove all elements
598
+ * const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
599
+ * heap.clear();
600
+ * console.log(heap.isEmpty()); // true;
601
+ */
880
602
  clear() {
881
603
  this._elements = [];
882
604
  }
883
605
  /**
884
- * Check if an equal element exists in the heap.
885
- * @remarks Time O(N), Space O(1)
886
- * @param element - Element to search for.
887
- * @returns True if found.
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
-
920
-
921
- * @example
922
- * // Check element existence
923
- * const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
924
- * console.log(heap.has(1)); // true;
925
- * console.log(heap.has(99)); // false;
926
- */
606
+ * Check if an equal element exists in the heap.
607
+ * @remarks Time O(N), Space O(1)
608
+ * @param element - Element to search for.
609
+ * @returns True if found.
610
+ * @example
611
+ * // Check element existence
612
+ * const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
613
+ * console.log(heap.has(1)); // true;
614
+ * console.log(heap.has(99)); // false;
615
+ */
927
616
  has(element) {
928
617
  for (const el of this.elements) if (this._equals(el, element)) return true;
929
618
  return false;
930
619
  }
931
620
  /**
932
- * Delete one occurrence of an element.
933
- * @remarks Time O(N), Space O(1)
934
- * @param element - Element to delete.
935
- * @returns True if an element was removed.
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
-
974
-
975
- * @example
976
- * // Remove specific element
977
- * const heap = new Heap<number>([3, 1, 4, 1, 5], { comparator: (a, b) => a - b });
978
- * heap.delete(4);
979
- * console.log(heap.toArray().includes(4)); // false;
980
- */
621
+ * Delete one occurrence of an element.
622
+ * @remarks Time O(N), Space O(1)
623
+ * @param element - Element to delete.
624
+ * @returns True if an element was removed.
625
+ * @example
626
+ * // Remove specific element
627
+ * const heap = new Heap<number>([3, 1, 4, 1, 5], { comparator: (a, b) => a - b });
628
+ * heap.delete(4);
629
+ * console.log(heap.toArray().includes(4)); // false;
630
+ */
981
631
  delete(element) {
982
632
  let index = -1;
983
633
  for (let i = 0; i < this.elements.length; i++) {
@@ -1041,49 +691,16 @@ var _Heap = class _Heap extends IterableElementBase {
1041
691
  return this;
1042
692
  }
1043
693
  /**
1044
- * Traverse the binary heap as a complete binary tree and collect elements.
1045
- * @remarks Time O(N), Space O(H)
1046
- * @param [order] - Traversal order: 'PRE' | 'IN' | 'POST'.
1047
- * @returns Array of visited elements.
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
-
1080
-
1081
- * @example
1082
- * // Depth-first traversal
1083
- * const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
1084
- * const result = heap.dfs('IN');
1085
- * console.log(result.length); // 3;
1086
- */
694
+ * Traverse the binary heap as a complete binary tree and collect elements.
695
+ * @remarks Time O(N), Space O(H)
696
+ * @param [order] - Traversal order: 'PRE' | 'IN' | 'POST'.
697
+ * @returns Array of visited elements.
698
+ * @example
699
+ * // Depth-first traversal
700
+ * const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
701
+ * const result = heap.dfs('IN');
702
+ * console.log(result.length); // 3;
703
+ */
1087
704
  dfs(order = "PRE") {
1088
705
  const result = [];
1089
706
  const _dfs = /* @__PURE__ */ __name((index) => {
@@ -1120,57 +737,15 @@ var _Heap = class _Heap extends IterableElementBase {
1120
737
  return results;
1121
738
  }
1122
739
  /**
1123
- * Return all elements in ascending order by repeatedly polling.
1124
- * @remarks Time O(N log N), Space O(N)
1125
- * @returns Sorted array of elements.
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
-
1167
-
1168
- * @example
1169
- * // Sort elements using heap
1170
- * const heap = new Heap<number>([5, 1, 3, 2, 4]);
1171
- * const sorted = heap.sort();
1172
- * console.log(sorted); // [1, 2, 3, 4, 5];
1173
- */
740
+ * Return all elements in ascending order by repeatedly polling.
741
+ * @remarks Time O(N log N), Space O(N)
742
+ * @returns Sorted array of elements.
743
+ * @example
744
+ * // Sort elements using heap
745
+ * const heap = new Heap<number>([5, 1, 3, 2, 4]);
746
+ * const sorted = heap.sort();
747
+ * console.log(sorted); // [1, 2, 3, 4, 5];
748
+ */
1174
749
  sort() {
1175
750
  const visited = [];
1176
751
  const cloned = this._createInstance();
@@ -1182,114 +757,34 @@ var _Heap = class _Heap extends IterableElementBase {
1182
757
  return visited;
1183
758
  }
1184
759
  /**
1185
- * Deep clone this heap.
1186
- * @remarks Time O(N), Space O(N)
1187
- * @returns A new heap with the same elements.
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
-
1227
-
1228
- * @example
1229
- * // Create independent copy
1230
- * const heap = new Heap<number>([3, 1, 4], { comparator: (a, b) => a - b });
1231
- * const copy = heap.clone();
1232
- * copy.poll();
1233
- * console.log(heap.size); // 3;
1234
- * console.log(copy.size); // 2;
1235
- */
760
+ * Deep clone this heap.
761
+ * @remarks Time O(N), Space O(N)
762
+ * @returns A new heap with the same elements.
763
+ * @example
764
+ * // Create independent copy
765
+ * const heap = new Heap<number>([3, 1, 4], { comparator: (a, b) => a - b });
766
+ * const copy = heap.clone();
767
+ * copy.poll();
768
+ * console.log(heap.size); // 3;
769
+ * console.log(copy.size); // 2;
770
+ */
1236
771
  clone() {
1237
772
  const next = this._createInstance();
1238
773
  for (const x of this.elements) next.add(x);
1239
774
  return next;
1240
775
  }
1241
776
  /**
1242
- * Filter elements into a new heap of the same class.
1243
- * @remarks Time O(N log N), Space O(N)
1244
- * @param callback - Predicate (element, index, heap) → boolean to keep element.
1245
- * @param [thisArg] - Value for `this` inside the callback.
1246
- * @returns A new heap with the kept elements.
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
-
1286
-
1287
- * @example
1288
- * // Filter elements
1289
- * const heap = new Heap<number>([1, 2, 3, 4, 5], { comparator: (a, b) => a - b });
1290
- * const evens = heap.filter(x => x % 2 === 0);
1291
- * console.log(evens.size); // 2;
1292
- */
777
+ * Filter elements into a new heap of the same class.
778
+ * @remarks Time O(N log N), Space O(N)
779
+ * @param callback - Predicate (element, index, heap) → boolean to keep element.
780
+ * @param [thisArg] - Value for `this` inside the callback.
781
+ * @returns A new heap with the kept elements.
782
+ * @example
783
+ * // Filter elements
784
+ * const heap = new Heap<number>([1, 2, 3, 4, 5], { comparator: (a, b) => a - b });
785
+ * const evens = heap.filter(x => x % 2 === 0);
786
+ * console.log(evens.size); // 2;
787
+ */
1293
788
  filter(callback, thisArg) {
1294
789
  const out = this._createInstance();
1295
790
  let i = 0;
@@ -1303,59 +798,20 @@ var _Heap = class _Heap extends IterableElementBase {
1303
798
  return out;
1304
799
  }
1305
800
  /**
1306
- * Map elements into a new heap of possibly different element type.
1307
- * @remarks Time O(N log N), Space O(N)
1308
- * @template EM
1309
- * @template RM
1310
- * @param callback - Mapping function (element, index, heap) → newElement.
1311
- * @param options - Options for the output heap, including comparator for EM.
1312
- * @param [thisArg] - Value for `this` inside the callback.
1313
- * @returns A new heap with mapped elements.
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
-
1352
-
1353
- * @example
1354
- * // Transform elements
1355
- * const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
1356
- * const doubled = heap.map(x => x * 2, { comparator: (a, b) => a - b });
1357
- * console.log(doubled.peek()); // 2;
1358
- */
801
+ * Map elements into a new heap of possibly different element type.
802
+ * @remarks Time O(N log N), Space O(N)
803
+ * @template EM
804
+ * @template RM
805
+ * @param callback - Mapping function (element, index, heap) → newElement.
806
+ * @param options - Options for the output heap, including comparator for EM.
807
+ * @param [thisArg] - Value for `this` inside the callback.
808
+ * @returns A new heap with mapped elements.
809
+ * @example
810
+ * // Transform elements
811
+ * const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
812
+ * const doubled = heap.map(x => x * 2, { comparator: (a, b) => a - b });
813
+ * console.log(doubled.peek()); // 2;
814
+ */
1359
815
  map(callback, options, thisArg) {
1360
816
  const { comparator, toElementFn, ...rest } = options != null ? options : {};
1361
817
  if (!comparator) raise(TypeError, ERR.comparatorRequired("Heap.map"));
@@ -1383,14 +839,6 @@ var _Heap = class _Heap extends IterableElementBase {
1383
839
  }
1384
840
  return out;
1385
841
  }
1386
- /**
1387
- * Get the comparator used to order elements.
1388
- * @remarks Time O(1), Space O(1)
1389
- * @returns Comparator function.
1390
- */
1391
- get comparator() {
1392
- return this._comparator;
1393
- }
1394
842
  *_getIterator() {
1395
843
  for (const element of this.elements) yield element;
1396
844
  }
@@ -1484,10 +932,10 @@ var _FibonacciHeap = class _FibonacciHeap {
1484
932
  * @returns New FibonacciHeap instance.
1485
933
  */
1486
934
  constructor(comparator) {
935
+ __publicField(this, "_comparator");
1487
936
  __publicField(this, "_root");
1488
937
  __publicField(this, "_size", 0);
1489
938
  __publicField(this, "_min");
1490
- __publicField(this, "_comparator");
1491
939
  this.clear();
1492
940
  this._comparator = comparator || this._defaultComparator;
1493
941
  if (typeof this.comparator !== "function") raise(TypeError, ERR.notAFunction("comparator", "FibonacciHeap"));