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
@@ -21,48 +21,6 @@ import { LinearBase } from '../base/linear-base';
21
21
  * 6. Breadth-First Search (BFS): In traversal algorithms for graphs and trees, queues store elements that are to be visited.
22
22
  * 7. Real-time Queuing: Like queuing systems in banks or supermarkets.
23
23
  * @example
24
- * // basic Queue creation and push operation
25
- * // Create a simple Queue with initial values
26
- * const queue = new Queue([1, 2, 3, 4, 5]);
27
- *
28
- * // Verify the queue maintains insertion order
29
- * console.log([...queue]); // [1, 2, 3, 4, 5];
30
- *
31
- * // Check length
32
- * console.log(queue.length); // 5;
33
- * @example
34
- * // Queue shift and peek operations
35
- * const queue = new Queue<number>([10, 20, 30, 40]);
36
- *
37
- * // Peek at the front element without removing it
38
- * console.log(queue.first); // 10;
39
- *
40
- * // Remove and get the first element (FIFO)
41
- * const first = queue.shift();
42
- * console.log(first); // 10;
43
- *
44
- * // Verify remaining elements and length decreased
45
- * console.log([...queue]); // [20, 30, 40];
46
- * console.log(queue.length); // 3;
47
- * @example
48
- * // Queue for...of iteration and isEmpty check
49
- * const queue = new Queue<string>(['A', 'B', 'C', 'D']);
50
- *
51
- * const elements: string[] = [];
52
- * for (const item of queue) {
53
- * elements.push(item);
54
- * }
55
- *
56
- * // Verify all elements are iterated in order
57
- * console.log(elements); // ['A', 'B', 'C', 'D'];
58
- *
59
- * // Process all elements
60
- * while (queue.length > 0) {
61
- * queue.shift();
62
- * }
63
- *
64
- * console.log(queue.length); // 0;
65
- * @example
66
24
  * // Queue as message broker for event processing
67
25
  * interface Message {
68
26
  * id: string;
@@ -123,6 +81,10 @@ import { LinearBase } from '../base/linear-base';
123
81
  *
124
82
  * // Queue should be empty after processing all messages
125
83
  * console.log(messageQueue.length); // 0;
84
+ * @example
85
+ * // Convert queue to array
86
+ * const q = new Queue<number>([10, 20, 30]);
87
+ * console.log(q.toArray()); // [10, 20, 30];
126
88
  */
127
89
  export declare class Queue<E = any, R = any> extends LinearBase<E, R> {
128
90
  /**
@@ -165,12 +127,88 @@ export declare class Queue<E = any, R = any> extends LinearBase<E, R> {
165
127
  * Get the number of elements currently in the queue.
166
128
  * @remarks Time O(1), Space O(1)
167
129
  * @returns Current length.
130
+
131
+
132
+
133
+
134
+
135
+
136
+
137
+
138
+
139
+
140
+
141
+
142
+
143
+
144
+
145
+
146
+
147
+
148
+
149
+
150
+
151
+
152
+
153
+
154
+
155
+
156
+
157
+
158
+
159
+
160
+
161
+
162
+ * @example
163
+ * // Track queue length
164
+ * const q = new Queue<number>();
165
+ * console.log(q.length); // 0;
166
+ * q.push(1);
167
+ * q.push(2);
168
+ * console.log(q.length); // 2;
168
169
  */
169
170
  get length(): number;
170
171
  /**
171
172
  * Get the first element (front) without removing it.
172
173
  * @remarks Time O(1), Space O(1)
173
174
  * @returns Front element or undefined.
175
+
176
+
177
+
178
+
179
+
180
+
181
+
182
+
183
+
184
+
185
+
186
+
187
+
188
+
189
+
190
+
191
+
192
+
193
+
194
+
195
+
196
+
197
+
198
+
199
+
200
+
201
+
202
+
203
+
204
+
205
+
206
+
207
+ * @example
208
+ * // View the front element
209
+ * const q = new Queue<string>(['first', 'second', 'third']);
210
+ * console.log(q.first); // 'first';
211
+ * console.log(q.length); // 3;
174
212
  */
175
213
  get first(): E | undefined;
176
214
  /**
@@ -191,6 +229,56 @@ export declare class Queue<E = any, R = any> extends LinearBase<E, R> {
191
229
  * Check whether the queue is empty.
192
230
  * @remarks Time O(1), Space O(1)
193
231
  * @returns True if length is 0.
232
+
233
+
234
+
235
+
236
+
237
+
238
+
239
+
240
+
241
+
242
+
243
+
244
+
245
+
246
+
247
+
248
+
249
+
250
+
251
+
252
+
253
+
254
+
255
+
256
+
257
+
258
+
259
+
260
+
261
+
262
+
263
+
264
+ * @example
265
+ * // Queue for...of iteration and isEmpty check
266
+ * const queue = new Queue<string>(['A', 'B', 'C', 'D']);
267
+ *
268
+ * const elements: string[] = [];
269
+ * for (const item of queue) {
270
+ * elements.push(item);
271
+ * }
272
+ *
273
+ * // Verify all elements are iterated in order
274
+ * console.log(elements); // ['A', 'B', 'C', 'D'];
275
+ *
276
+ * // Process all elements
277
+ * while (queue.length > 0) {
278
+ * queue.shift();
279
+ * }
280
+ *
281
+ * console.log(queue.length); // 0;
194
282
  */
195
283
  isEmpty(): boolean;
196
284
  /**
@@ -198,6 +286,48 @@ export declare class Queue<E = any, R = any> extends LinearBase<E, R> {
198
286
  * @remarks Time O(1), Space O(1)
199
287
  * @param element - Element to enqueue.
200
288
  * @returns True on success.
289
+
290
+
291
+
292
+
293
+
294
+
295
+
296
+
297
+
298
+
299
+
300
+
301
+
302
+
303
+
304
+
305
+
306
+
307
+
308
+
309
+
310
+
311
+
312
+
313
+
314
+
315
+
316
+
317
+
318
+
319
+
320
+
321
+ * @example
322
+ * // basic Queue creation and push operation
323
+ * // Create a simple Queue with initial values
324
+ * const queue = new Queue([1, 2, 3, 4, 5]);
325
+ *
326
+ * // Verify the queue maintains insertion order
327
+ * console.log([...queue]); // [1, 2, 3, 4, 5];
328
+ *
329
+ * // Check length
330
+ * console.log(queue.length); // 5;
201
331
  */
202
332
  push(element: E): boolean;
203
333
  /**
@@ -211,6 +341,52 @@ export declare class Queue<E = any, R = any> extends LinearBase<E, R> {
211
341
  * Dequeue one element from the front (amortized via offset).
212
342
  * @remarks Time O(1) amortized, Space O(1)
213
343
  * @returns Removed element or undefined.
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
+
373
+
374
+
375
+
376
+ * @example
377
+ * // Queue shift and peek operations
378
+ * const queue = new Queue<number>([10, 20, 30, 40]);
379
+ *
380
+ * // Peek at the front element without removing it
381
+ * console.log(queue.first); // 10;
382
+ *
383
+ * // Remove and get the first element (FIFO)
384
+ * const first = queue.shift();
385
+ * console.log(first); // 10;
386
+ *
387
+ * // Verify remaining elements and length decreased
388
+ * console.log([...queue]); // [20, 30, 40];
389
+ * console.log(queue.length); // 3;
214
390
  */
215
391
  shift(): E | undefined;
216
392
  /**
@@ -218,6 +394,40 @@ export declare class Queue<E = any, R = any> extends LinearBase<E, R> {
218
394
  * @remarks Time O(N), Space O(1)
219
395
  * @param element - Element to remove (strict equality via Object.is).
220
396
  * @returns True if an element was removed.
397
+
398
+
399
+
400
+
401
+
402
+
403
+
404
+
405
+
406
+
407
+
408
+
409
+
410
+
411
+
412
+
413
+
414
+
415
+
416
+
417
+
418
+
419
+
420
+
421
+
422
+
423
+
424
+
425
+
426
+ * @example
427
+ * // Remove specific element
428
+ * const q = new Queue<number>([1, 2, 3, 2]);
429
+ * q.delete(2);
430
+ * console.log(q.length); // 3;
221
431
  */
222
432
  delete(element: E): boolean;
223
433
  /**
@@ -225,6 +435,40 @@ export declare class Queue<E = any, R = any> extends LinearBase<E, R> {
225
435
  * @remarks Time O(1), Space O(1)
226
436
  * @param index - Zero-based index from the front.
227
437
  * @returns Element or undefined.
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
+
467
+ * @example
468
+ * // Access element by index
469
+ * const q = new Queue<string>(['a', 'b', 'c']);
470
+ * console.log(q.at(0)); // 'a';
471
+ * console.log(q.at(2)); // 'c';
228
472
  */
229
473
  at(index: number): E | undefined;
230
474
  /**
@@ -260,12 +504,83 @@ export declare class Queue<E = any, R = any> extends LinearBase<E, R> {
260
504
  * Remove all elements and reset offset.
261
505
  * @remarks Time O(1), Space O(1)
262
506
  * @returns void
507
+
508
+
509
+
510
+
511
+
512
+
513
+
514
+
515
+
516
+
517
+
518
+
519
+
520
+
521
+
522
+
523
+
524
+
525
+
526
+
527
+
528
+
529
+
530
+
531
+
532
+
533
+
534
+
535
+
536
+
537
+ * @example
538
+ * // Remove all elements
539
+ * const q = new Queue<number>([1, 2, 3]);
540
+ * q.clear();
541
+ * console.log(q.length); // 0;
263
542
  */
264
543
  clear(): void;
265
544
  /**
266
545
  * Compact storage by discarding consumed head elements.
267
546
  * @remarks Time O(N), Space O(N)
268
547
  * @returns True when compaction performed.
548
+
549
+
550
+
551
+
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
+ * @example
578
+ * // Reclaim unused memory
579
+ * const q = new Queue<number>([1, 2, 3, 4, 5]);
580
+ * q.shift();
581
+ * q.shift();
582
+ * q.compact();
583
+ * console.log(q.length); // 3;
269
584
  */
270
585
  compact(): boolean;
271
586
  /**
@@ -281,6 +596,43 @@ export declare class Queue<E = any, R = any> extends LinearBase<E, R> {
281
596
  * Deep clone this queue and its parameters.
282
597
  * @remarks Time O(N), Space O(N)
283
598
  * @returns A new queue with the same content and options.
599
+
600
+
601
+
602
+
603
+
604
+
605
+
606
+
607
+
608
+
609
+
610
+
611
+
612
+
613
+
614
+
615
+
616
+
617
+
618
+
619
+
620
+
621
+
622
+
623
+
624
+
625
+
626
+
627
+
628
+
629
+ * @example
630
+ * // Create independent copy
631
+ * const q = new Queue<number>([1, 2, 3]);
632
+ * const copy = q.clone();
633
+ * copy.shift();
634
+ * console.log(q.length); // 3;
635
+ * console.log(copy.length); // 2;
284
636
  */
285
637
  clone(): this;
286
638
  /**
@@ -289,6 +641,41 @@ export declare class Queue<E = any, R = any> extends LinearBase<E, R> {
289
641
  * @param predicate - Predicate (element, index, queue) → boolean to keep element.
290
642
  * @param [thisArg] - Value for `this` inside the predicate.
291
643
  * @returns A new queue with kept elements.
644
+
645
+
646
+
647
+
648
+
649
+
650
+
651
+
652
+
653
+
654
+
655
+
656
+
657
+
658
+
659
+
660
+
661
+
662
+
663
+
664
+
665
+
666
+
667
+
668
+
669
+
670
+
671
+
672
+
673
+
674
+ * @example
675
+ * // Filter elements
676
+ * const q = new Queue<number>([1, 2, 3, 4, 5]);
677
+ * const evens = q.filter(x => x % 2 === 0);
678
+ * console.log(evens.length); // 2;
292
679
  */
293
680
  filter(predicate: ElementCallback<E, R, boolean>, thisArg?: unknown): this;
294
681
  /**
@@ -300,6 +687,40 @@ export declare class Queue<E = any, R = any> extends LinearBase<E, R> {
300
687
  * @param [options] - Options for the output queue (e.g., toElementFn, maxLen, autoCompactRatio).
301
688
  * @param [thisArg] - Value for `this` inside the callback.
302
689
  * @returns A new Queue with mapped elements.
690
+
691
+
692
+
693
+
694
+
695
+
696
+
697
+
698
+
699
+
700
+
701
+
702
+
703
+
704
+
705
+
706
+
707
+
708
+
709
+
710
+
711
+
712
+
713
+
714
+
715
+
716
+
717
+
718
+
719
+ * @example
720
+ * // Transform elements
721
+ * const q = new Queue<number>([1, 2, 3]);
722
+ * const doubled = q.map(x => x * 2);
723
+ * console.log(doubled.toArray()); // [2, 4, 6];
303
724
  */
304
725
  map<EM, RM>(callback: ElementCallback<E, R, EM>, options?: QueueOptions<EM, RM>, thisArg?: unknown): Queue<EM, RM>;
305
726
  /**