data-structure-typed 2.6.1 → 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.
- package/CHANGELOG.md +9 -1
- package/dist/cjs/binary-tree.cjs +2927 -23688
- package/dist/cjs/graph.cjs +845 -2634
- package/dist/cjs/hash.cjs +185 -616
- package/dist/cjs/heap.cjs +266 -818
- package/dist/cjs/index.cjs +5116 -31358
- package/dist/cjs/linked-list.cjs +644 -2615
- package/dist/cjs/matrix.cjs +220 -535
- package/dist/cjs/priority-queue.cjs +266 -818
- package/dist/cjs/queue.cjs +637 -2343
- package/dist/cjs/stack.cjs +124 -530
- package/dist/cjs/trie.cjs +145 -592
- package/dist/cjs-legacy/binary-tree.cjs +4352 -25113
- package/dist/cjs-legacy/graph.cjs +847 -2636
- package/dist/cjs-legacy/hash.cjs +181 -612
- package/dist/cjs-legacy/heap.cjs +266 -818
- package/dist/cjs-legacy/index.cjs +6657 -32899
- package/dist/cjs-legacy/linked-list.cjs +640 -2611
- package/dist/cjs-legacy/matrix.cjs +220 -535
- package/dist/cjs-legacy/priority-queue.cjs +266 -818
- package/dist/cjs-legacy/queue.cjs +634 -2340
- package/dist/cjs-legacy/stack.cjs +124 -530
- package/dist/cjs-legacy/trie.cjs +145 -592
- package/dist/esm/binary-tree.mjs +2927 -23688
- package/dist/esm/graph.mjs +845 -2634
- package/dist/esm/hash.mjs +185 -616
- package/dist/esm/heap.mjs +266 -818
- package/dist/esm/index.mjs +5116 -31358
- package/dist/esm/linked-list.mjs +644 -2615
- package/dist/esm/matrix.mjs +220 -535
- package/dist/esm/priority-queue.mjs +266 -818
- package/dist/esm/queue.mjs +637 -2343
- package/dist/esm/stack.mjs +124 -530
- package/dist/esm/trie.mjs +145 -592
- package/dist/esm-legacy/binary-tree.mjs +4352 -25113
- package/dist/esm-legacy/graph.mjs +847 -2636
- package/dist/esm-legacy/hash.mjs +181 -612
- package/dist/esm-legacy/heap.mjs +266 -818
- package/dist/esm-legacy/index.mjs +6657 -32899
- package/dist/esm-legacy/linked-list.mjs +640 -2611
- package/dist/esm-legacy/matrix.mjs +220 -535
- package/dist/esm-legacy/priority-queue.mjs +266 -818
- package/dist/esm-legacy/queue.mjs +634 -2340
- package/dist/esm-legacy/stack.mjs +124 -530
- package/dist/esm-legacy/trie.mjs +145 -592
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +29 -500
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +38 -563
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +230 -1212
- package/dist/types/data-structures/binary-tree/bst.d.ts +124 -1063
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +99 -854
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +62 -314
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +366 -5057
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +277 -4885
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +253 -3929
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +261 -4782
- package/dist/types/data-structures/graph/abstract-graph.d.ts +44 -44
- package/dist/types/data-structures/graph/directed-graph.d.ts +130 -527
- package/dist/types/data-structures/graph/undirected-graph.d.ts +125 -482
- package/dist/types/data-structures/hash/hash-map.d.ts +132 -562
- package/dist/types/data-structures/heap/heap.d.ts +194 -746
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +120 -809
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +121 -733
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +193 -863
- package/dist/types/data-structures/matrix/matrix.d.ts +159 -474
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -6
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +6 -11
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/types/data-structures/queue/deque.d.ts +196 -804
- package/dist/types/data-structures/queue/queue.d.ts +99 -585
- package/dist/types/data-structures/stack/stack.d.ts +75 -481
- package/dist/types/data-structures/trie/trie.d.ts +98 -584
- package/dist/umd/data-structure-typed.js +6580 -32822
- package/dist/umd/data-structure-typed.min.js +3 -3
- package/docs-site-docusaurus/docs/api/classes/AVLTree.md +162 -215
- package/docs-site-docusaurus/docs/api/classes/AVLTreeNode.md +9 -9
- package/docs-site-docusaurus/docs/api/classes/AbstractGraph.md +47 -47
- package/docs-site-docusaurus/docs/api/classes/BST.md +155 -208
- package/docs-site-docusaurus/docs/api/classes/BSTNode.md +7 -7
- package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +13 -29
- package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +104 -158
- package/docs-site-docusaurus/docs/api/classes/BinaryTreeNode.md +13 -13
- package/docs-site-docusaurus/docs/api/classes/Deque.md +72 -104
- package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +60 -80
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +67 -101
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedListNode.md +6 -6
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +9 -9
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +1 -1
- package/docs-site-docusaurus/docs/api/classes/HashMap.md +52 -48
- package/docs-site-docusaurus/docs/api/classes/Heap.md +40 -68
- package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +17 -17
- package/docs-site-docusaurus/docs/api/classes/LinearBase.md +38 -38
- package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +45 -45
- package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +23 -23
- package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +68 -96
- package/docs-site-docusaurus/docs/api/classes/MapGraph.md +60 -80
- package/docs-site-docusaurus/docs/api/classes/Matrix.md +57 -52
- package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +38 -66
- package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +41 -74
- package/docs-site-docusaurus/docs/api/classes/MinHeap.md +38 -66
- package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +46 -79
- package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +40 -68
- package/docs-site-docusaurus/docs/api/classes/Queue.md +54 -78
- package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +171 -225
- package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +10 -22
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +68 -98
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedListNode.md +4 -4
- package/docs-site-docusaurus/docs/api/classes/SkipList.md +98 -75
- package/docs-site-docusaurus/docs/api/classes/Stack.md +33 -53
- package/docs-site-docusaurus/docs/api/classes/TreeMap.md +104 -129
- package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +57 -124
- package/docs-site-docusaurus/docs/api/classes/TreeSet.md +45 -116
- package/docs-site-docusaurus/docs/api/classes/Trie.md +37 -61
- package/docs-site-docusaurus/docs/api/classes/TrieNode.md +8 -8
- package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +59 -77
- package/package.json +1 -1
- package/src/data-structures/binary-tree/tree-multi-set.ts +15 -11
package/dist/cjs/stack.cjs
CHANGED
|
@@ -266,7 +266,6 @@ var Stack = class extends IterableElementBase {
|
|
|
266
266
|
static {
|
|
267
267
|
__name(this, "Stack");
|
|
268
268
|
}
|
|
269
|
-
_equals = /* @__PURE__ */ __name((a, b) => Object.is(a, b), "_equals");
|
|
270
269
|
/**
|
|
271
270
|
* Create a Stack and optionally bulk-push elements.
|
|
272
271
|
* @remarks Time O(N), Space O(N)
|
|
@@ -288,54 +287,14 @@ var Stack = class extends IterableElementBase {
|
|
|
288
287
|
return this._elements;
|
|
289
288
|
}
|
|
290
289
|
/**
|
|
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
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
* @example
|
|
335
|
-
* // Get number of elements
|
|
336
|
-
* const stack = new Stack<number>([1, 2, 3]);
|
|
337
|
-
* console.log(stack.size); // 3;
|
|
338
|
-
*/
|
|
290
|
+
* Get the number of stored elements.
|
|
291
|
+
* @remarks Time O(1), Space O(1)
|
|
292
|
+
* @returns Current size.
|
|
293
|
+
* @example
|
|
294
|
+
* // Get number of elements
|
|
295
|
+
* const stack = new Stack<number>([1, 2, 3]);
|
|
296
|
+
* console.log(stack.size); // 3;
|
|
297
|
+
*/
|
|
339
298
|
get size() {
|
|
340
299
|
return this.elements.length;
|
|
341
300
|
}
|
|
@@ -353,247 +312,79 @@ var Stack = class extends IterableElementBase {
|
|
|
353
312
|
return new this(elements, options);
|
|
354
313
|
}
|
|
355
314
|
/**
|
|
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
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
* @example
|
|
402
|
-
* // Check if stack has elements
|
|
403
|
-
* const stack = new Stack<number>();
|
|
404
|
-
* console.log(stack.isEmpty()); // true;
|
|
405
|
-
* stack.push(1);
|
|
406
|
-
* console.log(stack.isEmpty()); // false;
|
|
407
|
-
*/
|
|
315
|
+
* Check whether the stack is empty.
|
|
316
|
+
* @remarks Time O(1), Space O(1)
|
|
317
|
+
* @returns True if size is 0.
|
|
318
|
+
* @example
|
|
319
|
+
* // Check if stack has elements
|
|
320
|
+
* const stack = new Stack<number>();
|
|
321
|
+
* console.log(stack.isEmpty()); // true;
|
|
322
|
+
* stack.push(1);
|
|
323
|
+
* console.log(stack.isEmpty()); // false;
|
|
324
|
+
*/
|
|
408
325
|
isEmpty() {
|
|
409
326
|
return this.elements.length === 0;
|
|
410
327
|
}
|
|
411
328
|
/**
|
|
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
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
* @example
|
|
458
|
-
* // View the top element without removing it
|
|
459
|
-
* const stack = new Stack<string>(['a', 'b', 'c']);
|
|
460
|
-
* console.log(stack.peek()); // 'c';
|
|
461
|
-
* console.log(stack.size); // 3;
|
|
462
|
-
*/
|
|
329
|
+
* Get the top element without removing it.
|
|
330
|
+
* @remarks Time O(1), Space O(1)
|
|
331
|
+
* @returns Top element or undefined.
|
|
332
|
+
* @example
|
|
333
|
+
* // View the top element without removing it
|
|
334
|
+
* const stack = new Stack<string>(['a', 'b', 'c']);
|
|
335
|
+
* console.log(stack.peek()); // 'c';
|
|
336
|
+
* console.log(stack.size); // 3;
|
|
337
|
+
*/
|
|
463
338
|
peek() {
|
|
464
339
|
return this.isEmpty() ? void 0 : this.elements[this.elements.length - 1];
|
|
465
340
|
}
|
|
466
341
|
/**
|
|
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
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
* @example
|
|
514
|
-
* // basic Stack creation and push operation
|
|
515
|
-
* // Create a simple Stack with initial values
|
|
516
|
-
* const stack = new Stack([1, 2, 3, 4, 5]);
|
|
517
|
-
*
|
|
518
|
-
* // Verify the stack maintains insertion order (LIFO will be shown in pop)
|
|
519
|
-
* console.log([...stack]); // [1, 2, 3, 4, 5];
|
|
520
|
-
*
|
|
521
|
-
* // Check length
|
|
522
|
-
* console.log(stack.size); // 5;
|
|
523
|
-
*
|
|
524
|
-
* // Push a new element to the top
|
|
525
|
-
* stack.push(6);
|
|
526
|
-
* console.log(stack.size); // 6;
|
|
527
|
-
*/
|
|
342
|
+
* Push one element onto the top.
|
|
343
|
+
* @remarks Time O(1), Space O(1)
|
|
344
|
+
* @param element - Element to push.
|
|
345
|
+
* @returns True when pushed.
|
|
346
|
+
* @example
|
|
347
|
+
* // basic Stack creation and push operation
|
|
348
|
+
* // Create a simple Stack with initial values
|
|
349
|
+
* const stack = new Stack([1, 2, 3, 4, 5]);
|
|
350
|
+
*
|
|
351
|
+
* // Verify the stack maintains insertion order (LIFO will be shown in pop)
|
|
352
|
+
* console.log([...stack]); // [1, 2, 3, 4, 5];
|
|
353
|
+
*
|
|
354
|
+
* // Check length
|
|
355
|
+
* console.log(stack.size); // 5;
|
|
356
|
+
*
|
|
357
|
+
* // Push a new element to the top
|
|
358
|
+
* stack.push(6);
|
|
359
|
+
* console.log(stack.size); // 6;
|
|
360
|
+
*/
|
|
528
361
|
push(element) {
|
|
529
362
|
this.elements.push(element);
|
|
530
363
|
return true;
|
|
531
364
|
}
|
|
532
365
|
/**
|
|
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
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
* @example
|
|
579
|
-
* // Stack pop operation (LIFO - Last In First Out)
|
|
580
|
-
* const stack = new Stack<number>([10, 20, 30, 40, 50]);
|
|
581
|
-
*
|
|
582
|
-
* // Peek at the top element without removing
|
|
583
|
-
* const top = stack.peek();
|
|
584
|
-
* console.log(top); // 50;
|
|
585
|
-
*
|
|
586
|
-
* // Pop removes from the top (LIFO order)
|
|
587
|
-
* const popped = stack.pop();
|
|
588
|
-
* console.log(popped); // 50;
|
|
589
|
-
*
|
|
590
|
-
* // Next pop gets the previous element
|
|
591
|
-
* const next = stack.pop();
|
|
592
|
-
* console.log(next); // 40;
|
|
593
|
-
*
|
|
594
|
-
* // Verify length decreased
|
|
595
|
-
* console.log(stack.size); // 3;
|
|
596
|
-
*/
|
|
366
|
+
* Pop and return the top element.
|
|
367
|
+
* @remarks Time O(1), Space O(1)
|
|
368
|
+
* @returns Removed element or undefined.
|
|
369
|
+
* @example
|
|
370
|
+
* // Stack pop operation (LIFO - Last In First Out)
|
|
371
|
+
* const stack = new Stack<number>([10, 20, 30, 40, 50]);
|
|
372
|
+
*
|
|
373
|
+
* // Peek at the top element without removing
|
|
374
|
+
* const top = stack.peek();
|
|
375
|
+
* console.log(top); // 50;
|
|
376
|
+
*
|
|
377
|
+
* // Pop removes from the top (LIFO order)
|
|
378
|
+
* const popped = stack.pop();
|
|
379
|
+
* console.log(popped); // 50;
|
|
380
|
+
*
|
|
381
|
+
* // Next pop gets the previous element
|
|
382
|
+
* const next = stack.pop();
|
|
383
|
+
* console.log(next); // 40;
|
|
384
|
+
*
|
|
385
|
+
* // Verify length decreased
|
|
386
|
+
* console.log(stack.size); // 3;
|
|
387
|
+
*/
|
|
597
388
|
pop() {
|
|
598
389
|
return this.isEmpty() ? void 0 : this.elements.pop();
|
|
599
390
|
}
|
|
@@ -612,55 +403,16 @@ var Stack = class extends IterableElementBase {
|
|
|
612
403
|
return ans;
|
|
613
404
|
}
|
|
614
405
|
/**
|
|
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
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
* @example
|
|
659
|
-
* // Remove element
|
|
660
|
-
* const stack = new Stack<number>([1, 2, 3]);
|
|
661
|
-
* stack.delete(2);
|
|
662
|
-
* console.log(stack.toArray()); // [1, 3];
|
|
663
|
-
*/
|
|
406
|
+
* Delete the first occurrence of a specific element.
|
|
407
|
+
* @remarks Time O(N), Space O(1)
|
|
408
|
+
* @param element - Element to remove (using the configured equality).
|
|
409
|
+
* @returns True if an element was removed.
|
|
410
|
+
* @example
|
|
411
|
+
* // Remove element
|
|
412
|
+
* const stack = new Stack<number>([1, 2, 3]);
|
|
413
|
+
* stack.delete(2);
|
|
414
|
+
* console.log(stack.toArray()); // [1, 3];
|
|
415
|
+
*/
|
|
664
416
|
delete(element) {
|
|
665
417
|
const idx = this._indexOfByEquals(element);
|
|
666
418
|
return this.deleteAt(idx) !== void 0;
|
|
@@ -692,167 +444,47 @@ var Stack = class extends IterableElementBase {
|
|
|
692
444
|
return false;
|
|
693
445
|
}
|
|
694
446
|
/**
|
|
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
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
* @example
|
|
739
|
-
* // Remove all elements
|
|
740
|
-
* const stack = new Stack<number>([1, 2, 3]);
|
|
741
|
-
* stack.clear();
|
|
742
|
-
* console.log(stack.isEmpty()); // true;
|
|
743
|
-
*/
|
|
447
|
+
* Remove all elements and reset storage.
|
|
448
|
+
* @remarks Time O(1), Space O(1)
|
|
449
|
+
* @returns void
|
|
450
|
+
* @example
|
|
451
|
+
* // Remove all elements
|
|
452
|
+
* const stack = new Stack<number>([1, 2, 3]);
|
|
453
|
+
* stack.clear();
|
|
454
|
+
* console.log(stack.isEmpty()); // true;
|
|
455
|
+
*/
|
|
744
456
|
clear() {
|
|
745
457
|
this._elements = [];
|
|
746
458
|
}
|
|
747
459
|
/**
|
|
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
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
* @example
|
|
792
|
-
* // Create independent copy
|
|
793
|
-
* const stack = new Stack<number>([1, 2, 3]);
|
|
794
|
-
* const copy = stack.clone();
|
|
795
|
-
* copy.pop();
|
|
796
|
-
* console.log(stack.size); // 3;
|
|
797
|
-
* console.log(copy.size); // 2;
|
|
798
|
-
*/
|
|
460
|
+
* Deep clone this stack.
|
|
461
|
+
* @remarks Time O(N), Space O(N)
|
|
462
|
+
* @returns A new stack with the same content.
|
|
463
|
+
* @example
|
|
464
|
+
* // Create independent copy
|
|
465
|
+
* const stack = new Stack<number>([1, 2, 3]);
|
|
466
|
+
* const copy = stack.clone();
|
|
467
|
+
* copy.pop();
|
|
468
|
+
* console.log(stack.size); // 3;
|
|
469
|
+
* console.log(copy.size); // 2;
|
|
470
|
+
*/
|
|
799
471
|
clone() {
|
|
800
472
|
const out = this._createInstance({ toElementFn: this.toElementFn });
|
|
801
473
|
for (const v of this) out.push(v);
|
|
802
474
|
return out;
|
|
803
475
|
}
|
|
804
476
|
/**
|
|
805
|
-
|
|
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
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
* @example
|
|
851
|
-
* // Filter elements
|
|
852
|
-
* const stack = new Stack<number>([1, 2, 3, 4, 5]);
|
|
853
|
-
* const evens = stack.filter(x => x % 2 === 0);
|
|
854
|
-
* console.log(evens.toArray()); // [2, 4];
|
|
855
|
-
*/
|
|
477
|
+
* Filter elements into a new stack of the same class.
|
|
478
|
+
* @remarks Time O(N), Space O(N)
|
|
479
|
+
* @param predicate - Predicate (value, index, stack) → boolean to keep value.
|
|
480
|
+
* @param [thisArg] - Value for `this` inside the predicate.
|
|
481
|
+
* @returns A new stack with kept values.
|
|
482
|
+
* @example
|
|
483
|
+
* // Filter elements
|
|
484
|
+
* const stack = new Stack<number>([1, 2, 3, 4, 5]);
|
|
485
|
+
* const evens = stack.filter(x => x % 2 === 0);
|
|
486
|
+
* console.log(evens.toArray()); // [2, 4];
|
|
487
|
+
*/
|
|
856
488
|
filter(predicate, thisArg) {
|
|
857
489
|
const out = this._createInstance({ toElementFn: this.toElementFn });
|
|
858
490
|
let index = 0;
|
|
@@ -879,59 +511,20 @@ var Stack = class extends IterableElementBase {
|
|
|
879
511
|
return out;
|
|
880
512
|
}
|
|
881
513
|
/**
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
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
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
* @example
|
|
930
|
-
* // Transform elements
|
|
931
|
-
* const stack = new Stack<number>([1, 2, 3]);
|
|
932
|
-
* const doubled = stack.map(x => x * 2);
|
|
933
|
-
* console.log(doubled.toArray()); // [2, 4, 6];
|
|
934
|
-
*/
|
|
514
|
+
* Map values into a new stack (possibly different element type).
|
|
515
|
+
* @remarks Time O(N), Space O(N)
|
|
516
|
+
* @template EM
|
|
517
|
+
* @template RM
|
|
518
|
+
* @param callback - Mapping function (value, index, stack) → newElement.
|
|
519
|
+
* @param [options] - Options for the output stack (e.g., toElementFn).
|
|
520
|
+
* @param [thisArg] - Value for `this` inside the callback.
|
|
521
|
+
* @returns A new Stack with mapped elements.
|
|
522
|
+
* @example
|
|
523
|
+
* // Transform elements
|
|
524
|
+
* const stack = new Stack<number>([1, 2, 3]);
|
|
525
|
+
* const doubled = stack.map(x => x * 2);
|
|
526
|
+
* console.log(doubled.toArray()); // [2, 4, 6];
|
|
527
|
+
*/
|
|
935
528
|
map(callback, options, thisArg) {
|
|
936
529
|
const out = this._createLike([], { ...options ?? {} });
|
|
937
530
|
let index = 0;
|
|
@@ -951,6 +544,7 @@ var Stack = class extends IterableElementBase {
|
|
|
951
544
|
this._equals = equals;
|
|
952
545
|
return this;
|
|
953
546
|
}
|
|
547
|
+
_equals = /* @__PURE__ */ __name((a, b) => Object.is(a, b), "_equals");
|
|
954
548
|
/**
|
|
955
549
|
* (Protected) Find the index of a target element using the equality function.
|
|
956
550
|
* @remarks Time O(N), Space O(1)
|