data-structure-typed 2.6.0 → 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 (160) hide show
  1. package/.github/workflows/ci.yml +7 -2
  2. package/.github/workflows/release-package.yml +9 -2
  3. package/CHANGELOG.md +9 -1
  4. package/dist/cjs/binary-tree.cjs +2927 -23688
  5. package/dist/cjs/graph.cjs +845 -2634
  6. package/dist/cjs/hash.cjs +185 -616
  7. package/dist/cjs/heap.cjs +266 -818
  8. package/dist/cjs/index.cjs +5116 -31358
  9. package/dist/cjs/linked-list.cjs +644 -2615
  10. package/dist/cjs/matrix.cjs +220 -535
  11. package/dist/cjs/priority-queue.cjs +266 -818
  12. package/dist/cjs/queue.cjs +637 -2343
  13. package/dist/cjs/stack.cjs +124 -530
  14. package/dist/cjs/trie.cjs +145 -592
  15. package/dist/cjs-legacy/binary-tree.cjs +4352 -25113
  16. package/dist/cjs-legacy/graph.cjs +847 -2636
  17. package/dist/cjs-legacy/hash.cjs +181 -612
  18. package/dist/cjs-legacy/heap.cjs +266 -818
  19. package/dist/cjs-legacy/index.cjs +6657 -32899
  20. package/dist/cjs-legacy/linked-list.cjs +640 -2611
  21. package/dist/cjs-legacy/matrix.cjs +220 -535
  22. package/dist/cjs-legacy/priority-queue.cjs +266 -818
  23. package/dist/cjs-legacy/queue.cjs +634 -2340
  24. package/dist/cjs-legacy/stack.cjs +124 -530
  25. package/dist/cjs-legacy/trie.cjs +145 -592
  26. package/dist/esm/binary-tree.mjs +2927 -23688
  27. package/dist/esm/graph.mjs +845 -2634
  28. package/dist/esm/hash.mjs +185 -616
  29. package/dist/esm/heap.mjs +266 -818
  30. package/dist/esm/index.mjs +5116 -31358
  31. package/dist/esm/linked-list.mjs +644 -2615
  32. package/dist/esm/matrix.mjs +220 -535
  33. package/dist/esm/priority-queue.mjs +266 -818
  34. package/dist/esm/queue.mjs +637 -2343
  35. package/dist/esm/stack.mjs +124 -530
  36. package/dist/esm/trie.mjs +145 -592
  37. package/dist/esm-legacy/binary-tree.mjs +4352 -25113
  38. package/dist/esm-legacy/graph.mjs +847 -2636
  39. package/dist/esm-legacy/hash.mjs +181 -612
  40. package/dist/esm-legacy/heap.mjs +266 -818
  41. package/dist/esm-legacy/index.mjs +6657 -32899
  42. package/dist/esm-legacy/linked-list.mjs +640 -2611
  43. package/dist/esm-legacy/matrix.mjs +220 -535
  44. package/dist/esm-legacy/priority-queue.mjs +266 -818
  45. package/dist/esm-legacy/queue.mjs +634 -2340
  46. package/dist/esm-legacy/stack.mjs +124 -530
  47. package/dist/esm-legacy/trie.mjs +145 -592
  48. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +29 -500
  49. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +38 -563
  50. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +230 -1212
  51. package/dist/types/data-structures/binary-tree/bst.d.ts +124 -1063
  52. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +99 -854
  53. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +62 -314
  54. package/dist/types/data-structures/binary-tree/tree-map.d.ts +366 -5057
  55. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +277 -4885
  56. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +253 -3929
  57. package/dist/types/data-structures/binary-tree/tree-set.d.ts +261 -4782
  58. package/dist/types/data-structures/graph/abstract-graph.d.ts +44 -44
  59. package/dist/types/data-structures/graph/directed-graph.d.ts +130 -527
  60. package/dist/types/data-structures/graph/undirected-graph.d.ts +125 -482
  61. package/dist/types/data-structures/hash/hash-map.d.ts +132 -562
  62. package/dist/types/data-structures/heap/heap.d.ts +194 -746
  63. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +120 -809
  64. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +121 -733
  65. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +193 -863
  66. package/dist/types/data-structures/matrix/matrix.d.ts +159 -474
  67. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -6
  68. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +6 -11
  69. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  70. package/dist/types/data-structures/queue/deque.d.ts +196 -804
  71. package/dist/types/data-structures/queue/queue.d.ts +99 -585
  72. package/dist/types/data-structures/stack/stack.d.ts +75 -481
  73. package/dist/types/data-structures/trie/trie.d.ts +98 -584
  74. package/dist/umd/data-structure-typed.js +6580 -32822
  75. package/dist/umd/data-structure-typed.min.js +3 -3
  76. package/docs-site-docusaurus/docs/api/classes/AVLTree.md +162 -215
  77. package/docs-site-docusaurus/docs/api/classes/AVLTreeNode.md +9 -9
  78. package/docs-site-docusaurus/docs/api/classes/AbstractGraph.md +47 -47
  79. package/docs-site-docusaurus/docs/api/classes/BST.md +155 -208
  80. package/docs-site-docusaurus/docs/api/classes/BSTNode.md +7 -7
  81. package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +13 -29
  82. package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +104 -158
  83. package/docs-site-docusaurus/docs/api/classes/BinaryTreeNode.md +13 -13
  84. package/docs-site-docusaurus/docs/api/classes/Deque.md +253 -101
  85. package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +60 -80
  86. package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +244 -114
  87. package/docs-site-docusaurus/docs/api/classes/DoublyLinkedListNode.md +6 -6
  88. package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +9 -9
  89. package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +1 -1
  90. package/docs-site-docusaurus/docs/api/classes/HashMap.md +52 -48
  91. package/docs-site-docusaurus/docs/api/classes/Heap.md +119 -64
  92. package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +84 -14
  93. package/docs-site-docusaurus/docs/api/classes/LinearBase.md +138 -34
  94. package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +149 -41
  95. package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +23 -23
  96. package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +172 -92
  97. package/docs-site-docusaurus/docs/api/classes/MapGraph.md +60 -80
  98. package/docs-site-docusaurus/docs/api/classes/Matrix.md +57 -52
  99. package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +117 -62
  100. package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +120 -70
  101. package/docs-site-docusaurus/docs/api/classes/MinHeap.md +117 -62
  102. package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +125 -75
  103. package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +119 -64
  104. package/docs-site-docusaurus/docs/api/classes/Queue.md +158 -74
  105. package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +171 -225
  106. package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +10 -22
  107. package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +172 -94
  108. package/docs-site-docusaurus/docs/api/classes/SinglyLinkedListNode.md +4 -4
  109. package/docs-site-docusaurus/docs/api/classes/SkipList.md +98 -75
  110. package/docs-site-docusaurus/docs/api/classes/Stack.md +112 -50
  111. package/docs-site-docusaurus/docs/api/classes/TreeMap.md +104 -129
  112. package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +90 -121
  113. package/docs-site-docusaurus/docs/api/classes/TreeSet.md +298 -107
  114. package/docs-site-docusaurus/docs/api/classes/Trie.md +116 -58
  115. package/docs-site-docusaurus/docs/api/classes/TrieNode.md +8 -8
  116. package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +59 -77
  117. package/package.json +45 -46
  118. package/src/common/error.ts +15 -32
  119. package/src/common/index.ts +0 -3
  120. package/src/data-structures/base/iterable-element-base.ts +0 -3
  121. package/src/data-structures/base/linear-base.ts +2 -36
  122. package/src/data-structures/binary-tree/avl-tree.ts +31 -529
  123. package/src/data-structures/binary-tree/binary-indexed-tree.ts +47 -572
  124. package/src/data-structures/binary-tree/binary-tree.ts +326 -1311
  125. package/src/data-structures/binary-tree/bst.ts +158 -1082
  126. package/src/data-structures/binary-tree/red-black-tree.ts +451 -1290
  127. package/src/data-structures/binary-tree/segment-tree.ts +73 -351
  128. package/src/data-structures/binary-tree/tree-map.ts +462 -5124
  129. package/src/data-structures/binary-tree/tree-multi-map.ts +302 -4914
  130. package/src/data-structures/binary-tree/tree-multi-set.ts +299 -3983
  131. package/src/data-structures/binary-tree/tree-set.ts +338 -4836
  132. package/src/data-structures/graph/abstract-graph.ts +98 -167
  133. package/src/data-structures/graph/directed-graph.ts +137 -562
  134. package/src/data-structures/graph/map-graph.ts +0 -3
  135. package/src/data-structures/graph/undirected-graph.ts +132 -511
  136. package/src/data-structures/hash/hash-map.ts +154 -582
  137. package/src/data-structures/heap/heap.ts +200 -795
  138. package/src/data-structures/linked-list/doubly-linked-list.ts +121 -865
  139. package/src/data-structures/linked-list/singly-linked-list.ts +122 -794
  140. package/src/data-structures/linked-list/skip-linked-list.ts +211 -918
  141. package/src/data-structures/matrix/matrix.ts +179 -518
  142. package/src/data-structures/matrix/navigator.ts +0 -1
  143. package/src/data-structures/priority-queue/max-priority-queue.ts +1 -6
  144. package/src/data-structures/priority-queue/min-priority-queue.ts +6 -11
  145. package/src/data-structures/priority-queue/priority-queue.ts +1 -2
  146. package/src/data-structures/queue/deque.ts +214 -882
  147. package/src/data-structures/queue/queue.ts +102 -625
  148. package/src/data-structures/stack/stack.ts +76 -505
  149. package/src/data-structures/trie/trie.ts +98 -628
  150. package/src/types/common.ts +0 -10
  151. package/src/types/data-structures/binary-tree/bst.ts +0 -7
  152. package/src/types/data-structures/binary-tree/red-black-tree.ts +0 -1
  153. package/src/types/data-structures/graph/abstract-graph.ts +0 -2
  154. package/src/types/data-structures/hash/hash-map.ts +0 -3
  155. package/src/types/data-structures/hash/index.ts +0 -1
  156. package/src/types/data-structures/matrix/navigator.ts +0 -2
  157. package/src/types/utils/utils.ts +0 -7
  158. package/src/types/utils/validate-type.ts +0 -7
  159. package/src/utils/number.ts +0 -2
  160. package/src/utils/utils.ts +0 -5
@@ -273,8 +273,8 @@ var _Stack = class _Stack extends IterableElementBase {
273
273
  */
274
274
  constructor(elements = [], options) {
275
275
  super(options);
276
- __publicField(this, "_equals", /* @__PURE__ */ __name((a, b) => Object.is(a, b), "_equals"));
277
276
  __publicField(this, "_elements", []);
277
+ __publicField(this, "_equals", /* @__PURE__ */ __name((a, b) => Object.is(a, b), "_equals"));
278
278
  this.pushMany(elements);
279
279
  }
280
280
  /**
@@ -286,54 +286,14 @@ var _Stack = class _Stack extends IterableElementBase {
286
286
  return this._elements;
287
287
  }
288
288
  /**
289
- * Get the number of stored elements.
290
- * @remarks Time O(1), Space O(1)
291
- * @returns Current size.
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
-
322
-
323
-
324
-
325
-
326
-
327
-
328
-
329
-
330
-
331
-
332
- * @example
333
- * // Get number of elements
334
- * const stack = new Stack<number>([1, 2, 3]);
335
- * console.log(stack.size); // 3;
336
- */
289
+ * Get the number of stored elements.
290
+ * @remarks Time O(1), Space O(1)
291
+ * @returns Current size.
292
+ * @example
293
+ * // Get number of elements
294
+ * const stack = new Stack<number>([1, 2, 3]);
295
+ * console.log(stack.size); // 3;
296
+ */
337
297
  get size() {
338
298
  return this.elements.length;
339
299
  }
@@ -351,247 +311,79 @@ var _Stack = class _Stack extends IterableElementBase {
351
311
  return new this(elements, options);
352
312
  }
353
313
  /**
354
- * Check whether the stack is empty.
355
- * @remarks Time O(1), Space O(1)
356
- * @returns True if size is 0.
357
-
358
-
359
-
360
-
361
-
362
-
363
-
364
-
365
-
366
-
367
-
368
-
369
-
370
-
371
-
372
-
373
-
374
-
375
-
376
-
377
-
378
-
379
-
380
-
381
-
382
-
383
-
384
-
385
-
386
-
387
-
388
-
389
-
390
-
391
-
392
-
393
-
394
-
395
-
396
-
397
-
398
-
399
- * @example
400
- * // Check if stack has elements
401
- * const stack = new Stack<number>();
402
- * console.log(stack.isEmpty()); // true;
403
- * stack.push(1);
404
- * console.log(stack.isEmpty()); // false;
405
- */
314
+ * Check whether the stack is empty.
315
+ * @remarks Time O(1), Space O(1)
316
+ * @returns True if size is 0.
317
+ * @example
318
+ * // Check if stack has elements
319
+ * const stack = new Stack<number>();
320
+ * console.log(stack.isEmpty()); // true;
321
+ * stack.push(1);
322
+ * console.log(stack.isEmpty()); // false;
323
+ */
406
324
  isEmpty() {
407
325
  return this.elements.length === 0;
408
326
  }
409
327
  /**
410
- * Get the top element without removing it.
411
- * @remarks Time O(1), Space O(1)
412
- * @returns Top element or undefined.
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
-
442
-
443
-
444
-
445
-
446
-
447
-
448
-
449
-
450
-
451
-
452
-
453
-
454
-
455
- * @example
456
- * // View the top element without removing it
457
- * const stack = new Stack<string>(['a', 'b', 'c']);
458
- * console.log(stack.peek()); // 'c';
459
- * console.log(stack.size); // 3;
460
- */
328
+ * Get the top element without removing it.
329
+ * @remarks Time O(1), Space O(1)
330
+ * @returns Top element or undefined.
331
+ * @example
332
+ * // View the top element without removing it
333
+ * const stack = new Stack<string>(['a', 'b', 'c']);
334
+ * console.log(stack.peek()); // 'c';
335
+ * console.log(stack.size); // 3;
336
+ */
461
337
  peek() {
462
338
  return this.isEmpty() ? void 0 : this.elements[this.elements.length - 1];
463
339
  }
464
340
  /**
465
- * Push one element onto the top.
466
- * @remarks Time O(1), Space O(1)
467
- * @param element - Element to push.
468
- * @returns True when pushed.
469
-
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
-
500
-
501
-
502
-
503
-
504
-
505
-
506
-
507
-
508
-
509
-
510
-
511
- * @example
512
- * // basic Stack creation and push operation
513
- * // Create a simple Stack with initial values
514
- * const stack = new Stack([1, 2, 3, 4, 5]);
515
- *
516
- * // Verify the stack maintains insertion order (LIFO will be shown in pop)
517
- * console.log([...stack]); // [1, 2, 3, 4, 5];
518
- *
519
- * // Check length
520
- * console.log(stack.size); // 5;
521
- *
522
- * // Push a new element to the top
523
- * stack.push(6);
524
- * console.log(stack.size); // 6;
525
- */
341
+ * Push one element onto the top.
342
+ * @remarks Time O(1), Space O(1)
343
+ * @param element - Element to push.
344
+ * @returns True when pushed.
345
+ * @example
346
+ * // basic Stack creation and push operation
347
+ * // Create a simple Stack with initial values
348
+ * const stack = new Stack([1, 2, 3, 4, 5]);
349
+ *
350
+ * // Verify the stack maintains insertion order (LIFO will be shown in pop)
351
+ * console.log([...stack]); // [1, 2, 3, 4, 5];
352
+ *
353
+ * // Check length
354
+ * console.log(stack.size); // 5;
355
+ *
356
+ * // Push a new element to the top
357
+ * stack.push(6);
358
+ * console.log(stack.size); // 6;
359
+ */
526
360
  push(element) {
527
361
  this.elements.push(element);
528
362
  return true;
529
363
  }
530
364
  /**
531
- * Pop and return the top element.
532
- * @remarks Time O(1), Space O(1)
533
- * @returns Removed element or undefined.
534
-
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
-
566
-
567
-
568
-
569
-
570
-
571
-
572
-
573
-
574
-
575
-
576
- * @example
577
- * // Stack pop operation (LIFO - Last In First Out)
578
- * const stack = new Stack<number>([10, 20, 30, 40, 50]);
579
- *
580
- * // Peek at the top element without removing
581
- * const top = stack.peek();
582
- * console.log(top); // 50;
583
- *
584
- * // Pop removes from the top (LIFO order)
585
- * const popped = stack.pop();
586
- * console.log(popped); // 50;
587
- *
588
- * // Next pop gets the previous element
589
- * const next = stack.pop();
590
- * console.log(next); // 40;
591
- *
592
- * // Verify length decreased
593
- * console.log(stack.size); // 3;
594
- */
365
+ * Pop and return the top element.
366
+ * @remarks Time O(1), Space O(1)
367
+ * @returns Removed element or undefined.
368
+ * @example
369
+ * // Stack pop operation (LIFO - Last In First Out)
370
+ * const stack = new Stack<number>([10, 20, 30, 40, 50]);
371
+ *
372
+ * // Peek at the top element without removing
373
+ * const top = stack.peek();
374
+ * console.log(top); // 50;
375
+ *
376
+ * // Pop removes from the top (LIFO order)
377
+ * const popped = stack.pop();
378
+ * console.log(popped); // 50;
379
+ *
380
+ * // Next pop gets the previous element
381
+ * const next = stack.pop();
382
+ * console.log(next); // 40;
383
+ *
384
+ * // Verify length decreased
385
+ * console.log(stack.size); // 3;
386
+ */
595
387
  pop() {
596
388
  return this.isEmpty() ? void 0 : this.elements.pop();
597
389
  }
@@ -610,55 +402,16 @@ var _Stack = class _Stack extends IterableElementBase {
610
402
  return ans;
611
403
  }
612
404
  /**
613
- * Delete the first occurrence of a specific element.
614
- * @remarks Time O(N), Space O(1)
615
- * @param element - Element to remove (using the configured equality).
616
- * @returns True if an element was removed.
617
-
618
-
619
-
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
-
651
-
652
-
653
-
654
-
655
-
656
- * @example
657
- * // Remove element
658
- * const stack = new Stack<number>([1, 2, 3]);
659
- * stack.delete(2);
660
- * console.log(stack.toArray()); // [1, 3];
661
- */
405
+ * Delete the first occurrence of a specific element.
406
+ * @remarks Time O(N), Space O(1)
407
+ * @param element - Element to remove (using the configured equality).
408
+ * @returns True if an element was removed.
409
+ * @example
410
+ * // Remove element
411
+ * const stack = new Stack<number>([1, 2, 3]);
412
+ * stack.delete(2);
413
+ * console.log(stack.toArray()); // [1, 3];
414
+ */
662
415
  delete(element) {
663
416
  const idx = this._indexOfByEquals(element);
664
417
  return this.deleteAt(idx) !== void 0;
@@ -690,167 +443,47 @@ var _Stack = class _Stack extends IterableElementBase {
690
443
  return false;
691
444
  }
692
445
  /**
693
- * Remove all elements and reset storage.
694
- * @remarks Time O(1), Space O(1)
695
- * @returns void
696
-
697
-
698
-
699
-
700
-
701
-
702
-
703
-
704
-
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
-
735
-
736
- * @example
737
- * // Remove all elements
738
- * const stack = new Stack<number>([1, 2, 3]);
739
- * stack.clear();
740
- * console.log(stack.isEmpty()); // true;
741
- */
446
+ * Remove all elements and reset storage.
447
+ * @remarks Time O(1), Space O(1)
448
+ * @returns void
449
+ * @example
450
+ * // Remove all elements
451
+ * const stack = new Stack<number>([1, 2, 3]);
452
+ * stack.clear();
453
+ * console.log(stack.isEmpty()); // true;
454
+ */
742
455
  clear() {
743
456
  this._elements = [];
744
457
  }
745
458
  /**
746
- * Deep clone this stack.
747
- * @remarks Time O(N), Space O(N)
748
- * @returns A new stack with the same content.
749
-
750
-
751
-
752
-
753
-
754
-
755
-
756
-
757
-
758
-
759
-
760
-
761
-
762
-
763
-
764
-
765
-
766
-
767
-
768
-
769
-
770
-
771
-
772
-
773
-
774
-
775
-
776
-
777
-
778
-
779
-
780
-
781
-
782
-
783
-
784
-
785
-
786
-
787
-
788
-
789
- * @example
790
- * // Create independent copy
791
- * const stack = new Stack<number>([1, 2, 3]);
792
- * const copy = stack.clone();
793
- * copy.pop();
794
- * console.log(stack.size); // 3;
795
- * console.log(copy.size); // 2;
796
- */
459
+ * Deep clone this stack.
460
+ * @remarks Time O(N), Space O(N)
461
+ * @returns A new stack with the same content.
462
+ * @example
463
+ * // Create independent copy
464
+ * const stack = new Stack<number>([1, 2, 3]);
465
+ * const copy = stack.clone();
466
+ * copy.pop();
467
+ * console.log(stack.size); // 3;
468
+ * console.log(copy.size); // 2;
469
+ */
797
470
  clone() {
798
471
  const out = this._createInstance({ toElementFn: this.toElementFn });
799
472
  for (const v of this) out.push(v);
800
473
  return out;
801
474
  }
802
475
  /**
803
- * Filter elements into a new stack of the same class.
804
- * @remarks Time O(N), Space O(N)
805
- * @param predicate - Predicate (value, index, stack) → boolean to keep value.
806
- * @param [thisArg] - Value for `this` inside the predicate.
807
- * @returns A new stack with kept values.
808
-
809
-
810
-
811
-
812
-
813
-
814
-
815
-
816
-
817
-
818
-
819
-
820
-
821
-
822
-
823
-
824
-
825
-
826
-
827
-
828
-
829
-
830
-
831
-
832
-
833
-
834
-
835
-
836
-
837
-
838
-
839
-
840
-
841
-
842
-
843
-
844
-
845
-
846
-
847
-
848
- * @example
849
- * // Filter elements
850
- * const stack = new Stack<number>([1, 2, 3, 4, 5]);
851
- * const evens = stack.filter(x => x % 2 === 0);
852
- * console.log(evens.toArray()); // [2, 4];
853
- */
476
+ * Filter elements into a new stack of the same class.
477
+ * @remarks Time O(N), Space O(N)
478
+ * @param predicate - Predicate (value, index, stack) → boolean to keep value.
479
+ * @param [thisArg] - Value for `this` inside the predicate.
480
+ * @returns A new stack with kept values.
481
+ * @example
482
+ * // Filter elements
483
+ * const stack = new Stack<number>([1, 2, 3, 4, 5]);
484
+ * const evens = stack.filter(x => x % 2 === 0);
485
+ * console.log(evens.toArray()); // [2, 4];
486
+ */
854
487
  filter(predicate, thisArg) {
855
488
  const out = this._createInstance({ toElementFn: this.toElementFn });
856
489
  let index = 0;
@@ -877,59 +510,20 @@ var _Stack = class _Stack extends IterableElementBase {
877
510
  return out;
878
511
  }
879
512
  /**
880
- * Map values into a new stack (possibly different element type).
881
- * @remarks Time O(N), Space O(N)
882
- * @template EM
883
- * @template RM
884
- * @param callback - Mapping function (value, index, stack) → newElement.
885
- * @param [options] - Options for the output stack (e.g., toElementFn).
886
- * @param [thisArg] - Value for `this` inside the callback.
887
- * @returns A new Stack with mapped elements.
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
-
922
-
923
-
924
-
925
-
926
-
927
- * @example
928
- * // Transform elements
929
- * const stack = new Stack<number>([1, 2, 3]);
930
- * const doubled = stack.map(x => x * 2);
931
- * console.log(doubled.toArray()); // [2, 4, 6];
932
- */
513
+ * Map values into a new stack (possibly different element type).
514
+ * @remarks Time O(N), Space O(N)
515
+ * @template EM
516
+ * @template RM
517
+ * @param callback - Mapping function (value, index, stack) → newElement.
518
+ * @param [options] - Options for the output stack (e.g., toElementFn).
519
+ * @param [thisArg] - Value for `this` inside the callback.
520
+ * @returns A new Stack with mapped elements.
521
+ * @example
522
+ * // Transform elements
523
+ * const stack = new Stack<number>([1, 2, 3]);
524
+ * const doubled = stack.map(x => x * 2);
525
+ * console.log(doubled.toArray()); // [2, 4, 6];
526
+ */
933
527
  map(callback, options, thisArg) {
934
528
  const out = this._createLike([], { ...options != null ? options : {} });
935
529
  let index = 0;