binary-tree-typed 2.4.5 → 2.5.0
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/README.md +0 -84
- package/dist/cjs/index.cjs +867 -404
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +864 -401
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +867 -404
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +864 -401
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/data-structures/base/iterable-element-base.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +128 -51
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +210 -164
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +429 -78
- package/dist/types/data-structures/binary-tree/bst.d.ts +311 -28
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +212 -32
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +218 -152
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +1281 -5
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1087 -201
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +858 -65
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +1133 -5
- package/dist/types/data-structures/graph/directed-graph.d.ts +219 -47
- package/dist/types/data-structures/graph/map-graph.d.ts +59 -1
- package/dist/types/data-structures/graph/undirected-graph.d.ts +204 -59
- package/dist/types/data-structures/hash/hash-map.d.ts +230 -77
- package/dist/types/data-structures/heap/heap.d.ts +287 -99
- package/dist/types/data-structures/heap/max-heap.d.ts +46 -0
- package/dist/types/data-structures/heap/min-heap.d.ts +59 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +286 -44
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +278 -65
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +415 -12
- package/dist/types/data-structures/matrix/matrix.d.ts +331 -0
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +57 -0
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +60 -0
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +60 -0
- package/dist/types/data-structures/queue/deque.d.ts +272 -65
- package/dist/types/data-structures/queue/queue.d.ts +211 -42
- package/dist/types/data-structures/stack/stack.d.ts +174 -32
- package/dist/types/data-structures/trie/trie.d.ts +213 -43
- package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -1
- package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +1 -4
- package/dist/umd/binary-tree-typed.js +860 -397
- package/dist/umd/binary-tree-typed.js.map +1 -1
- package/dist/umd/binary-tree-typed.min.js +2 -2
- package/dist/umd/binary-tree-typed.min.js.map +1 -1
- package/package.json +2 -2
- package/src/data-structures/base/iterable-element-base.ts +4 -5
- package/src/data-structures/binary-tree/avl-tree.ts +134 -51
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +302 -247
- package/src/data-structures/binary-tree/binary-tree.ts +429 -79
- package/src/data-structures/binary-tree/bst.ts +335 -34
- package/src/data-structures/binary-tree/red-black-tree.ts +290 -97
- package/src/data-structures/binary-tree/segment-tree.ts +372 -248
- package/src/data-structures/binary-tree/tree-map.ts +1284 -6
- package/src/data-structures/binary-tree/tree-multi-map.ts +1094 -211
- package/src/data-structures/binary-tree/tree-multi-set.ts +858 -65
- package/src/data-structures/binary-tree/tree-set.ts +1136 -9
- package/src/data-structures/graph/directed-graph.ts +219 -47
- package/src/data-structures/graph/map-graph.ts +59 -1
- package/src/data-structures/graph/undirected-graph.ts +204 -59
- package/src/data-structures/hash/hash-map.ts +230 -77
- package/src/data-structures/heap/heap.ts +287 -99
- package/src/data-structures/heap/max-heap.ts +46 -0
- package/src/data-structures/heap/min-heap.ts +59 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +286 -44
- package/src/data-structures/linked-list/singly-linked-list.ts +278 -65
- package/src/data-structures/linked-list/skip-linked-list.ts +689 -90
- package/src/data-structures/matrix/matrix.ts +416 -12
- package/src/data-structures/priority-queue/max-priority-queue.ts +57 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +60 -0
- package/src/data-structures/priority-queue/priority-queue.ts +60 -0
- package/src/data-structures/queue/deque.ts +272 -65
- package/src/data-structures/queue/queue.ts +211 -42
- package/src/data-structures/stack/stack.ts +174 -32
- package/src/data-structures/trie/trie.ts +213 -43
- package/src/types/data-structures/binary-tree/segment-tree.ts +1 -1
- package/src/types/data-structures/linked-list/skip-linked-list.ts +2 -1
|
@@ -27,71 +27,6 @@ import { LinearBase } from '../base/linear-base';
|
|
|
27
27
|
* 4. Efficiency: Adding and removing elements at both ends of a deque is usually very fast. However, when the dynamic array needs to expand, it may involve copying the entire array to a larger one, and this operation has a time complexity of O(n).
|
|
28
28
|
* 5. Performance jitter: Deque may experience performance jitter, but DoublyLinkedList will not
|
|
29
29
|
* @example
|
|
30
|
-
* // basic Deque creation and push/pop operations
|
|
31
|
-
* // Create a simple Deque with initial values
|
|
32
|
-
* const deque = new Deque([1, 2, 3, 4, 5]);
|
|
33
|
-
*
|
|
34
|
-
* // Verify the deque maintains insertion order
|
|
35
|
-
* console.log([...deque]); // [1, 2, 3, 4, 5];
|
|
36
|
-
*
|
|
37
|
-
* // Check length
|
|
38
|
-
* console.log(deque.length); // 5;
|
|
39
|
-
*
|
|
40
|
-
* // Push to the end
|
|
41
|
-
* deque.push(6);
|
|
42
|
-
* console.log(deque.length); // 6;
|
|
43
|
-
*
|
|
44
|
-
* // Pop from the end
|
|
45
|
-
* const last = deque.pop();
|
|
46
|
-
* console.log(last); // 6;
|
|
47
|
-
* @example
|
|
48
|
-
* // Deque shift and unshift operations
|
|
49
|
-
* const deque = new Deque<number>([20, 30, 40]);
|
|
50
|
-
*
|
|
51
|
-
* // Unshift adds to the front
|
|
52
|
-
* deque.unshift(10);
|
|
53
|
-
* console.log([...deque]); // [10, 20, 30, 40];
|
|
54
|
-
*
|
|
55
|
-
* // Shift removes from the front (O(1) complexity!)
|
|
56
|
-
* const first = deque.shift();
|
|
57
|
-
* console.log(first); // 10;
|
|
58
|
-
*
|
|
59
|
-
* // Verify remaining elements
|
|
60
|
-
* console.log([...deque]); // [20, 30, 40];
|
|
61
|
-
* console.log(deque.length); // 3;
|
|
62
|
-
* @example
|
|
63
|
-
* // Deque peek at both ends
|
|
64
|
-
* const deque = new Deque<number>([10, 20, 30, 40, 50]);
|
|
65
|
-
*
|
|
66
|
-
* // Get first element without removing
|
|
67
|
-
* const first = deque.at(0);
|
|
68
|
-
* console.log(first); // 10;
|
|
69
|
-
*
|
|
70
|
-
* // Get last element without removing
|
|
71
|
-
* const last = deque.at(deque.length - 1);
|
|
72
|
-
* console.log(last); // 50;
|
|
73
|
-
*
|
|
74
|
-
* // Length unchanged
|
|
75
|
-
* console.log(deque.length); // 5;
|
|
76
|
-
* @example
|
|
77
|
-
* // Deque for...of iteration and reverse
|
|
78
|
-
* const deque = new Deque<string>(['A', 'B', 'C', 'D']);
|
|
79
|
-
*
|
|
80
|
-
* // Iterate forward
|
|
81
|
-
* const forward: string[] = [];
|
|
82
|
-
* for (const item of deque) {
|
|
83
|
-
* forward.push(item);
|
|
84
|
-
* }
|
|
85
|
-
* console.log(forward); // ['A', 'B', 'C', 'D'];
|
|
86
|
-
*
|
|
87
|
-
* // Reverse the deque
|
|
88
|
-
* deque.reverse();
|
|
89
|
-
* const backward: string[] = [];
|
|
90
|
-
* for (const item of deque) {
|
|
91
|
-
* backward.push(item);
|
|
92
|
-
* }
|
|
93
|
-
* console.log(backward); // ['D', 'C', 'B', 'A'];
|
|
94
|
-
* @example
|
|
95
30
|
* // Deque as sliding window for stream processing
|
|
96
31
|
* interface DataPoint {
|
|
97
32
|
* timestamp: number;
|
|
@@ -142,6 +77,10 @@ import { LinearBase } from '../base/linear-base';
|
|
|
142
77
|
* console.log(windowResults[2].windowSize); // 3; // Windows are at max size from 3rd onwards
|
|
143
78
|
* console.log(windowResults[4].windowSize); // 3; // Last window still has 3 elements
|
|
144
79
|
* console.log(dataWindow.length); // 3;
|
|
80
|
+
* @example
|
|
81
|
+
* // Convert deque to array
|
|
82
|
+
* const dq = new Deque<number>([10, 20, 30]);
|
|
83
|
+
* console.log(dq.toArray()); // [10, 20, 30];
|
|
145
84
|
*/
|
|
146
85
|
export class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
147
86
|
protected _equals: (a: E, b: E) => boolean = (a, b) => Object.is(a, b);
|
|
@@ -310,6 +249,31 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
310
249
|
* Get the first element without removing it.
|
|
311
250
|
* @remarks Time O(1), Space O(1)
|
|
312
251
|
* @returns First element or undefined.
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
* @example
|
|
264
|
+
* // Deque peek at both ends
|
|
265
|
+
* const deque = new Deque<number>([10, 20, 30, 40, 50]);
|
|
266
|
+
*
|
|
267
|
+
* // Get first element without removing
|
|
268
|
+
* const first = deque.at(0);
|
|
269
|
+
* console.log(first); // 10;
|
|
270
|
+
*
|
|
271
|
+
* // Get last element without removing
|
|
272
|
+
* const last = deque.at(deque.length - 1);
|
|
273
|
+
* console.log(last); // 50;
|
|
274
|
+
*
|
|
275
|
+
* // Length unchanged
|
|
276
|
+
* console.log(deque.length); // 5;
|
|
313
277
|
*/
|
|
314
278
|
|
|
315
279
|
get first(): E | undefined {
|
|
@@ -321,6 +285,22 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
321
285
|
* Get the last element without removing it.
|
|
322
286
|
* @remarks Time O(1), Space O(1)
|
|
323
287
|
* @returns Last element or undefined.
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
* @example
|
|
300
|
+
* // Peek at the back element
|
|
301
|
+
* const dq = new Deque<string>(['a', 'b', 'c']);
|
|
302
|
+
* console.log(dq.last); // 'c';
|
|
303
|
+
* console.log(dq.first); // 'a';
|
|
324
304
|
*/
|
|
325
305
|
|
|
326
306
|
get last(): E | undefined {
|
|
@@ -355,6 +335,35 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
355
335
|
* @remarks Time O(1) amortized, Space O(1)
|
|
356
336
|
* @param element - Element to append.
|
|
357
337
|
* @returns True when appended.
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
* @example
|
|
350
|
+
* // basic Deque creation and push/pop operations
|
|
351
|
+
* // Create a simple Deque with initial values
|
|
352
|
+
* const deque = new Deque([1, 2, 3, 4, 5]);
|
|
353
|
+
*
|
|
354
|
+
* // Verify the deque maintains insertion order
|
|
355
|
+
* console.log([...deque]); // [1, 2, 3, 4, 5];
|
|
356
|
+
*
|
|
357
|
+
* // Check length
|
|
358
|
+
* console.log(deque.length); // 5;
|
|
359
|
+
*
|
|
360
|
+
* // Push to the end
|
|
361
|
+
* deque.push(6);
|
|
362
|
+
* console.log(deque.length); // 6;
|
|
363
|
+
*
|
|
364
|
+
* // Pop from the end
|
|
365
|
+
* const last = deque.pop();
|
|
366
|
+
* console.log(last); // 6;
|
|
358
367
|
*/
|
|
359
368
|
|
|
360
369
|
push(element: E): boolean {
|
|
@@ -380,6 +389,22 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
380
389
|
* Remove and return the last element.
|
|
381
390
|
* @remarks Time O(1), Space O(1)
|
|
382
391
|
* @returns Removed element or undefined.
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
* @example
|
|
404
|
+
* // Remove from the back
|
|
405
|
+
* const dq = new Deque<number>([1, 2, 3]);
|
|
406
|
+
* console.log(dq.pop()); // 3;
|
|
407
|
+
* console.log(dq.length); // 2;
|
|
383
408
|
*/
|
|
384
409
|
|
|
385
410
|
pop(): E | undefined {
|
|
@@ -405,6 +430,22 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
405
430
|
* Remove and return the first element.
|
|
406
431
|
* @remarks Time O(1) amortized, Space O(1)
|
|
407
432
|
* @returns Removed element or undefined.
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
* @example
|
|
445
|
+
* // Remove from the front
|
|
446
|
+
* const dq = new Deque<number>([1, 2, 3]);
|
|
447
|
+
* console.log(dq.shift()); // 1;
|
|
448
|
+
* console.log(dq.length); // 2;
|
|
408
449
|
*/
|
|
409
450
|
|
|
410
451
|
shift(): E | undefined {
|
|
@@ -431,6 +472,32 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
431
472
|
* @remarks Time O(1) amortized, Space O(1)
|
|
432
473
|
* @param element - Element to prepend.
|
|
433
474
|
* @returns True when prepended.
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
* @example
|
|
487
|
+
* // Deque shift and unshift operations
|
|
488
|
+
* const deque = new Deque<number>([20, 30, 40]);
|
|
489
|
+
*
|
|
490
|
+
* // Unshift adds to the front
|
|
491
|
+
* deque.unshift(10);
|
|
492
|
+
* console.log([...deque]); // [10, 20, 30, 40];
|
|
493
|
+
*
|
|
494
|
+
* // Shift removes from the front (O(1) complexity!)
|
|
495
|
+
* const first = deque.shift();
|
|
496
|
+
* console.log(first); // 10;
|
|
497
|
+
*
|
|
498
|
+
* // Verify remaining elements
|
|
499
|
+
* console.log([...deque]); // [20, 30, 40];
|
|
500
|
+
* console.log(deque.length); // 3;
|
|
434
501
|
*/
|
|
435
502
|
|
|
436
503
|
unshift(element: E): boolean {
|
|
@@ -494,6 +561,19 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
494
561
|
* Check whether the deque is empty.
|
|
495
562
|
* @remarks Time O(1), Space O(1)
|
|
496
563
|
* @returns True if length is 0.
|
|
564
|
+
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
* @example
|
|
574
|
+
* // Check if empty
|
|
575
|
+
* const dq = new Deque();
|
|
576
|
+
* console.log(dq.isEmpty()); // true;
|
|
497
577
|
*/
|
|
498
578
|
|
|
499
579
|
isEmpty(): boolean {
|
|
@@ -504,6 +584,20 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
504
584
|
* Remove all elements and reset structure.
|
|
505
585
|
* @remarks Time O(1), Space O(1)
|
|
506
586
|
* @returns void
|
|
587
|
+
|
|
588
|
+
|
|
589
|
+
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
|
|
593
|
+
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
* @example
|
|
597
|
+
* // Remove all elements
|
|
598
|
+
* const dq = new Deque<number>([1, 2, 3]);
|
|
599
|
+
* dq.clear();
|
|
600
|
+
* console.log(dq.length); // 0;
|
|
507
601
|
*/
|
|
508
602
|
|
|
509
603
|
clear(): void {
|
|
@@ -518,6 +612,19 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
518
612
|
* @remarks Time O(1), Space O(1)
|
|
519
613
|
* @param pos - Zero-based position from the front.
|
|
520
614
|
* @returns Element or undefined.
|
|
615
|
+
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
|
|
622
|
+
|
|
623
|
+
* @example
|
|
624
|
+
* // Access by index
|
|
625
|
+
* const dq = new Deque<string>(['a', 'b', 'c']);
|
|
626
|
+
* console.log(dq.at(0)); // 'a';
|
|
627
|
+
* console.log(dq.at(2)); // 'c';
|
|
521
628
|
*/
|
|
522
629
|
|
|
523
630
|
at(pos: number): E | undefined {
|
|
@@ -705,6 +812,19 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
705
812
|
* @remarks Time O(N), Space O(1)
|
|
706
813
|
* @param element - Element to remove (using the configured equality).
|
|
707
814
|
* @returns True if an element was removed.
|
|
815
|
+
|
|
816
|
+
|
|
817
|
+
|
|
818
|
+
|
|
819
|
+
|
|
820
|
+
|
|
821
|
+
|
|
822
|
+
|
|
823
|
+
* @example
|
|
824
|
+
* // Remove element
|
|
825
|
+
* const dq = new Deque<number>([1, 2, 3]);
|
|
826
|
+
* dq.delete(2);
|
|
827
|
+
* console.log(dq.length); // 2;
|
|
708
828
|
*/
|
|
709
829
|
|
|
710
830
|
delete(element: E): boolean {
|
|
@@ -758,6 +878,35 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
758
878
|
* Reverse the deque by reversing buckets and pointers.
|
|
759
879
|
* @remarks Time O(N), Space O(N)
|
|
760
880
|
* @returns This deque.
|
|
881
|
+
|
|
882
|
+
|
|
883
|
+
|
|
884
|
+
|
|
885
|
+
|
|
886
|
+
|
|
887
|
+
|
|
888
|
+
|
|
889
|
+
|
|
890
|
+
|
|
891
|
+
|
|
892
|
+
* @example
|
|
893
|
+
* // Deque for...of iteration and reverse
|
|
894
|
+
* const deque = new Deque<string>(['A', 'B', 'C', 'D']);
|
|
895
|
+
*
|
|
896
|
+
* // Iterate forward
|
|
897
|
+
* const forward: string[] = [];
|
|
898
|
+
* for (const item of deque) {
|
|
899
|
+
* forward.push(item);
|
|
900
|
+
* }
|
|
901
|
+
* console.log(forward); // ['A', 'B', 'C', 'D'];
|
|
902
|
+
*
|
|
903
|
+
* // Reverse the deque
|
|
904
|
+
* deque.reverse();
|
|
905
|
+
* const backward: string[] = [];
|
|
906
|
+
* for (const item of deque) {
|
|
907
|
+
* backward.push(item);
|
|
908
|
+
* }
|
|
909
|
+
* console.log(backward); // ['D', 'C', 'B', 'A'];
|
|
761
910
|
*/
|
|
762
911
|
|
|
763
912
|
reverse(): this {
|
|
@@ -828,6 +977,21 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
828
977
|
* Compact the deque by removing unused buckets.
|
|
829
978
|
* @remarks Time O(N), Space O(1)
|
|
830
979
|
* @returns True if compaction was performed (bucket count reduced).
|
|
980
|
+
|
|
981
|
+
|
|
982
|
+
|
|
983
|
+
|
|
984
|
+
|
|
985
|
+
|
|
986
|
+
|
|
987
|
+
|
|
988
|
+
* @example
|
|
989
|
+
* // Reclaim memory
|
|
990
|
+
* const dq = new Deque<number>([1, 2, 3, 4, 5]);
|
|
991
|
+
* dq.shift();
|
|
992
|
+
* dq.shift();
|
|
993
|
+
* dq.compact();
|
|
994
|
+
* console.log(dq.length); // 3;
|
|
831
995
|
*/
|
|
832
996
|
compact(): boolean {
|
|
833
997
|
const before = this._bucketCount;
|
|
@@ -861,6 +1025,22 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
861
1025
|
* Deep clone this deque, preserving options.
|
|
862
1026
|
* @remarks Time O(N), Space O(N)
|
|
863
1027
|
* @returns A new deque with the same content and options.
|
|
1028
|
+
|
|
1029
|
+
|
|
1030
|
+
|
|
1031
|
+
|
|
1032
|
+
|
|
1033
|
+
|
|
1034
|
+
|
|
1035
|
+
|
|
1036
|
+
|
|
1037
|
+
* @example
|
|
1038
|
+
* // Create independent copy
|
|
1039
|
+
* const dq = new Deque<number>([1, 2, 3]);
|
|
1040
|
+
* const copy = dq.clone();
|
|
1041
|
+
* copy.pop();
|
|
1042
|
+
* console.log(dq.length); // 3;
|
|
1043
|
+
* console.log(copy.length); // 2;
|
|
864
1044
|
*/
|
|
865
1045
|
|
|
866
1046
|
clone(): this {
|
|
@@ -877,6 +1057,20 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
877
1057
|
* @param predicate - Predicate (value, index, deque) → boolean to keep element.
|
|
878
1058
|
* @param [thisArg] - Value for `this` inside the predicate.
|
|
879
1059
|
* @returns A new deque with kept elements.
|
|
1060
|
+
|
|
1061
|
+
|
|
1062
|
+
|
|
1063
|
+
|
|
1064
|
+
|
|
1065
|
+
|
|
1066
|
+
|
|
1067
|
+
|
|
1068
|
+
|
|
1069
|
+
* @example
|
|
1070
|
+
* // Filter elements
|
|
1071
|
+
* const dq = new Deque<number>([1, 2, 3, 4]);
|
|
1072
|
+
* const result = dq.filter(x => x > 2);
|
|
1073
|
+
* console.log(result.length); // 2;
|
|
880
1074
|
*/
|
|
881
1075
|
|
|
882
1076
|
filter(predicate: ElementCallback<E, R, boolean>, thisArg?: any): this {
|
|
@@ -918,6 +1112,19 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
918
1112
|
* @param [options] - Options for the output deque (e.g., bucketSize, toElementFn, maxLen).
|
|
919
1113
|
* @param [thisArg] - Value for `this` inside the callback.
|
|
920
1114
|
* @returns A new Deque with mapped elements.
|
|
1115
|
+
|
|
1116
|
+
|
|
1117
|
+
|
|
1118
|
+
|
|
1119
|
+
|
|
1120
|
+
|
|
1121
|
+
|
|
1122
|
+
|
|
1123
|
+
* @example
|
|
1124
|
+
* // Transform elements
|
|
1125
|
+
* const dq = new Deque<number>([1, 2, 3]);
|
|
1126
|
+
* const result = dq.map(x => x * 10);
|
|
1127
|
+
* console.log(result.toArray()); // [10, 20, 30];
|
|
921
1128
|
*/
|
|
922
1129
|
|
|
923
1130
|
map<EM, RM>(
|