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
|
@@ -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
|
-
|
|
288
|
-
|
|
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
|
-
* @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
|
-
|
|
353
|
-
|
|
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
|
-
* @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
|
-
|
|
409
|
-
|
|
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
|
-
* @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
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
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
|
-
|
|
530
|
-
|
|
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
|
-
* @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
|
-
|
|
612
|
-
|
|
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
|
-
* @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
|
-
|
|
692
|
-
|
|
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
|
-
* @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
|
-
|
|
745
|
-
|
|
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
|
-
* @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
|
-
|
|
802
|
-
|
|
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
|
-
* @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
|
-
|
|
879
|
-
|
|
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
|
-
* @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;
|