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,38 +21,6 @@ import { IterableElementBase } from '../base';
21
21
  * 5. Expression Evaluation: Used for the evaluation of arithmetic or logical expressions, especially when dealing with parenthesis matching and operator precedence.
22
22
  * 6. Backtracking Algorithms: In problems where multiple branches need to be explored but only one branch can be explored at a time, stacks can be used to save the state at each branching point.
23
23
  * @example
24
- * // basic Stack creation and push operation
25
- * // Create a simple Stack with initial values
26
- * const stack = new Stack([1, 2, 3, 4, 5]);
27
- *
28
- * // Verify the stack maintains insertion order (LIFO will be shown in pop)
29
- * console.log([...stack]); // [1, 2, 3, 4, 5];
30
- *
31
- * // Check length
32
- * console.log(stack.size); // 5;
33
- *
34
- * // Push a new element to the top
35
- * stack.push(6);
36
- * console.log(stack.size); // 6;
37
- * @example
38
- * // Stack pop operation (LIFO - Last In First Out)
39
- * const stack = new Stack<number>([10, 20, 30, 40, 50]);
40
- *
41
- * // Peek at the top element without removing
42
- * const top = stack.peek();
43
- * console.log(top); // 50;
44
- *
45
- * // Pop removes from the top (LIFO order)
46
- * const popped = stack.pop();
47
- * console.log(popped); // 50;
48
- *
49
- * // Next pop gets the previous element
50
- * const next = stack.pop();
51
- * console.log(next); // 40;
52
- *
53
- * // Verify length decreased
54
- * console.log(stack.size); // 3;
55
- * @example
56
24
  * // Function Call Stack
57
25
  * const functionStack = new Stack<string>();
58
26
  * functionStack.push('main');
@@ -159,6 +127,10 @@ import { IterableElementBase } from '../base';
159
127
  * else if (segment && segment !== '.') stack.push(segment);
160
128
  * });
161
129
  * console.log(stack.elements.join('/')); // 'c';
130
+ * @example
131
+ * // Convert stack to array
132
+ * const stack = new Stack<number>([1, 2, 3]);
133
+ * console.log(stack.toArray()); // [1, 2, 3];
162
134
  */
163
135
  export class Stack<E = any, R = any> extends IterableElementBase<E, R> {
164
136
  protected _equals: (a: E, b: E) => boolean = (a, b) => Object.is(a, b);
@@ -192,6 +164,40 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R> {
192
164
  * Get the number of stored elements.
193
165
  * @remarks Time O(1), Space O(1)
194
166
  * @returns Current size.
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
+
193
+
194
+
195
+
196
+
197
+ * @example
198
+ * // Get number of elements
199
+ * const stack = new Stack<number>([1, 2, 3]);
200
+ * console.log(stack.size); // 3;
195
201
  */
196
202
 
197
203
  get size(): number {
@@ -221,6 +227,44 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R> {
221
227
  * Check whether the stack is empty.
222
228
  * @remarks Time O(1), Space O(1)
223
229
  * @returns True if size is 0.
230
+
231
+
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
+ * @example
263
+ * // Check if stack has elements
264
+ * const stack = new Stack<number>();
265
+ * console.log(stack.isEmpty()); // true;
266
+ * stack.push(1);
267
+ * console.log(stack.isEmpty()); // false;
224
268
  */
225
269
 
226
270
  isEmpty(): boolean {
@@ -231,6 +275,43 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R> {
231
275
  * Get the top element without removing it.
232
276
  * @remarks Time O(1), Space O(1)
233
277
  * @returns Top element or undefined.
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
+ * // View the top element without removing it
312
+ * const stack = new Stack<string>(['a', 'b', 'c']);
313
+ * console.log(stack.peek()); // 'c';
314
+ * console.log(stack.size); // 3;
234
315
  */
235
316
 
236
317
  peek(): E | undefined {
@@ -242,6 +323,52 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R> {
242
323
  * @remarks Time O(1), Space O(1)
243
324
  * @param element - Element to push.
244
325
  * @returns True when pushed.
326
+
327
+
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
+ * @example
359
+ * // basic Stack creation and push operation
360
+ * // Create a simple Stack with initial values
361
+ * const stack = new Stack([1, 2, 3, 4, 5]);
362
+ *
363
+ * // Verify the stack maintains insertion order (LIFO will be shown in pop)
364
+ * console.log([...stack]); // [1, 2, 3, 4, 5];
365
+ *
366
+ * // Check length
367
+ * console.log(stack.size); // 5;
368
+ *
369
+ * // Push a new element to the top
370
+ * stack.push(6);
371
+ * console.log(stack.size); // 6;
245
372
  */
246
373
 
247
374
  push(element: E): boolean {
@@ -253,6 +380,56 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R> {
253
380
  * Pop and return the top element.
254
381
  * @remarks Time O(1), Space O(1)
255
382
  * @returns Removed element or undefined.
383
+
384
+
385
+
386
+
387
+
388
+
389
+
390
+
391
+
392
+
393
+
394
+
395
+
396
+
397
+
398
+
399
+
400
+
401
+
402
+
403
+
404
+
405
+
406
+
407
+
408
+
409
+
410
+
411
+
412
+
413
+
414
+
415
+ * @example
416
+ * // Stack pop operation (LIFO - Last In First Out)
417
+ * const stack = new Stack<number>([10, 20, 30, 40, 50]);
418
+ *
419
+ * // Peek at the top element without removing
420
+ * const top = stack.peek();
421
+ * console.log(top); // 50;
422
+ *
423
+ * // Pop removes from the top (LIFO order)
424
+ * const popped = stack.pop();
425
+ * console.log(popped); // 50;
426
+ *
427
+ * // Next pop gets the previous element
428
+ * const next = stack.pop();
429
+ * console.log(next); // 40;
430
+ *
431
+ * // Verify length decreased
432
+ * console.log(stack.size); // 3;
256
433
  */
257
434
 
258
435
  pop(): E | undefined {
@@ -280,6 +457,40 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R> {
280
457
  * @remarks Time O(N), Space O(1)
281
458
  * @param element - Element to remove (using the configured equality).
282
459
  * @returns True if an element was removed.
460
+
461
+
462
+
463
+
464
+
465
+
466
+
467
+
468
+
469
+
470
+
471
+
472
+
473
+
474
+
475
+
476
+
477
+
478
+
479
+
480
+
481
+
482
+
483
+
484
+
485
+
486
+
487
+
488
+
489
+ * @example
490
+ * // Remove element
491
+ * const stack = new Stack<number>([1, 2, 3]);
492
+ * stack.delete(2);
493
+ * console.log(stack.toArray()); // [1, 3];
283
494
  */
284
495
 
285
496
  delete(element: E): boolean {
@@ -321,6 +532,41 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R> {
321
532
  * Remove all elements and reset storage.
322
533
  * @remarks Time O(1), Space O(1)
323
534
  * @returns void
535
+
536
+
537
+
538
+
539
+
540
+
541
+
542
+
543
+
544
+
545
+
546
+
547
+
548
+
549
+
550
+
551
+
552
+
553
+
554
+
555
+
556
+
557
+
558
+
559
+
560
+
561
+
562
+
563
+
564
+
565
+ * @example
566
+ * // Remove all elements
567
+ * const stack = new Stack<number>([1, 2, 3]);
568
+ * stack.clear();
569
+ * console.log(stack.isEmpty()); // true;
324
570
  */
325
571
 
326
572
  clear(): void {
@@ -331,6 +577,43 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R> {
331
577
  * Deep clone this stack.
332
578
  * @remarks Time O(N), Space O(N)
333
579
  * @returns A new stack with the same content.
580
+
581
+
582
+
583
+
584
+
585
+
586
+
587
+
588
+
589
+
590
+
591
+
592
+
593
+
594
+
595
+
596
+
597
+
598
+
599
+
600
+
601
+
602
+
603
+
604
+
605
+
606
+
607
+
608
+
609
+
610
+ * @example
611
+ * // Create independent copy
612
+ * const stack = new Stack<number>([1, 2, 3]);
613
+ * const copy = stack.clone();
614
+ * copy.pop();
615
+ * console.log(stack.size); // 3;
616
+ * console.log(copy.size); // 2;
334
617
  */
335
618
 
336
619
  clone(): this {
@@ -345,6 +628,41 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R> {
345
628
  * @param predicate - Predicate (value, index, stack) → boolean to keep value.
346
629
  * @param [thisArg] - Value for `this` inside the predicate.
347
630
  * @returns A new stack with kept values.
631
+
632
+
633
+
634
+
635
+
636
+
637
+
638
+
639
+
640
+
641
+
642
+
643
+
644
+
645
+
646
+
647
+
648
+
649
+
650
+
651
+
652
+
653
+
654
+
655
+
656
+
657
+
658
+
659
+
660
+
661
+ * @example
662
+ * // Filter elements
663
+ * const stack = new Stack<number>([1, 2, 3, 4, 5]);
664
+ * const evens = stack.filter(x => x % 2 === 0);
665
+ * console.log(evens.toArray()); // [2, 4];
348
666
  */
349
667
 
350
668
  filter(predicate: ElementCallback<E, R, boolean>, thisArg?: unknown): this {
@@ -384,6 +702,40 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R> {
384
702
  * @param [options] - Options for the output stack (e.g., toElementFn).
385
703
  * @param [thisArg] - Value for `this` inside the callback.
386
704
  * @returns A new Stack with mapped elements.
705
+
706
+
707
+
708
+
709
+
710
+
711
+
712
+
713
+
714
+
715
+
716
+
717
+
718
+
719
+
720
+
721
+
722
+
723
+
724
+
725
+
726
+
727
+
728
+
729
+
730
+
731
+
732
+
733
+
734
+ * @example
735
+ * // Transform elements
736
+ * const stack = new Stack<number>([1, 2, 3]);
737
+ * const doubled = stack.map(x => x * 2);
738
+ * console.log(doubled.toArray()); // [2, 4, 6];
387
739
  */
388
740
 
389
741
  map<EM, RM>(