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
@@ -271,8 +271,8 @@ var _Stack = class _Stack extends IterableElementBase {
271
271
  */
272
272
  constructor(elements = [], options) {
273
273
  super(options);
274
- __publicField(this, "_equals", /* @__PURE__ */ __name((a, b) => Object.is(a, b), "_equals"));
275
274
  __publicField(this, "_elements", []);
275
+ __publicField(this, "_equals", /* @__PURE__ */ __name((a, b) => Object.is(a, b), "_equals"));
276
276
  this.pushMany(elements);
277
277
  }
278
278
  /**
@@ -284,54 +284,14 @@ var _Stack = class _Stack extends IterableElementBase {
284
284
  return this._elements;
285
285
  }
286
286
  /**
287
- * Get the number of stored elements.
288
- * @remarks Time O(1), Space O(1)
289
- * @returns Current size.
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
-
322
-
323
-
324
-
325
-
326
-
327
-
328
-
329
-
330
- * @example
331
- * // Get number of elements
332
- * const stack = new Stack<number>([1, 2, 3]);
333
- * console.log(stack.size); // 3;
334
- */
287
+ * Get the number of stored elements.
288
+ * @remarks Time O(1), Space O(1)
289
+ * @returns Current size.
290
+ * @example
291
+ * // Get number of elements
292
+ * const stack = new Stack<number>([1, 2, 3]);
293
+ * console.log(stack.size); // 3;
294
+ */
335
295
  get size() {
336
296
  return this.elements.length;
337
297
  }
@@ -349,247 +309,79 @@ var _Stack = class _Stack extends IterableElementBase {
349
309
  return new this(elements, options);
350
310
  }
351
311
  /**
352
- * Check whether the stack is empty.
353
- * @remarks Time O(1), Space O(1)
354
- * @returns True if size is 0.
355
-
356
-
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
- * @example
398
- * // Check if stack has elements
399
- * const stack = new Stack<number>();
400
- * console.log(stack.isEmpty()); // true;
401
- * stack.push(1);
402
- * console.log(stack.isEmpty()); // false;
403
- */
312
+ * Check whether the stack is empty.
313
+ * @remarks Time O(1), Space O(1)
314
+ * @returns True if size is 0.
315
+ * @example
316
+ * // Check if stack has elements
317
+ * const stack = new Stack<number>();
318
+ * console.log(stack.isEmpty()); // true;
319
+ * stack.push(1);
320
+ * console.log(stack.isEmpty()); // false;
321
+ */
404
322
  isEmpty() {
405
323
  return this.elements.length === 0;
406
324
  }
407
325
  /**
408
- * Get the top element without removing it.
409
- * @remarks Time O(1), Space O(1)
410
- * @returns Top element or undefined.
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
-
442
-
443
-
444
-
445
-
446
-
447
-
448
-
449
-
450
-
451
-
452
-
453
- * @example
454
- * // View the top element without removing it
455
- * const stack = new Stack<string>(['a', 'b', 'c']);
456
- * console.log(stack.peek()); // 'c';
457
- * console.log(stack.size); // 3;
458
- */
326
+ * Get the top element without removing it.
327
+ * @remarks Time O(1), Space O(1)
328
+ * @returns Top element or undefined.
329
+ * @example
330
+ * // View the top element without removing it
331
+ * const stack = new Stack<string>(['a', 'b', 'c']);
332
+ * console.log(stack.peek()); // 'c';
333
+ * console.log(stack.size); // 3;
334
+ */
459
335
  peek() {
460
336
  return this.isEmpty() ? void 0 : this.elements[this.elements.length - 1];
461
337
  }
462
338
  /**
463
- * Push one element onto the top.
464
- * @remarks Time O(1), Space O(1)
465
- * @param element - Element to push.
466
- * @returns True when pushed.
467
-
468
-
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
- * @example
510
- * // basic Stack creation and push operation
511
- * // Create a simple Stack with initial values
512
- * const stack = new Stack([1, 2, 3, 4, 5]);
513
- *
514
- * // Verify the stack maintains insertion order (LIFO will be shown in pop)
515
- * console.log([...stack]); // [1, 2, 3, 4, 5];
516
- *
517
- * // Check length
518
- * console.log(stack.size); // 5;
519
- *
520
- * // Push a new element to the top
521
- * stack.push(6);
522
- * console.log(stack.size); // 6;
523
- */
339
+ * Push one element onto the top.
340
+ * @remarks Time O(1), Space O(1)
341
+ * @param element - Element to push.
342
+ * @returns True when pushed.
343
+ * @example
344
+ * // basic Stack creation and push operation
345
+ * // Create a simple Stack with initial values
346
+ * const stack = new Stack([1, 2, 3, 4, 5]);
347
+ *
348
+ * // Verify the stack maintains insertion order (LIFO will be shown in pop)
349
+ * console.log([...stack]); // [1, 2, 3, 4, 5];
350
+ *
351
+ * // Check length
352
+ * console.log(stack.size); // 5;
353
+ *
354
+ * // Push a new element to the top
355
+ * stack.push(6);
356
+ * console.log(stack.size); // 6;
357
+ */
524
358
  push(element) {
525
359
  this.elements.push(element);
526
360
  return true;
527
361
  }
528
362
  /**
529
- * Pop and return the top element.
530
- * @remarks Time O(1), Space O(1)
531
- * @returns Removed element or undefined.
532
-
533
-
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
- * @example
575
- * // Stack pop operation (LIFO - Last In First Out)
576
- * const stack = new Stack<number>([10, 20, 30, 40, 50]);
577
- *
578
- * // Peek at the top element without removing
579
- * const top = stack.peek();
580
- * console.log(top); // 50;
581
- *
582
- * // Pop removes from the top (LIFO order)
583
- * const popped = stack.pop();
584
- * console.log(popped); // 50;
585
- *
586
- * // Next pop gets the previous element
587
- * const next = stack.pop();
588
- * console.log(next); // 40;
589
- *
590
- * // Verify length decreased
591
- * console.log(stack.size); // 3;
592
- */
363
+ * Pop and return the top element.
364
+ * @remarks Time O(1), Space O(1)
365
+ * @returns Removed element or undefined.
366
+ * @example
367
+ * // Stack pop operation (LIFO - Last In First Out)
368
+ * const stack = new Stack<number>([10, 20, 30, 40, 50]);
369
+ *
370
+ * // Peek at the top element without removing
371
+ * const top = stack.peek();
372
+ * console.log(top); // 50;
373
+ *
374
+ * // Pop removes from the top (LIFO order)
375
+ * const popped = stack.pop();
376
+ * console.log(popped); // 50;
377
+ *
378
+ * // Next pop gets the previous element
379
+ * const next = stack.pop();
380
+ * console.log(next); // 40;
381
+ *
382
+ * // Verify length decreased
383
+ * console.log(stack.size); // 3;
384
+ */
593
385
  pop() {
594
386
  return this.isEmpty() ? void 0 : this.elements.pop();
595
387
  }
@@ -608,55 +400,16 @@ var _Stack = class _Stack extends IterableElementBase {
608
400
  return ans;
609
401
  }
610
402
  /**
611
- * Delete the first occurrence of a specific element.
612
- * @remarks Time O(N), Space O(1)
613
- * @param element - Element to remove (using the configured equality).
614
- * @returns True if an element was removed.
615
-
616
-
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
- * @example
655
- * // Remove element
656
- * const stack = new Stack<number>([1, 2, 3]);
657
- * stack.delete(2);
658
- * console.log(stack.toArray()); // [1, 3];
659
- */
403
+ * Delete the first occurrence of a specific element.
404
+ * @remarks Time O(N), Space O(1)
405
+ * @param element - Element to remove (using the configured equality).
406
+ * @returns True if an element was removed.
407
+ * @example
408
+ * // Remove element
409
+ * const stack = new Stack<number>([1, 2, 3]);
410
+ * stack.delete(2);
411
+ * console.log(stack.toArray()); // [1, 3];
412
+ */
660
413
  delete(element) {
661
414
  const idx = this._indexOfByEquals(element);
662
415
  return this.deleteAt(idx) !== void 0;
@@ -688,167 +441,47 @@ var _Stack = class _Stack extends IterableElementBase {
688
441
  return false;
689
442
  }
690
443
  /**
691
- * Remove all elements and reset storage.
692
- * @remarks Time O(1), Space O(1)
693
- * @returns void
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
-
720
-
721
-
722
-
723
-
724
-
725
-
726
-
727
-
728
-
729
-
730
-
731
-
732
-
733
-
734
- * @example
735
- * // Remove all elements
736
- * const stack = new Stack<number>([1, 2, 3]);
737
- * stack.clear();
738
- * console.log(stack.isEmpty()); // true;
739
- */
444
+ * Remove all elements and reset storage.
445
+ * @remarks Time O(1), Space O(1)
446
+ * @returns void
447
+ * @example
448
+ * // Remove all elements
449
+ * const stack = new Stack<number>([1, 2, 3]);
450
+ * stack.clear();
451
+ * console.log(stack.isEmpty()); // true;
452
+ */
740
453
  clear() {
741
454
  this._elements = [];
742
455
  }
743
456
  /**
744
- * Deep clone this stack.
745
- * @remarks Time O(N), Space O(N)
746
- * @returns A new stack with the same content.
747
-
748
-
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
- * @example
788
- * // Create independent copy
789
- * const stack = new Stack<number>([1, 2, 3]);
790
- * const copy = stack.clone();
791
- * copy.pop();
792
- * console.log(stack.size); // 3;
793
- * console.log(copy.size); // 2;
794
- */
457
+ * Deep clone this stack.
458
+ * @remarks Time O(N), Space O(N)
459
+ * @returns A new stack with the same content.
460
+ * @example
461
+ * // Create independent copy
462
+ * const stack = new Stack<number>([1, 2, 3]);
463
+ * const copy = stack.clone();
464
+ * copy.pop();
465
+ * console.log(stack.size); // 3;
466
+ * console.log(copy.size); // 2;
467
+ */
795
468
  clone() {
796
469
  const out = this._createInstance({ toElementFn: this.toElementFn });
797
470
  for (const v of this) out.push(v);
798
471
  return out;
799
472
  }
800
473
  /**
801
- * Filter elements into a new stack of the same class.
802
- * @remarks Time O(N), Space O(N)
803
- * @param predicate - Predicate (value, index, stack) → boolean to keep value.
804
- * @param [thisArg] - Value for `this` inside the predicate.
805
- * @returns A new stack with kept values.
806
-
807
-
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
- * @example
847
- * // Filter elements
848
- * const stack = new Stack<number>([1, 2, 3, 4, 5]);
849
- * const evens = stack.filter(x => x % 2 === 0);
850
- * console.log(evens.toArray()); // [2, 4];
851
- */
474
+ * Filter elements into a new stack of the same class.
475
+ * @remarks Time O(N), Space O(N)
476
+ * @param predicate - Predicate (value, index, stack) → boolean to keep value.
477
+ * @param [thisArg] - Value for `this` inside the predicate.
478
+ * @returns A new stack with kept values.
479
+ * @example
480
+ * // Filter elements
481
+ * const stack = new Stack<number>([1, 2, 3, 4, 5]);
482
+ * const evens = stack.filter(x => x % 2 === 0);
483
+ * console.log(evens.toArray()); // [2, 4];
484
+ */
852
485
  filter(predicate, thisArg) {
853
486
  const out = this._createInstance({ toElementFn: this.toElementFn });
854
487
  let index = 0;
@@ -875,59 +508,20 @@ var _Stack = class _Stack extends IterableElementBase {
875
508
  return out;
876
509
  }
877
510
  /**
878
- * Map values into a new stack (possibly different element type).
879
- * @remarks Time O(N), Space O(N)
880
- * @template EM
881
- * @template RM
882
- * @param callback - Mapping function (value, index, stack) → newElement.
883
- * @param [options] - Options for the output stack (e.g., toElementFn).
884
- * @param [thisArg] - Value for `this` inside the callback.
885
- * @returns A new Stack with mapped elements.
886
-
887
-
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
- * @example
926
- * // Transform elements
927
- * const stack = new Stack<number>([1, 2, 3]);
928
- * const doubled = stack.map(x => x * 2);
929
- * console.log(doubled.toArray()); // [2, 4, 6];
930
- */
511
+ * Map values into a new stack (possibly different element type).
512
+ * @remarks Time O(N), Space O(N)
513
+ * @template EM
514
+ * @template RM
515
+ * @param callback - Mapping function (value, index, stack) → newElement.
516
+ * @param [options] - Options for the output stack (e.g., toElementFn).
517
+ * @param [thisArg] - Value for `this` inside the callback.
518
+ * @returns A new Stack with mapped elements.
519
+ * @example
520
+ * // Transform elements
521
+ * const stack = new Stack<number>([1, 2, 3]);
522
+ * const doubled = stack.map(x => x * 2);
523
+ * console.log(doubled.toArray()); // [2, 4, 6];
524
+ */
931
525
  map(callback, options, thisArg) {
932
526
  const out = this._createLike([], { ...options != null ? options : {} });
933
527
  let index = 0;