avl-tree-typed 1.52.4 → 1.52.6
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/dist/data-structures/base/iterable-element-base.d.ts +1 -37
- package/dist/data-structures/base/iterable-element-base.js +1 -37
- package/dist/data-structures/base/iterable-entry-base.d.ts +2 -54
- package/dist/data-structures/base/iterable-entry-base.js +1 -49
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -32
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +9 -41
- package/dist/data-structures/binary-tree/avl-tree.d.ts +0 -46
- package/dist/data-structures/binary-tree/avl-tree.js +0 -46
- package/dist/data-structures/binary-tree/binary-tree.d.ts +82 -147
- package/dist/data-structures/binary-tree/binary-tree.js +300 -332
- package/dist/data-structures/binary-tree/bst.d.ts +1 -40
- package/dist/data-structures/binary-tree/bst.js +12 -44
- package/dist/data-structures/binary-tree/rb-tree.d.ts +0 -48
- package/dist/data-structures/binary-tree/rb-tree.js +2 -50
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +0 -32
- package/dist/data-structures/binary-tree/tree-multi-map.js +9 -41
- package/dist/data-structures/graph/abstract-graph.d.ts +0 -75
- package/dist/data-structures/graph/abstract-graph.js +0 -75
- package/dist/data-structures/graph/directed-graph.d.ts +0 -98
- package/dist/data-structures/graph/directed-graph.js +0 -98
- package/dist/data-structures/graph/undirected-graph.d.ts +0 -50
- package/dist/data-structures/graph/undirected-graph.js +0 -50
- package/dist/data-structures/hash/hash-map.d.ts +5 -92
- package/dist/data-structures/hash/hash-map.js +27 -111
- package/dist/data-structures/heap/heap.d.ts +0 -32
- package/dist/data-structures/heap/heap.js +0 -32
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +5 -88
- package/dist/data-structures/linked-list/doubly-linked-list.js +5 -88
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +1 -83
- package/dist/data-structures/linked-list/singly-linked-list.js +2 -84
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +1 -35
- package/dist/data-structures/linked-list/skip-linked-list.js +1 -35
- package/dist/data-structures/queue/deque.d.ts +1 -98
- package/dist/data-structures/queue/deque.js +3 -99
- package/dist/data-structures/queue/queue.d.ts +1 -54
- package/dist/data-structures/queue/queue.js +0 -53
- package/dist/data-structures/stack/stack.d.ts +1 -34
- package/dist/data-structures/stack/stack.js +1 -34
- package/dist/data-structures/tree/tree.js +2 -1
- package/dist/data-structures/trie/trie.d.ts +0 -64
- package/dist/data-structures/trie/trie.js +0 -64
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +8 -0
- package/dist/types/data-structures/binary-tree/binary-tree.js +6 -0
- package/dist/types/utils/utils.d.ts +13 -12
- package/dist/utils/number.d.ts +13 -0
- package/dist/utils/number.js +13 -0
- package/dist/utils/utils.d.ts +125 -3
- package/dist/utils/utils.js +177 -21
- package/package.json +2 -2
- package/src/data-structures/base/iterable-element-base.ts +2 -42
- package/src/data-structures/base/iterable-entry-base.ts +3 -62
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +8 -48
- package/src/data-structures/binary-tree/avl-tree.ts +0 -57
- package/src/data-structures/binary-tree/binary-tree.ts +330 -359
- package/src/data-structures/binary-tree/bst.ts +11 -54
- package/src/data-structures/binary-tree/rb-tree.ts +2 -62
- package/src/data-structures/binary-tree/tree-multi-map.ts +8 -48
- package/src/data-structures/graph/abstract-graph.ts +0 -92
- package/src/data-structures/graph/directed-graph.ts +0 -122
- package/src/data-structures/graph/undirected-graph.ts +0 -62
- package/src/data-structures/hash/hash-map.ts +29 -133
- package/src/data-structures/heap/heap.ts +0 -40
- package/src/data-structures/linked-list/doubly-linked-list.ts +5 -112
- package/src/data-structures/linked-list/singly-linked-list.ts +2 -104
- package/src/data-structures/linked-list/skip-linked-list.ts +1 -44
- package/src/data-structures/queue/deque.ts +2 -125
- package/src/data-structures/queue/queue.ts +1 -68
- package/src/data-structures/stack/stack.ts +1 -43
- package/src/data-structures/tree/tree.ts +1 -1
- package/src/data-structures/trie/trie.ts +0 -80
- package/src/types/data-structures/binary-tree/binary-tree.ts +8 -1
- package/src/types/utils/utils.ts +17 -15
- package/src/utils/number.ts +13 -0
- package/src/utils/utils.ts +174 -18
|
@@ -176,11 +176,6 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|
|
176
176
|
return this._buckets[this._bucketLast][this._lastInBucket];
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
/**
|
|
180
|
-
* Time Complexity - Amortized O(1) (possible reallocation)
|
|
181
|
-
* Space Complexity - O(n) (due to potential resizing).
|
|
182
|
-
*/
|
|
183
|
-
|
|
184
179
|
/**
|
|
185
180
|
* Time Complexity - Amortized O(1) (possible reallocation),
|
|
186
181
|
* Space Complexity - O(n) (due to potential resizing).
|
|
@@ -209,11 +204,6 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|
|
209
204
|
return true;
|
|
210
205
|
}
|
|
211
206
|
|
|
212
|
-
/**
|
|
213
|
-
* Time Complexity: O(1)
|
|
214
|
-
* Space Complexity: O(1)
|
|
215
|
-
*/
|
|
216
|
-
|
|
217
207
|
/**
|
|
218
208
|
* Time Complexity: O(1)
|
|
219
209
|
* Space Complexity: O(1)
|
|
@@ -240,11 +230,6 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|
|
240
230
|
return element;
|
|
241
231
|
}
|
|
242
232
|
|
|
243
|
-
/**
|
|
244
|
-
* Time Complexity: Amortized O(1)
|
|
245
|
-
* Space Complexity: O(n)
|
|
246
|
-
*/
|
|
247
|
-
|
|
248
233
|
/**
|
|
249
234
|
* Time Complexity: Amortized O(1)
|
|
250
235
|
* Space Complexity: O(n)
|
|
@@ -274,11 +259,6 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|
|
274
259
|
return true;
|
|
275
260
|
}
|
|
276
261
|
|
|
277
|
-
/**
|
|
278
|
-
* Time Complexity: O(1)
|
|
279
|
-
* Space Complexity: O(1)
|
|
280
|
-
*/
|
|
281
|
-
|
|
282
262
|
/**
|
|
283
263
|
* Time Complexity: O(1)
|
|
284
264
|
* Space Complexity: O(1)
|
|
@@ -306,11 +286,6 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|
|
306
286
|
return element;
|
|
307
287
|
}
|
|
308
288
|
|
|
309
|
-
/**
|
|
310
|
-
* Time Complexity: O(1)
|
|
311
|
-
* Space Complexity: O(1)
|
|
312
|
-
*/
|
|
313
|
-
|
|
314
289
|
/**
|
|
315
290
|
* Time Complexity: O(1)
|
|
316
291
|
* Space Complexity: O(1)
|
|
@@ -322,11 +297,6 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|
|
322
297
|
return this.size === 0;
|
|
323
298
|
}
|
|
324
299
|
|
|
325
|
-
/**
|
|
326
|
-
* Time Complexity: O(1)
|
|
327
|
-
* Space Complexity: O(1)
|
|
328
|
-
*/
|
|
329
|
-
|
|
330
300
|
/**
|
|
331
301
|
* Time Complexity: O(1)
|
|
332
302
|
* Space Complexity: O(1)
|
|
@@ -364,11 +334,6 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|
|
364
334
|
}
|
|
365
335
|
}
|
|
366
336
|
|
|
367
|
-
/**
|
|
368
|
-
* Time Complexity: O(1)
|
|
369
|
-
* Space Complexity: O(1)
|
|
370
|
-
*/
|
|
371
|
-
|
|
372
337
|
/**
|
|
373
338
|
* Time Complexity: O(1)
|
|
374
339
|
* Space Complexity: O(1)
|
|
@@ -385,11 +350,6 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|
|
385
350
|
return this._buckets[bucketIndex][indexInBucket]!;
|
|
386
351
|
}
|
|
387
352
|
|
|
388
|
-
/**
|
|
389
|
-
* Time Complexity: O(1)
|
|
390
|
-
* Space Complexity: O(1)
|
|
391
|
-
*/
|
|
392
|
-
|
|
393
353
|
/**
|
|
394
354
|
* Time Complexity: O(1)
|
|
395
355
|
* Space Complexity: O(1)
|
|
@@ -407,11 +367,6 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|
|
407
367
|
return true;
|
|
408
368
|
}
|
|
409
369
|
|
|
410
|
-
/**
|
|
411
|
-
* Time Complexity: O(n)
|
|
412
|
-
* Space Complexity: O(n)
|
|
413
|
-
*/
|
|
414
|
-
|
|
415
370
|
/**
|
|
416
371
|
* Time Complexity: O(n)
|
|
417
372
|
* Space Complexity: O(n)
|
|
@@ -446,11 +401,6 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|
|
446
401
|
return true;
|
|
447
402
|
}
|
|
448
403
|
|
|
449
|
-
/**
|
|
450
|
-
* Time Complexity: O(1)
|
|
451
|
-
* Space Complexity: O(1)
|
|
452
|
-
*/
|
|
453
|
-
|
|
454
404
|
/**
|
|
455
405
|
* Time Complexity: O(1)
|
|
456
406
|
* Space Complexity: O(1)
|
|
@@ -484,11 +434,6 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|
|
484
434
|
}
|
|
485
435
|
}
|
|
486
436
|
|
|
487
|
-
/**
|
|
488
|
-
* Time Complexity: O(1)
|
|
489
|
-
* Space Complexity: O(1) or O(n)
|
|
490
|
-
*/
|
|
491
|
-
|
|
492
437
|
/**
|
|
493
438
|
* Time Complexity: O(1)
|
|
494
439
|
* Space Complexity: O(1) or O(n)
|
|
@@ -507,7 +452,6 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|
|
507
452
|
cutRest(pos: number, isCutSelf = false): Deque<E> {
|
|
508
453
|
if (isCutSelf) {
|
|
509
454
|
if (pos < 0) {
|
|
510
|
-
this.clear();
|
|
511
455
|
return this;
|
|
512
456
|
}
|
|
513
457
|
const { bucketIndex, indexInBucket } = this._getBucketAndPosition(pos);
|
|
@@ -517,7 +461,7 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|
|
517
461
|
return this;
|
|
518
462
|
} else {
|
|
519
463
|
const newDeque = new Deque<E>([], { bucketSize: this._bucketSize });
|
|
520
|
-
|
|
464
|
+
if (pos < 0) pos = 0;
|
|
521
465
|
for (let i = pos; i < this.size; i++) {
|
|
522
466
|
newDeque.push(this.at(i));
|
|
523
467
|
}
|
|
@@ -526,11 +470,6 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|
|
526
470
|
}
|
|
527
471
|
}
|
|
528
472
|
|
|
529
|
-
/**
|
|
530
|
-
* Time Complexity: O(n)
|
|
531
|
-
* Space Complexity: O(1) or O(n)
|
|
532
|
-
*/
|
|
533
|
-
|
|
534
473
|
/**
|
|
535
474
|
* Time Complexity: O(n)
|
|
536
475
|
* Space Complexity: O(1) or O(n)
|
|
@@ -560,11 +499,6 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|
|
560
499
|
return true;
|
|
561
500
|
}
|
|
562
501
|
|
|
563
|
-
/**
|
|
564
|
-
* Time Complexity: O(n)
|
|
565
|
-
* Space Complexity: O(1)
|
|
566
|
-
*/
|
|
567
|
-
|
|
568
502
|
/**
|
|
569
503
|
* Time Complexity: O(n)
|
|
570
504
|
* Space Complexity: O(1)
|
|
@@ -592,11 +526,6 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|
|
592
526
|
return true;
|
|
593
527
|
}
|
|
594
528
|
|
|
595
|
-
/**
|
|
596
|
-
* Time Complexity: O(n)
|
|
597
|
-
* Space Complexity: O(1)
|
|
598
|
-
*/
|
|
599
|
-
|
|
600
529
|
/**
|
|
601
530
|
* Time Complexity: O(n)
|
|
602
531
|
* Space Complexity: O(1)
|
|
@@ -618,11 +547,6 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|
|
618
547
|
return this;
|
|
619
548
|
}
|
|
620
549
|
|
|
621
|
-
/**
|
|
622
|
-
* Time Complexity: O(n)
|
|
623
|
-
* Space Complexity: O(1)
|
|
624
|
-
*/
|
|
625
|
-
|
|
626
550
|
/**
|
|
627
551
|
* Time Complexity: O(n)
|
|
628
552
|
* Space Complexity: O(1)
|
|
@@ -648,11 +572,6 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|
|
648
572
|
return this;
|
|
649
573
|
}
|
|
650
574
|
|
|
651
|
-
/**
|
|
652
|
-
* Time Complexity: O(n log n)
|
|
653
|
-
* Space Complexity: O(n)
|
|
654
|
-
*/
|
|
655
|
-
|
|
656
575
|
/**
|
|
657
576
|
* Time Complexity: O(n log n)
|
|
658
577
|
* Space Complexity: O(n)
|
|
@@ -675,11 +594,6 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|
|
675
594
|
return this;
|
|
676
595
|
}
|
|
677
596
|
|
|
678
|
-
/**
|
|
679
|
-
* Time Complexity: O(n)
|
|
680
|
-
* Space Complexity: O(n)
|
|
681
|
-
*/
|
|
682
|
-
|
|
683
597
|
/**
|
|
684
598
|
* Time Complexity: O(n)
|
|
685
599
|
* Space Complexity: O(n)
|
|
@@ -710,11 +624,6 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|
|
710
624
|
this._buckets = newBuckets;
|
|
711
625
|
}
|
|
712
626
|
|
|
713
|
-
/**
|
|
714
|
-
* Time Complexity: O(n)
|
|
715
|
-
* Space Complexity: O(1)
|
|
716
|
-
*/
|
|
717
|
-
|
|
718
627
|
/**
|
|
719
628
|
* Time Complexity: O(n)
|
|
720
629
|
* Space Complexity: O(1)
|
|
@@ -735,11 +644,6 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|
|
735
644
|
return -1;
|
|
736
645
|
}
|
|
737
646
|
|
|
738
|
-
/**
|
|
739
|
-
* Time Complexity: O(n)
|
|
740
|
-
* Space Complexity: O(n)
|
|
741
|
-
*/
|
|
742
|
-
|
|
743
647
|
/**
|
|
744
648
|
* Time Complexity: O(n)
|
|
745
649
|
* Space Complexity: O(n)
|
|
@@ -751,11 +655,6 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|
|
751
655
|
return [...this];
|
|
752
656
|
}
|
|
753
657
|
|
|
754
|
-
/**
|
|
755
|
-
* Time Complexity: O(n)
|
|
756
|
-
* Space Complexity: O(n)
|
|
757
|
-
*/
|
|
758
|
-
|
|
759
658
|
/**
|
|
760
659
|
* Time Complexity: O(n)
|
|
761
660
|
* Space Complexity: O(n)
|
|
@@ -769,11 +668,6 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|
|
769
668
|
return new Deque<E, R>(this, { bucketSize: this.bucketSize, toElementFn: this.toElementFn });
|
|
770
669
|
}
|
|
771
670
|
|
|
772
|
-
/**
|
|
773
|
-
* Time Complexity: O(n)
|
|
774
|
-
* Space Complexity: O(n)
|
|
775
|
-
*/
|
|
776
|
-
|
|
777
671
|
/**
|
|
778
672
|
* Time Complexity: O(n)
|
|
779
673
|
* Space Complexity: O(n)
|
|
@@ -805,9 +699,7 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|
|
805
699
|
/**
|
|
806
700
|
* Time Complexity: O(n)
|
|
807
701
|
* Space Complexity: O(n)
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
/**
|
|
702
|
+
*
|
|
811
703
|
* The `map` function takes a callback function and applies it to each element in the deque,
|
|
812
704
|
* returning a new deque with the results.
|
|
813
705
|
* @param callback - The callback parameter is a function that will be called for each element in the
|
|
@@ -836,11 +728,6 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|
|
836
728
|
return newDeque;
|
|
837
729
|
}
|
|
838
730
|
|
|
839
|
-
/**
|
|
840
|
-
* Time Complexity: O(n)
|
|
841
|
-
* Space Complexity: O(1)
|
|
842
|
-
*/
|
|
843
|
-
|
|
844
731
|
/**
|
|
845
732
|
* Time Complexity: O(n)
|
|
846
733
|
* Space Complexity: O(1)
|
|
@@ -854,11 +741,6 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|
|
854
741
|
}
|
|
855
742
|
}
|
|
856
743
|
|
|
857
|
-
/**
|
|
858
|
-
* Time Complexity: O(n)
|
|
859
|
-
* Space Complexity: O(n)
|
|
860
|
-
*/
|
|
861
|
-
|
|
862
744
|
/**
|
|
863
745
|
* Time Complexity: O(n)
|
|
864
746
|
* Space Complexity: O(n)
|
|
@@ -890,11 +772,6 @@ export class Deque<E = any, R = any> extends IterableElementBase<E, R, Deque<E,
|
|
|
890
772
|
this._bucketCount = newBuckets.length;
|
|
891
773
|
}
|
|
892
774
|
|
|
893
|
-
/**
|
|
894
|
-
* Time Complexity: O(1)
|
|
895
|
-
* Space Complexity: O(1)
|
|
896
|
-
*/
|
|
897
|
-
|
|
898
775
|
/**
|
|
899
776
|
* Time Complexity: O(1)
|
|
900
777
|
* Space Complexity: O(1)
|
|
@@ -61,11 +61,6 @@ export class Queue<E = any, R = any> extends IterableElementBase<E, R, Queue<E,
|
|
|
61
61
|
return this.elements.length - this.offset;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
/**
|
|
65
|
-
* Time Complexity: O(1)
|
|
66
|
-
* Space Complexity: O(1)
|
|
67
|
-
*/
|
|
68
|
-
|
|
69
64
|
/**
|
|
70
65
|
* Time Complexity: O(1)
|
|
71
66
|
* Space Complexity: O(1)
|
|
@@ -78,11 +73,6 @@ export class Queue<E = any, R = any> extends IterableElementBase<E, R, Queue<E,
|
|
|
78
73
|
return this.size > 0 ? this.elements[this.offset] : undefined;
|
|
79
74
|
}
|
|
80
75
|
|
|
81
|
-
/**
|
|
82
|
-
* Time Complexity: O(1)
|
|
83
|
-
* Space Complexity: O(1)
|
|
84
|
-
*/
|
|
85
|
-
|
|
86
76
|
/**
|
|
87
77
|
* Time Complexity: O(1)
|
|
88
78
|
* Space Complexity: O(1)
|
|
@@ -95,7 +85,7 @@ export class Queue<E = any, R = any> extends IterableElementBase<E, R, Queue<E,
|
|
|
95
85
|
return this.size > 0 ? this.elements[this.elements.length - 1] : undefined;
|
|
96
86
|
}
|
|
97
87
|
|
|
98
|
-
_autoCompactRatio: number = 0.5;
|
|
88
|
+
protected _autoCompactRatio: number = 0.5;
|
|
99
89
|
|
|
100
90
|
/**
|
|
101
91
|
* This function returns the value of the autoCompactRatio property.
|
|
@@ -114,11 +104,6 @@ export class Queue<E = any, R = any> extends IterableElementBase<E, R, Queue<E,
|
|
|
114
104
|
this._autoCompactRatio = v;
|
|
115
105
|
}
|
|
116
106
|
|
|
117
|
-
/**
|
|
118
|
-
* Time Complexity: O(n)
|
|
119
|
-
* Space Complexity: O(n)
|
|
120
|
-
*/
|
|
121
|
-
|
|
122
107
|
/**
|
|
123
108
|
* Time Complexity: O(n)
|
|
124
109
|
* Space Complexity: O(n)
|
|
@@ -133,11 +118,6 @@ export class Queue<E = any, R = any> extends IterableElementBase<E, R, Queue<E,
|
|
|
133
118
|
return new Queue(elements);
|
|
134
119
|
}
|
|
135
120
|
|
|
136
|
-
/**
|
|
137
|
-
* Time Complexity: O(1)
|
|
138
|
-
* Space Complexity: O(1)
|
|
139
|
-
*/
|
|
140
|
-
|
|
141
121
|
/**
|
|
142
122
|
* Time Complexity: O(1)
|
|
143
123
|
* Space Complexity: O(1)
|
|
@@ -151,11 +131,6 @@ export class Queue<E = any, R = any> extends IterableElementBase<E, R, Queue<E,
|
|
|
151
131
|
return true;
|
|
152
132
|
}
|
|
153
133
|
|
|
154
|
-
/**
|
|
155
|
-
* Time Complexity: O(1)
|
|
156
|
-
* Space Complexity: O(1)
|
|
157
|
-
*/
|
|
158
|
-
|
|
159
134
|
/**
|
|
160
135
|
* Time Complexity: O(1)
|
|
161
136
|
* Space Complexity: O(1)
|
|
@@ -194,11 +169,6 @@ export class Queue<E = any, R = any> extends IterableElementBase<E, R, Queue<E,
|
|
|
194
169
|
return spliced.length === 1;
|
|
195
170
|
}
|
|
196
171
|
|
|
197
|
-
/**
|
|
198
|
-
* Time Complexity: O(1)
|
|
199
|
-
* Space Complexity: O(1)
|
|
200
|
-
*/
|
|
201
|
-
|
|
202
172
|
/**
|
|
203
173
|
* Time Complexity: O(1)
|
|
204
174
|
* Space Complexity: O(1)
|
|
@@ -209,11 +179,6 @@ export class Queue<E = any, R = any> extends IterableElementBase<E, R, Queue<E,
|
|
|
209
179
|
return this.elements[index + this._offset];
|
|
210
180
|
}
|
|
211
181
|
|
|
212
|
-
/**
|
|
213
|
-
* Time Complexity: O(1)
|
|
214
|
-
* Space Complexity: O(1)
|
|
215
|
-
*/
|
|
216
|
-
|
|
217
182
|
/**
|
|
218
183
|
* Time Complexity: O(1)
|
|
219
184
|
* Space Complexity: O(1)
|
|
@@ -225,11 +190,6 @@ export class Queue<E = any, R = any> extends IterableElementBase<E, R, Queue<E,
|
|
|
225
190
|
return this.size === 0;
|
|
226
191
|
}
|
|
227
192
|
|
|
228
|
-
/**
|
|
229
|
-
* Time Complexity: O(1)
|
|
230
|
-
* Space Complexity: O(n)
|
|
231
|
-
*/
|
|
232
|
-
|
|
233
193
|
/**
|
|
234
194
|
* Time Complexity: O(1)
|
|
235
195
|
* Space Complexity: O(n)
|
|
@@ -241,11 +201,6 @@ export class Queue<E = any, R = any> extends IterableElementBase<E, R, Queue<E,
|
|
|
241
201
|
return this.elements.slice(this.offset);
|
|
242
202
|
}
|
|
243
203
|
|
|
244
|
-
/**
|
|
245
|
-
* Time Complexity: O(1)
|
|
246
|
-
* Space Complexity: O(1)
|
|
247
|
-
*/
|
|
248
|
-
|
|
249
204
|
/**
|
|
250
205
|
* Time Complexity: O(1)
|
|
251
206
|
* Space Complexity: O(1)
|
|
@@ -268,12 +223,6 @@ export class Queue<E = any, R = any> extends IterableElementBase<E, R, Queue<E,
|
|
|
268
223
|
return true;
|
|
269
224
|
}
|
|
270
225
|
|
|
271
|
-
/**
|
|
272
|
-
* Time Complexity: O(n)
|
|
273
|
-
* Space Complexity: O(n)
|
|
274
|
-
* where n is the number of elements in the queue. It creates a shallow copy of the internal array. the space required is proportional to the number of elements in the queue.
|
|
275
|
-
*/
|
|
276
|
-
|
|
277
226
|
/**
|
|
278
227
|
* Time Complexity: O(n)
|
|
279
228
|
* Space Complexity: O(n)
|
|
@@ -285,11 +234,6 @@ export class Queue<E = any, R = any> extends IterableElementBase<E, R, Queue<E,
|
|
|
285
234
|
return new Queue(this.elements.slice(this.offset), { toElementFn: this.toElementFn });
|
|
286
235
|
}
|
|
287
236
|
|
|
288
|
-
/**
|
|
289
|
-
* Time Complexity: O(n)
|
|
290
|
-
* Space Complexity: O(n)
|
|
291
|
-
*/
|
|
292
|
-
|
|
293
237
|
/**
|
|
294
238
|
* Time Complexity: O(n)
|
|
295
239
|
* Space Complexity: O(n)
|
|
@@ -322,7 +266,6 @@ export class Queue<E = any, R = any> extends IterableElementBase<E, R, Queue<E,
|
|
|
322
266
|
* Time Complexity: O(n)
|
|
323
267
|
* Space Complexity: O(n)
|
|
324
268
|
*/
|
|
325
|
-
|
|
326
269
|
map<EM, RM>(
|
|
327
270
|
callback: ElementCallback<E, R, EM, Queue<E, R>>,
|
|
328
271
|
toElementFn?: (rawElement: RM) => EM,
|
|
@@ -337,11 +280,6 @@ export class Queue<E = any, R = any> extends IterableElementBase<E, R, Queue<E,
|
|
|
337
280
|
return newDeque;
|
|
338
281
|
}
|
|
339
282
|
|
|
340
|
-
/**
|
|
341
|
-
* Time Complexity: O(n)
|
|
342
|
-
* Space Complexity: O(n)
|
|
343
|
-
*/
|
|
344
|
-
|
|
345
283
|
/**
|
|
346
284
|
* Time Complexity: O(n)
|
|
347
285
|
* Space Complexity: O(n)
|
|
@@ -362,11 +300,6 @@ export class Queue<E = any, R = any> extends IterableElementBase<E, R, Queue<E,
|
|
|
362
300
|
* 4. Frequent Enqueuing and Dequeuing Operations: If your application involves frequent enqueuing and dequeuing operations and is less concerned with random access, then LinkedListQueue is a good choice.
|
|
363
301
|
*/
|
|
364
302
|
export class LinkedListQueue<E = any, R = any> extends SinglyLinkedList<E, R> {
|
|
365
|
-
/**
|
|
366
|
-
* Time Complexity: O(n)
|
|
367
|
-
* Space Complexity: O(n)
|
|
368
|
-
*/
|
|
369
|
-
|
|
370
303
|
/**
|
|
371
304
|
* Time Complexity: O(n)
|
|
372
305
|
* Space Complexity: O(n)
|
|
@@ -74,11 +74,6 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R, Stack<E,
|
|
|
74
74
|
return this.elements.length === 0;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
/**
|
|
78
|
-
* Time Complexity: O(1)
|
|
79
|
-
* Space Complexity: O(1)
|
|
80
|
-
*/
|
|
81
|
-
|
|
82
77
|
/**
|
|
83
78
|
* Time Complexity: O(1)
|
|
84
79
|
* Space Complexity: O(1)
|
|
@@ -92,11 +87,6 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R, Stack<E,
|
|
|
92
87
|
return this.elements[this.elements.length - 1];
|
|
93
88
|
}
|
|
94
89
|
|
|
95
|
-
/**
|
|
96
|
-
* Time Complexity: O(1)
|
|
97
|
-
* Space Complexity: O(1)
|
|
98
|
-
*/
|
|
99
|
-
|
|
100
90
|
/**
|
|
101
91
|
* Time Complexity: O(1)
|
|
102
92
|
* Space Complexity: O(1)
|
|
@@ -110,11 +100,6 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R, Stack<E,
|
|
|
110
100
|
return true;
|
|
111
101
|
}
|
|
112
102
|
|
|
113
|
-
/**
|
|
114
|
-
* Time Complexity: O(1)
|
|
115
|
-
* Space Complexity: O(1)
|
|
116
|
-
*/
|
|
117
|
-
|
|
118
103
|
/**
|
|
119
104
|
* Time Complexity: O(1)
|
|
120
105
|
* Space Complexity: O(1)
|
|
@@ -149,11 +134,6 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R, Stack<E,
|
|
|
149
134
|
return spliced.length === 1;
|
|
150
135
|
}
|
|
151
136
|
|
|
152
|
-
/**
|
|
153
|
-
* Time Complexity: O(n)
|
|
154
|
-
* Space Complexity: O(n)
|
|
155
|
-
*/
|
|
156
|
-
|
|
157
137
|
/**
|
|
158
138
|
* Time Complexity: O(n)
|
|
159
139
|
* Space Complexity: O(n)
|
|
@@ -165,11 +145,6 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R, Stack<E,
|
|
|
165
145
|
return this.elements.slice();
|
|
166
146
|
}
|
|
167
147
|
|
|
168
|
-
/**
|
|
169
|
-
* Time Complexity: O(1)
|
|
170
|
-
* Space Complexity: O(1)
|
|
171
|
-
*/
|
|
172
|
-
|
|
173
148
|
/**
|
|
174
149
|
* Time Complexity: O(1)
|
|
175
150
|
* Space Complexity: O(1)
|
|
@@ -180,11 +155,6 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R, Stack<E,
|
|
|
180
155
|
this._elements = [];
|
|
181
156
|
}
|
|
182
157
|
|
|
183
|
-
/**
|
|
184
|
-
* Time Complexity: O(n)
|
|
185
|
-
* Space Complexity: O(n)
|
|
186
|
-
*/
|
|
187
|
-
|
|
188
158
|
/**
|
|
189
159
|
* Time Complexity: O(n)
|
|
190
160
|
* Space Complexity: O(n)
|
|
@@ -196,11 +166,6 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R, Stack<E,
|
|
|
196
166
|
return new Stack<E, R>(this, { toElementFn: this.toElementFn });
|
|
197
167
|
}
|
|
198
168
|
|
|
199
|
-
/**
|
|
200
|
-
* Time Complexity: O(n)
|
|
201
|
-
* Space Complexity: O(n)
|
|
202
|
-
*/
|
|
203
|
-
|
|
204
169
|
/**
|
|
205
170
|
* Time Complexity: O(n)
|
|
206
171
|
* Space Complexity: O(n)
|
|
@@ -232,9 +197,7 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R, Stack<E,
|
|
|
232
197
|
/**
|
|
233
198
|
* Time Complexity: O(n)
|
|
234
199
|
* Space Complexity: O(n)
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
/**
|
|
200
|
+
*
|
|
238
201
|
* The `map` function takes a callback function and applies it to each element in the stack,
|
|
239
202
|
* returning a new stack with the results.
|
|
240
203
|
* @param callback - The callback parameter is a function that will be called for each element in the
|
|
@@ -262,11 +225,6 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R, Stack<E,
|
|
|
262
225
|
return newStack;
|
|
263
226
|
}
|
|
264
227
|
|
|
265
|
-
/**
|
|
266
|
-
* Time Complexity: O(n)
|
|
267
|
-
* Space Complexity: O(n)
|
|
268
|
-
*/
|
|
269
|
-
|
|
270
228
|
/**
|
|
271
229
|
* Time Complexity: O(n)
|
|
272
230
|
* Space Complexity: O(n)
|
|
@@ -12,7 +12,7 @@ export class TreeNode<V = any> {
|
|
|
12
12
|
constructor(key: string, value?: V, children?: TreeNode<V>[]) {
|
|
13
13
|
this._key = key;
|
|
14
14
|
this._value = value || undefined;
|
|
15
|
-
this._children = children
|
|
15
|
+
if (children) this._children = children;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
protected _key: string;
|