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/esm/stack.mjs
CHANGED
|
@@ -264,7 +264,6 @@ var Stack = class extends IterableElementBase {
|
|
|
264
264
|
static {
|
|
265
265
|
__name(this, "Stack");
|
|
266
266
|
}
|
|
267
|
-
_equals = /* @__PURE__ */ __name((a, b) => Object.is(a, b), "_equals");
|
|
268
267
|
/**
|
|
269
268
|
* Create a Stack and optionally bulk-push elements.
|
|
270
269
|
* @remarks Time O(N), Space O(N)
|
|
@@ -286,54 +285,14 @@ var Stack = class extends IterableElementBase {
|
|
|
286
285
|
return this._elements;
|
|
287
286
|
}
|
|
288
287
|
/**
|
|
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
|
-
|
|
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
|
-
*/
|
|
288
|
+
* Get the number of stored elements.
|
|
289
|
+
* @remarks Time O(1), Space O(1)
|
|
290
|
+
* @returns Current size.
|
|
291
|
+
* @example
|
|
292
|
+
* // Get number of elements
|
|
293
|
+
* const stack = new Stack<number>([1, 2, 3]);
|
|
294
|
+
* console.log(stack.size); // 3;
|
|
295
|
+
*/
|
|
337
296
|
get size() {
|
|
338
297
|
return this.elements.length;
|
|
339
298
|
}
|
|
@@ -351,247 +310,79 @@ var Stack = class extends IterableElementBase {
|
|
|
351
310
|
return new this(elements, options);
|
|
352
311
|
}
|
|
353
312
|
/**
|
|
354
|
-
|
|
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
|
-
|
|
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
|
-
*/
|
|
313
|
+
* Check whether the stack is empty.
|
|
314
|
+
* @remarks Time O(1), Space O(1)
|
|
315
|
+
* @returns True if size is 0.
|
|
316
|
+
* @example
|
|
317
|
+
* // Check if stack has elements
|
|
318
|
+
* const stack = new Stack<number>();
|
|
319
|
+
* console.log(stack.isEmpty()); // true;
|
|
320
|
+
* stack.push(1);
|
|
321
|
+
* console.log(stack.isEmpty()); // false;
|
|
322
|
+
*/
|
|
406
323
|
isEmpty() {
|
|
407
324
|
return this.elements.length === 0;
|
|
408
325
|
}
|
|
409
326
|
/**
|
|
410
|
-
|
|
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
|
-
|
|
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
|
-
*/
|
|
327
|
+
* Get the top element without removing it.
|
|
328
|
+
* @remarks Time O(1), Space O(1)
|
|
329
|
+
* @returns Top element or undefined.
|
|
330
|
+
* @example
|
|
331
|
+
* // View the top element without removing it
|
|
332
|
+
* const stack = new Stack<string>(['a', 'b', 'c']);
|
|
333
|
+
* console.log(stack.peek()); // 'c';
|
|
334
|
+
* console.log(stack.size); // 3;
|
|
335
|
+
*/
|
|
461
336
|
peek() {
|
|
462
337
|
return this.isEmpty() ? void 0 : this.elements[this.elements.length - 1];
|
|
463
338
|
}
|
|
464
339
|
/**
|
|
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
|
-
|
|
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
|
-
*/
|
|
340
|
+
* Push one element onto the top.
|
|
341
|
+
* @remarks Time O(1), Space O(1)
|
|
342
|
+
* @param element - Element to push.
|
|
343
|
+
* @returns True when pushed.
|
|
344
|
+
* @example
|
|
345
|
+
* // basic Stack creation and push operation
|
|
346
|
+
* // Create a simple Stack with initial values
|
|
347
|
+
* const stack = new Stack([1, 2, 3, 4, 5]);
|
|
348
|
+
*
|
|
349
|
+
* // Verify the stack maintains insertion order (LIFO will be shown in pop)
|
|
350
|
+
* console.log([...stack]); // [1, 2, 3, 4, 5];
|
|
351
|
+
*
|
|
352
|
+
* // Check length
|
|
353
|
+
* console.log(stack.size); // 5;
|
|
354
|
+
*
|
|
355
|
+
* // Push a new element to the top
|
|
356
|
+
* stack.push(6);
|
|
357
|
+
* console.log(stack.size); // 6;
|
|
358
|
+
*/
|
|
526
359
|
push(element) {
|
|
527
360
|
this.elements.push(element);
|
|
528
361
|
return true;
|
|
529
362
|
}
|
|
530
363
|
/**
|
|
531
|
-
|
|
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
|
-
|
|
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
|
-
*/
|
|
364
|
+
* Pop and return the top element.
|
|
365
|
+
* @remarks Time O(1), Space O(1)
|
|
366
|
+
* @returns Removed element or undefined.
|
|
367
|
+
* @example
|
|
368
|
+
* // Stack pop operation (LIFO - Last In First Out)
|
|
369
|
+
* const stack = new Stack<number>([10, 20, 30, 40, 50]);
|
|
370
|
+
*
|
|
371
|
+
* // Peek at the top element without removing
|
|
372
|
+
* const top = stack.peek();
|
|
373
|
+
* console.log(top); // 50;
|
|
374
|
+
*
|
|
375
|
+
* // Pop removes from the top (LIFO order)
|
|
376
|
+
* const popped = stack.pop();
|
|
377
|
+
* console.log(popped); // 50;
|
|
378
|
+
*
|
|
379
|
+
* // Next pop gets the previous element
|
|
380
|
+
* const next = stack.pop();
|
|
381
|
+
* console.log(next); // 40;
|
|
382
|
+
*
|
|
383
|
+
* // Verify length decreased
|
|
384
|
+
* console.log(stack.size); // 3;
|
|
385
|
+
*/
|
|
595
386
|
pop() {
|
|
596
387
|
return this.isEmpty() ? void 0 : this.elements.pop();
|
|
597
388
|
}
|
|
@@ -610,55 +401,16 @@ var Stack = class extends IterableElementBase {
|
|
|
610
401
|
return ans;
|
|
611
402
|
}
|
|
612
403
|
/**
|
|
613
|
-
|
|
614
|
-
|
|
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
|
-
* @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
|
-
*/
|
|
404
|
+
* Delete the first occurrence of a specific element.
|
|
405
|
+
* @remarks Time O(N), Space O(1)
|
|
406
|
+
* @param element - Element to remove (using the configured equality).
|
|
407
|
+
* @returns True if an element was removed.
|
|
408
|
+
* @example
|
|
409
|
+
* // Remove element
|
|
410
|
+
* const stack = new Stack<number>([1, 2, 3]);
|
|
411
|
+
* stack.delete(2);
|
|
412
|
+
* console.log(stack.toArray()); // [1, 3];
|
|
413
|
+
*/
|
|
662
414
|
delete(element) {
|
|
663
415
|
const idx = this._indexOfByEquals(element);
|
|
664
416
|
return this.deleteAt(idx) !== void 0;
|
|
@@ -690,167 +442,47 @@ var Stack = class extends IterableElementBase {
|
|
|
690
442
|
return false;
|
|
691
443
|
}
|
|
692
444
|
/**
|
|
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
|
-
|
|
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
|
-
*/
|
|
445
|
+
* Remove all elements and reset storage.
|
|
446
|
+
* @remarks Time O(1), Space O(1)
|
|
447
|
+
* @returns void
|
|
448
|
+
* @example
|
|
449
|
+
* // Remove all elements
|
|
450
|
+
* const stack = new Stack<number>([1, 2, 3]);
|
|
451
|
+
* stack.clear();
|
|
452
|
+
* console.log(stack.isEmpty()); // true;
|
|
453
|
+
*/
|
|
742
454
|
clear() {
|
|
743
455
|
this._elements = [];
|
|
744
456
|
}
|
|
745
457
|
/**
|
|
746
|
-
|
|
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
|
-
|
|
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
|
-
*/
|
|
458
|
+
* Deep clone this stack.
|
|
459
|
+
* @remarks Time O(N), Space O(N)
|
|
460
|
+
* @returns A new stack with the same content.
|
|
461
|
+
* @example
|
|
462
|
+
* // Create independent copy
|
|
463
|
+
* const stack = new Stack<number>([1, 2, 3]);
|
|
464
|
+
* const copy = stack.clone();
|
|
465
|
+
* copy.pop();
|
|
466
|
+
* console.log(stack.size); // 3;
|
|
467
|
+
* console.log(copy.size); // 2;
|
|
468
|
+
*/
|
|
797
469
|
clone() {
|
|
798
470
|
const out = this._createInstance({ toElementFn: this.toElementFn });
|
|
799
471
|
for (const v of this) out.push(v);
|
|
800
472
|
return out;
|
|
801
473
|
}
|
|
802
474
|
/**
|
|
803
|
-
|
|
804
|
-
|
|
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
|
-
* @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
|
-
*/
|
|
475
|
+
* Filter elements into a new stack of the same class.
|
|
476
|
+
* @remarks Time O(N), Space O(N)
|
|
477
|
+
* @param predicate - Predicate (value, index, stack) → boolean to keep value.
|
|
478
|
+
* @param [thisArg] - Value for `this` inside the predicate.
|
|
479
|
+
* @returns A new stack with kept values.
|
|
480
|
+
* @example
|
|
481
|
+
* // Filter elements
|
|
482
|
+
* const stack = new Stack<number>([1, 2, 3, 4, 5]);
|
|
483
|
+
* const evens = stack.filter(x => x % 2 === 0);
|
|
484
|
+
* console.log(evens.toArray()); // [2, 4];
|
|
485
|
+
*/
|
|
854
486
|
filter(predicate, thisArg) {
|
|
855
487
|
const out = this._createInstance({ toElementFn: this.toElementFn });
|
|
856
488
|
let index = 0;
|
|
@@ -877,59 +509,20 @@ var Stack = class extends IterableElementBase {
|
|
|
877
509
|
return out;
|
|
878
510
|
}
|
|
879
511
|
/**
|
|
880
|
-
|
|
881
|
-
|
|
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
|
-
* @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
|
-
*/
|
|
512
|
+
* Map values into a new stack (possibly different element type).
|
|
513
|
+
* @remarks Time O(N), Space O(N)
|
|
514
|
+
* @template EM
|
|
515
|
+
* @template RM
|
|
516
|
+
* @param callback - Mapping function (value, index, stack) → newElement.
|
|
517
|
+
* @param [options] - Options for the output stack (e.g., toElementFn).
|
|
518
|
+
* @param [thisArg] - Value for `this` inside the callback.
|
|
519
|
+
* @returns A new Stack with mapped elements.
|
|
520
|
+
* @example
|
|
521
|
+
* // Transform elements
|
|
522
|
+
* const stack = new Stack<number>([1, 2, 3]);
|
|
523
|
+
* const doubled = stack.map(x => x * 2);
|
|
524
|
+
* console.log(doubled.toArray()); // [2, 4, 6];
|
|
525
|
+
*/
|
|
933
526
|
map(callback, options, thisArg) {
|
|
934
527
|
const out = this._createLike([], { ...options ?? {} });
|
|
935
528
|
let index = 0;
|
|
@@ -949,6 +542,7 @@ var Stack = class extends IterableElementBase {
|
|
|
949
542
|
this._equals = equals;
|
|
950
543
|
return this;
|
|
951
544
|
}
|
|
545
|
+
_equals = /* @__PURE__ */ __name((a, b) => Object.is(a, b), "_equals");
|
|
952
546
|
/**
|
|
953
547
|
* (Protected) Find the index of a target element using the equality function.
|
|
954
548
|
* @remarks Time O(N), Space O(1)
|