max-priority-queue-typed 2.4.5 → 2.5.1

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 (94) hide show
  1. package/README.md +63 -0
  2. package/dist/cjs/index.cjs +694 -119
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/cjs-legacy/index.cjs +693 -118
  5. package/dist/cjs-legacy/index.cjs.map +1 -1
  6. package/dist/esm/index.mjs +694 -119
  7. package/dist/esm/index.mjs.map +1 -1
  8. package/dist/esm-legacy/index.mjs +693 -118
  9. package/dist/esm-legacy/index.mjs.map +1 -1
  10. package/dist/types/data-structures/base/index.d.ts +1 -0
  11. package/dist/types/data-structures/base/iterable-element-base.d.ts +1 -1
  12. package/dist/types/data-structures/base/iterable-entry-base.d.ts +8 -8
  13. package/dist/types/data-structures/base/linear-base.d.ts +3 -3
  14. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +380 -51
  15. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +487 -147
  16. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +956 -80
  17. package/dist/types/data-structures/binary-tree/bst.d.ts +816 -29
  18. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +610 -31
  19. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +326 -135
  20. package/dist/types/data-structures/binary-tree/tree-map.d.ts +3781 -6
  21. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3607 -201
  22. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2874 -65
  23. package/dist/types/data-structures/binary-tree/tree-set.d.ts +3528 -6
  24. package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
  25. package/dist/types/data-structures/graph/directed-graph.d.ts +429 -47
  26. package/dist/types/data-structures/graph/map-graph.d.ts +59 -1
  27. package/dist/types/data-structures/graph/undirected-graph.d.ts +393 -59
  28. package/dist/types/data-structures/hash/hash-map.d.ts +473 -89
  29. package/dist/types/data-structures/heap/heap.d.ts +581 -99
  30. package/dist/types/data-structures/heap/max-heap.d.ts +46 -0
  31. package/dist/types/data-structures/heap/min-heap.d.ts +59 -0
  32. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +646 -47
  33. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +596 -68
  34. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +793 -12
  35. package/dist/types/data-structures/matrix/matrix.d.ts +499 -0
  36. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +57 -0
  37. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +60 -0
  38. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +60 -0
  39. package/dist/types/data-structures/queue/deque.d.ts +593 -71
  40. package/dist/types/data-structures/queue/queue.d.ts +463 -42
  41. package/dist/types/data-structures/stack/stack.d.ts +384 -32
  42. package/dist/types/data-structures/trie/trie.d.ts +470 -48
  43. package/dist/types/interfaces/graph.d.ts +1 -1
  44. package/dist/types/types/common.d.ts +2 -2
  45. package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -1
  46. package/dist/types/types/data-structures/heap/heap.d.ts +1 -0
  47. package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +1 -4
  48. package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
  49. package/dist/types/types/utils/validate-type.d.ts +4 -4
  50. package/dist/umd/max-priority-queue-typed.js +691 -116
  51. package/dist/umd/max-priority-queue-typed.js.map +1 -1
  52. package/dist/umd/max-priority-queue-typed.min.js +1 -1
  53. package/dist/umd/max-priority-queue-typed.min.js.map +1 -1
  54. package/package.json +2 -2
  55. package/src/data-structures/base/index.ts +1 -0
  56. package/src/data-structures/base/iterable-element-base.ts +4 -5
  57. package/src/data-structures/base/iterable-entry-base.ts +8 -8
  58. package/src/data-structures/base/linear-base.ts +3 -3
  59. package/src/data-structures/binary-tree/avl-tree.ts +386 -51
  60. package/src/data-structures/binary-tree/binary-indexed-tree.ts +596 -247
  61. package/src/data-structures/binary-tree/binary-tree.ts +956 -81
  62. package/src/data-structures/binary-tree/bst.ts +840 -35
  63. package/src/data-structures/binary-tree/red-black-tree.ts +689 -97
  64. package/src/data-structures/binary-tree/segment-tree.ts +498 -249
  65. package/src/data-structures/binary-tree/tree-map.ts +3784 -7
  66. package/src/data-structures/binary-tree/tree-multi-map.ts +3614 -211
  67. package/src/data-structures/binary-tree/tree-multi-set.ts +2874 -65
  68. package/src/data-structures/binary-tree/tree-set.ts +3531 -10
  69. package/src/data-structures/graph/abstract-graph.ts +4 -4
  70. package/src/data-structures/graph/directed-graph.ts +429 -47
  71. package/src/data-structures/graph/map-graph.ts +59 -1
  72. package/src/data-structures/graph/undirected-graph.ts +393 -59
  73. package/src/data-structures/hash/hash-map.ts +476 -92
  74. package/src/data-structures/heap/heap.ts +581 -99
  75. package/src/data-structures/heap/max-heap.ts +46 -0
  76. package/src/data-structures/heap/min-heap.ts +59 -0
  77. package/src/data-structures/linked-list/doubly-linked-list.ts +646 -47
  78. package/src/data-structures/linked-list/singly-linked-list.ts +596 -68
  79. package/src/data-structures/linked-list/skip-linked-list.ts +1067 -90
  80. package/src/data-structures/matrix/matrix.ts +584 -12
  81. package/src/data-structures/priority-queue/max-priority-queue.ts +57 -0
  82. package/src/data-structures/priority-queue/min-priority-queue.ts +60 -0
  83. package/src/data-structures/priority-queue/priority-queue.ts +60 -0
  84. package/src/data-structures/queue/deque.ts +592 -70
  85. package/src/data-structures/queue/queue.ts +463 -42
  86. package/src/data-structures/stack/stack.ts +384 -32
  87. package/src/data-structures/trie/trie.ts +470 -48
  88. package/src/interfaces/graph.ts +1 -1
  89. package/src/types/common.ts +2 -2
  90. package/src/types/data-structures/binary-tree/segment-tree.ts +1 -1
  91. package/src/types/data-structures/heap/heap.ts +1 -0
  92. package/src/types/data-structures/linked-list/skip-linked-list.ts +2 -1
  93. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
  94. package/src/types/utils/validate-type.ts +4 -4
@@ -23,48 +23,6 @@ import { LinearBase } from '../base/linear-base';
23
23
  * 6. Breadth-First Search (BFS): In traversal algorithms for graphs and trees, queues store elements that are to be visited.
24
24
  * 7. Real-time Queuing: Like queuing systems in banks or supermarkets.
25
25
  * @example
26
- * // basic Queue creation and push operation
27
- * // Create a simple Queue with initial values
28
- * const queue = new Queue([1, 2, 3, 4, 5]);
29
- *
30
- * // Verify the queue maintains insertion order
31
- * console.log([...queue]); // [1, 2, 3, 4, 5];
32
- *
33
- * // Check length
34
- * console.log(queue.length); // 5;
35
- * @example
36
- * // Queue shift and peek operations
37
- * const queue = new Queue<number>([10, 20, 30, 40]);
38
- *
39
- * // Peek at the front element without removing it
40
- * console.log(queue.first); // 10;
41
- *
42
- * // Remove and get the first element (FIFO)
43
- * const first = queue.shift();
44
- * console.log(first); // 10;
45
- *
46
- * // Verify remaining elements and length decreased
47
- * console.log([...queue]); // [20, 30, 40];
48
- * console.log(queue.length); // 3;
49
- * @example
50
- * // Queue for...of iteration and isEmpty check
51
- * const queue = new Queue<string>(['A', 'B', 'C', 'D']);
52
- *
53
- * const elements: string[] = [];
54
- * for (const item of queue) {
55
- * elements.push(item);
56
- * }
57
- *
58
- * // Verify all elements are iterated in order
59
- * console.log(elements); // ['A', 'B', 'C', 'D'];
60
- *
61
- * // Process all elements
62
- * while (queue.length > 0) {
63
- * queue.shift();
64
- * }
65
- *
66
- * console.log(queue.length); // 0;
67
- * @example
68
26
  * // Queue as message broker for event processing
69
27
  * interface Message {
70
28
  * id: string;
@@ -125,6 +83,10 @@ import { LinearBase } from '../base/linear-base';
125
83
  *
126
84
  * // Queue should be empty after processing all messages
127
85
  * console.log(messageQueue.length); // 0;
86
+ * @example
87
+ * // Convert queue to array
88
+ * const q = new Queue<number>([10, 20, 30]);
89
+ * console.log(q.toArray()); // [10, 20, 30];
128
90
  */
129
91
  export class Queue<E = any, R = any> extends LinearBase<E, R> {
130
92
  /**
@@ -195,6 +157,45 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
195
157
  * Get the number of elements currently in the queue.
196
158
  * @remarks Time O(1), Space O(1)
197
159
  * @returns Current length.
160
+
161
+
162
+
163
+
164
+
165
+
166
+
167
+
168
+
169
+
170
+
171
+
172
+
173
+
174
+
175
+
176
+
177
+
178
+
179
+
180
+
181
+
182
+
183
+
184
+
185
+
186
+
187
+
188
+
189
+
190
+
191
+
192
+ * @example
193
+ * // Track queue length
194
+ * const q = new Queue<number>();
195
+ * console.log(q.length); // 0;
196
+ * q.push(1);
197
+ * q.push(2);
198
+ * console.log(q.length); // 2;
198
199
  */
199
200
 
200
201
  get length(): number {
@@ -205,6 +206,43 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
205
206
  * Get the first element (front) without removing it.
206
207
  * @remarks Time O(1), Space O(1)
207
208
  * @returns Front element or undefined.
209
+
210
+
211
+
212
+
213
+
214
+
215
+
216
+
217
+
218
+
219
+
220
+
221
+
222
+
223
+
224
+
225
+
226
+
227
+
228
+
229
+
230
+
231
+
232
+
233
+
234
+
235
+
236
+
237
+
238
+
239
+
240
+
241
+ * @example
242
+ * // View the front element
243
+ * const q = new Queue<string>(['first', 'second', 'third']);
244
+ * console.log(q.first); // 'first';
245
+ * console.log(q.length); // 3;
208
246
  */
209
247
 
210
248
  get first(): E | undefined {
@@ -237,6 +275,56 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
237
275
  * Check whether the queue is empty.
238
276
  * @remarks Time O(1), Space O(1)
239
277
  * @returns True if length is 0.
278
+
279
+
280
+
281
+
282
+
283
+
284
+
285
+
286
+
287
+
288
+
289
+
290
+
291
+
292
+
293
+
294
+
295
+
296
+
297
+
298
+
299
+
300
+
301
+
302
+
303
+
304
+
305
+
306
+
307
+
308
+
309
+
310
+ * @example
311
+ * // Queue for...of iteration and isEmpty check
312
+ * const queue = new Queue<string>(['A', 'B', 'C', 'D']);
313
+ *
314
+ * const elements: string[] = [];
315
+ * for (const item of queue) {
316
+ * elements.push(item);
317
+ * }
318
+ *
319
+ * // Verify all elements are iterated in order
320
+ * console.log(elements); // ['A', 'B', 'C', 'D'];
321
+ *
322
+ * // Process all elements
323
+ * while (queue.length > 0) {
324
+ * queue.shift();
325
+ * }
326
+ *
327
+ * console.log(queue.length); // 0;
240
328
  */
241
329
 
242
330
  isEmpty(): boolean {
@@ -248,6 +336,48 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
248
336
  * @remarks Time O(1), Space O(1)
249
337
  * @param element - Element to enqueue.
250
338
  * @returns True on success.
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
+ * @example
372
+ * // basic Queue creation and push operation
373
+ * // Create a simple Queue with initial values
374
+ * const queue = new Queue([1, 2, 3, 4, 5]);
375
+ *
376
+ * // Verify the queue maintains insertion order
377
+ * console.log([...queue]); // [1, 2, 3, 4, 5];
378
+ *
379
+ * // Check length
380
+ * console.log(queue.length); // 5;
251
381
  */
252
382
 
253
383
  push(element: E): boolean {
@@ -276,6 +406,52 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
276
406
  * Dequeue one element from the front (amortized via offset).
277
407
  * @remarks Time O(1) amortized, Space O(1)
278
408
  * @returns Removed element or undefined.
409
+
410
+
411
+
412
+
413
+
414
+
415
+
416
+
417
+
418
+
419
+
420
+
421
+
422
+
423
+
424
+
425
+
426
+
427
+
428
+
429
+
430
+
431
+
432
+
433
+
434
+
435
+
436
+
437
+
438
+
439
+
440
+
441
+ * @example
442
+ * // Queue shift and peek operations
443
+ * const queue = new Queue<number>([10, 20, 30, 40]);
444
+ *
445
+ * // Peek at the front element without removing it
446
+ * console.log(queue.first); // 10;
447
+ *
448
+ * // Remove and get the first element (FIFO)
449
+ * const first = queue.shift();
450
+ * console.log(first); // 10;
451
+ *
452
+ * // Verify remaining elements and length decreased
453
+ * console.log([...queue]); // [20, 30, 40];
454
+ * console.log(queue.length); // 3;
279
455
  */
280
456
 
281
457
  shift(): E | undefined {
@@ -291,6 +467,40 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
291
467
  * @remarks Time O(N), Space O(1)
292
468
  * @param element - Element to remove (strict equality via Object.is).
293
469
  * @returns True if an element was removed.
470
+
471
+
472
+
473
+
474
+
475
+
476
+
477
+
478
+
479
+
480
+
481
+
482
+
483
+
484
+
485
+
486
+
487
+
488
+
489
+
490
+
491
+
492
+
493
+
494
+
495
+
496
+
497
+
498
+
499
+ * @example
500
+ * // Remove specific element
501
+ * const q = new Queue<number>([1, 2, 3, 2]);
502
+ * q.delete(2);
503
+ * console.log(q.length); // 3;
294
504
  */
295
505
 
296
506
  delete(element: E): boolean {
@@ -308,6 +518,40 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
308
518
  * @remarks Time O(1), Space O(1)
309
519
  * @param index - Zero-based index from the front.
310
520
  * @returns Element or undefined.
521
+
522
+
523
+
524
+
525
+
526
+
527
+
528
+
529
+
530
+
531
+
532
+
533
+
534
+
535
+
536
+
537
+
538
+
539
+
540
+
541
+
542
+
543
+
544
+
545
+
546
+
547
+
548
+
549
+
550
+ * @example
551
+ * // Access element by index
552
+ * const q = new Queue<string>(['a', 'b', 'c']);
553
+ * console.log(q.at(0)); // 'a';
554
+ * console.log(q.at(2)); // 'c';
311
555
  */
312
556
 
313
557
  at(index: number): E | undefined {
@@ -373,6 +617,41 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
373
617
  * Remove all elements and reset offset.
374
618
  * @remarks Time O(1), Space O(1)
375
619
  * @returns void
620
+
621
+
622
+
623
+
624
+
625
+
626
+
627
+
628
+
629
+
630
+
631
+
632
+
633
+
634
+
635
+
636
+
637
+
638
+
639
+
640
+
641
+
642
+
643
+
644
+
645
+
646
+
647
+
648
+
649
+
650
+ * @example
651
+ * // Remove all elements
652
+ * const q = new Queue<number>([1, 2, 3]);
653
+ * q.clear();
654
+ * console.log(q.length); // 0;
376
655
  */
377
656
 
378
657
  clear(): void {
@@ -384,6 +663,42 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
384
663
  * Compact storage by discarding consumed head elements.
385
664
  * @remarks Time O(N), Space O(N)
386
665
  * @returns True when compaction performed.
666
+
667
+
668
+
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
+ * @example
696
+ * // Reclaim unused memory
697
+ * const q = new Queue<number>([1, 2, 3, 4, 5]);
698
+ * q.shift();
699
+ * q.shift();
700
+ * q.compact();
701
+ * console.log(q.length); // 3;
387
702
  */
388
703
 
389
704
  compact(): boolean {
@@ -421,6 +736,43 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
421
736
  * Deep clone this queue and its parameters.
422
737
  * @remarks Time O(N), Space O(N)
423
738
  * @returns A new queue with the same content and options.
739
+
740
+
741
+
742
+
743
+
744
+
745
+
746
+
747
+
748
+
749
+
750
+
751
+
752
+
753
+
754
+
755
+
756
+
757
+
758
+
759
+
760
+
761
+
762
+
763
+
764
+
765
+
766
+
767
+
768
+
769
+ * @example
770
+ * // Create independent copy
771
+ * const q = new Queue<number>([1, 2, 3]);
772
+ * const copy = q.clone();
773
+ * copy.shift();
774
+ * console.log(q.length); // 3;
775
+ * console.log(copy.length); // 2;
424
776
  */
425
777
 
426
778
  clone(): this {
@@ -436,6 +788,41 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
436
788
  * @param predicate - Predicate (element, index, queue) → boolean to keep element.
437
789
  * @param [thisArg] - Value for `this` inside the predicate.
438
790
  * @returns A new queue with kept elements.
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
+
821
+ * @example
822
+ * // Filter elements
823
+ * const q = new Queue<number>([1, 2, 3, 4, 5]);
824
+ * const evens = q.filter(x => x % 2 === 0);
825
+ * console.log(evens.length); // 2;
439
826
  */
440
827
 
441
828
  filter(predicate: ElementCallback<E, R, boolean>, thisArg?: unknown): this {
@@ -458,6 +845,40 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
458
845
  * @param [options] - Options for the output queue (e.g., toElementFn, maxLen, autoCompactRatio).
459
846
  * @param [thisArg] - Value for `this` inside the callback.
460
847
  * @returns A new Queue with mapped elements.
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
+
875
+
876
+
877
+ * @example
878
+ * // Transform elements
879
+ * const q = new Queue<number>([1, 2, 3]);
880
+ * const doubled = q.map(x => x * 2);
881
+ * console.log(doubled.toArray()); // [2, 4, 6];
461
882
  */
462
883
 
463
884
  map<EM, RM>(callback: ElementCallback<E, R, EM>, options?: QueueOptions<EM, RM>, thisArg?: unknown): Queue<EM, RM> {