binary-tree-typed 2.5.1 → 2.5.3
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/cjs/index.cjs +340 -107
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +339 -106
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +340 -108
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +339 -107
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/common/error.d.ts +9 -0
- package/dist/types/common/index.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +86 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +98 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +189 -13
- package/dist/types/data-structures/binary-tree/bst.d.ts +270 -3
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +136 -8
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +42 -0
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +1089 -161
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1243 -350
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +980 -255
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +1174 -284
- package/dist/types/data-structures/graph/directed-graph.d.ts +70 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +63 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +84 -6
- package/dist/types/data-structures/heap/heap.d.ts +140 -12
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +126 -0
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +106 -1
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +126 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +56 -0
- package/dist/types/data-structures/queue/deque.d.ts +127 -0
- package/dist/types/data-structures/queue/queue.d.ts +97 -0
- package/dist/types/data-structures/stack/stack.d.ts +72 -2
- package/dist/types/data-structures/trie/trie.d.ts +84 -0
- package/dist/types/interfaces/binary-tree.d.ts +2 -3
- package/dist/types/types/data-structures/binary-tree/bst.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
- package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
- package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
- package/dist/umd/binary-tree-typed.js +337 -105
- package/dist/umd/binary-tree-typed.js.map +1 -1
- package/dist/umd/binary-tree-typed.min.js +5 -5
- package/dist/umd/binary-tree-typed.min.js.map +1 -1
- package/package.json +2 -2
- package/src/common/error.ts +19 -1
- package/src/common/index.ts +1 -1
- package/src/data-structures/base/iterable-element-base.ts +3 -2
- package/src/data-structures/binary-tree/avl-tree.ts +99 -5
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +102 -4
- package/src/data-structures/binary-tree/binary-tree.ts +239 -78
- package/src/data-structures/binary-tree/bst.ts +542 -13
- package/src/data-structures/binary-tree/red-black-tree.ts +155 -15
- package/src/data-structures/binary-tree/segment-tree.ts +42 -0
- package/src/data-structures/binary-tree/tree-map.ts +1223 -261
- package/src/data-structures/binary-tree/tree-multi-map.ts +939 -30
- package/src/data-structures/binary-tree/tree-multi-set.ts +746 -10
- package/src/data-structures/binary-tree/tree-set.ts +1018 -99
- package/src/data-structures/graph/abstract-graph.ts +2 -2
- package/src/data-structures/graph/directed-graph.ts +71 -1
- package/src/data-structures/graph/undirected-graph.ts +64 -1
- package/src/data-structures/hash/hash-map.ts +102 -16
- package/src/data-structures/heap/heap.ts +153 -23
- package/src/data-structures/heap/max-heap.ts +2 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +139 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +106 -1
- package/src/data-structures/linked-list/skip-linked-list.ts +131 -5
- package/src/data-structures/matrix/matrix.ts +65 -9
- package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
- package/src/data-structures/queue/deque.ts +130 -0
- package/src/data-structures/queue/queue.ts +109 -0
- package/src/data-structures/stack/stack.ts +75 -5
- package/src/data-structures/trie/trie.ts +86 -2
- package/src/interfaces/binary-tree.ts +1 -9
- package/src/types/data-structures/binary-tree/bst.ts +1 -0
- package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
- package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
- package/src/types/data-structures/binary-tree/tree-set.ts +5 -0
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
|
|
9
9
|
import type { Comparator, DFSOrderPattern, ElementCallback, HeapOptions } from '../../types';
|
|
10
10
|
import { IterableElementBase } from '../base';
|
|
11
|
-
import { ERR } from '../../common';
|
|
11
|
+
import { ERR, raise } from '../../common';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Binary heap with pluggable comparator; supports fast insertion and removal of the top element.
|
|
15
|
-
* @remarks
|
|
15
|
+
* @remarks Typical operations: O(log N) insert/remove, O(1) peek. Space O(N).
|
|
16
16
|
* @template E
|
|
17
17
|
* @template R
|
|
18
18
|
* 1. Complete Binary Tree: Heaps are typically complete binary trees, meaning every level is fully filled except possibly for the last level, which has nodes as far left as possible.
|
|
@@ -209,6 +209,13 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
209
209
|
|
|
210
210
|
|
|
211
211
|
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
212
219
|
|
|
213
220
|
|
|
214
221
|
|
|
@@ -277,7 +284,7 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
277
284
|
|
|
278
285
|
/**
|
|
279
286
|
* Insert an element.
|
|
280
|
-
* @remarks Time O(
|
|
287
|
+
* @remarks Time O(log N) amortized, Space O(1)
|
|
281
288
|
* @param element - Element to insert.
|
|
282
289
|
* @returns True.
|
|
283
290
|
|
|
@@ -304,6 +311,13 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
304
311
|
|
|
305
312
|
|
|
306
313
|
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
|
|
307
321
|
|
|
308
322
|
|
|
309
323
|
|
|
@@ -360,6 +374,13 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
360
374
|
|
|
361
375
|
|
|
362
376
|
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
|
|
363
384
|
|
|
364
385
|
|
|
365
386
|
|
|
@@ -419,6 +440,12 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
419
440
|
|
|
420
441
|
|
|
421
442
|
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
|
|
422
449
|
|
|
423
450
|
|
|
424
451
|
|
|
@@ -453,7 +480,44 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
453
480
|
* console.log(topTask?.name); // 'Alert';
|
|
454
481
|
*/
|
|
455
482
|
|
|
483
|
+
/**
|
|
484
|
+
* @deprecated Use `pop` instead. Will be removed in a future major version.
|
|
485
|
+
* @example
|
|
486
|
+
* // Heap with custom comparator (MaxHeap behavior)
|
|
487
|
+
* interface Task {
|
|
488
|
+
* id: number;
|
|
489
|
+
* priority: number;
|
|
490
|
+
* name: string;
|
|
491
|
+
* }
|
|
492
|
+
*
|
|
493
|
+
* // Custom comparator for max heap behavior (higher priority first)
|
|
494
|
+
* const tasks: Task[] = [
|
|
495
|
+
* { id: 1, priority: 5, name: 'Email' },
|
|
496
|
+
* { id: 2, priority: 3, name: 'Chat' },
|
|
497
|
+
* { id: 3, priority: 8, name: 'Alert' }
|
|
498
|
+
* ];
|
|
499
|
+
*
|
|
500
|
+
* const maxHeap = new Heap(tasks, {
|
|
501
|
+
* comparator: (a: Task, b: Task) => b.priority - a.priority
|
|
502
|
+
* });
|
|
503
|
+
*
|
|
504
|
+
* console.log(maxHeap.size); // 3;
|
|
505
|
+
*
|
|
506
|
+
* // Peek returns highest priority task
|
|
507
|
+
* const topTask = maxHeap.peek();
|
|
508
|
+
* console.log(topTask?.priority); // 8;
|
|
509
|
+
* console.log(topTask?.name); // 'Alert';
|
|
510
|
+
*/
|
|
456
511
|
poll(): E | undefined {
|
|
512
|
+
return this.pop();
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Remove and return the top element (min or max depending on comparator).
|
|
517
|
+
* @remarks Time O(log N) amortized, Space O(1)
|
|
518
|
+
* @returns The removed top element, or undefined if empty.
|
|
519
|
+
*/
|
|
520
|
+
pop(): E | undefined {
|
|
457
521
|
if (this.elements.length === 0) return;
|
|
458
522
|
const value = this.elements[0];
|
|
459
523
|
const last = this.elements.pop()!;
|
|
@@ -492,6 +556,13 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
492
556
|
|
|
493
557
|
|
|
494
558
|
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
|
|
562
|
+
|
|
563
|
+
|
|
564
|
+
|
|
565
|
+
|
|
495
566
|
|
|
496
567
|
|
|
497
568
|
|
|
@@ -591,6 +662,13 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
591
662
|
|
|
592
663
|
|
|
593
664
|
|
|
665
|
+
|
|
666
|
+
|
|
667
|
+
|
|
668
|
+
|
|
669
|
+
|
|
670
|
+
|
|
671
|
+
|
|
594
672
|
|
|
595
673
|
|
|
596
674
|
|
|
@@ -637,6 +715,13 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
637
715
|
|
|
638
716
|
|
|
639
717
|
|
|
718
|
+
|
|
719
|
+
|
|
720
|
+
|
|
721
|
+
|
|
722
|
+
|
|
723
|
+
|
|
724
|
+
|
|
640
725
|
|
|
641
726
|
|
|
642
727
|
|
|
@@ -656,17 +741,7 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
656
741
|
this._elements = [];
|
|
657
742
|
}
|
|
658
743
|
|
|
659
|
-
/**
|
|
660
|
-
* Replace the backing array and rebuild the heap.
|
|
661
|
-
* @remarks Time O(N), Space O(N)
|
|
662
|
-
* @param elements - Iterable used to refill the heap.
|
|
663
|
-
* @returns Array of per-node results from fixing steps.
|
|
664
|
-
*/
|
|
665
744
|
|
|
666
|
-
refill(elements: Iterable<E>): boolean[] {
|
|
667
|
-
this._elements = Array.from(elements);
|
|
668
|
-
return this.fix();
|
|
669
|
-
}
|
|
670
745
|
|
|
671
746
|
/**
|
|
672
747
|
* Check if an equal element exists in the heap.
|
|
@@ -688,6 +763,13 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
688
763
|
|
|
689
764
|
|
|
690
765
|
|
|
766
|
+
|
|
767
|
+
|
|
768
|
+
|
|
769
|
+
|
|
770
|
+
|
|
771
|
+
|
|
772
|
+
|
|
691
773
|
|
|
692
774
|
|
|
693
775
|
|
|
@@ -734,6 +816,13 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
734
816
|
|
|
735
817
|
|
|
736
818
|
|
|
819
|
+
|
|
820
|
+
|
|
821
|
+
|
|
822
|
+
|
|
823
|
+
|
|
824
|
+
|
|
825
|
+
|
|
737
826
|
|
|
738
827
|
|
|
739
828
|
|
|
@@ -759,7 +848,7 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
759
848
|
}
|
|
760
849
|
if (index < 0) return false;
|
|
761
850
|
if (index === 0) {
|
|
762
|
-
this.
|
|
851
|
+
this.pop();
|
|
763
852
|
} else if (index === this.elements.length - 1) {
|
|
764
853
|
this.elements.pop();
|
|
765
854
|
} else {
|
|
@@ -770,14 +859,20 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
770
859
|
return true;
|
|
771
860
|
}
|
|
772
861
|
|
|
862
|
+
/**
|
|
863
|
+
* @deprecated Use `deleteWhere` instead. Will be removed in a future major version.
|
|
864
|
+
*/
|
|
865
|
+
deleteBy(predicate: (element: E, index: number, heap: this) => boolean): boolean {
|
|
866
|
+
return this.deleteWhere(predicate);
|
|
867
|
+
}
|
|
868
|
+
|
|
773
869
|
/**
|
|
774
870
|
* Delete the first element that matches a predicate.
|
|
775
871
|
* @remarks Time O(N), Space O(1)
|
|
776
872
|
* @param predicate - Function (element, index, heap) → boolean.
|
|
777
873
|
* @returns True if an element was removed.
|
|
778
874
|
*/
|
|
779
|
-
|
|
780
|
-
deleteBy(predicate: (element: E, index: number, heap: this) => boolean): boolean {
|
|
875
|
+
deleteWhere(predicate: (element: E, index: number, heap: this) => boolean): boolean {
|
|
781
876
|
let idx = -1;
|
|
782
877
|
for (let i = 0; i < this.elements.length; i++) {
|
|
783
878
|
if (predicate(this.elements[i], i, this)) {
|
|
@@ -787,7 +882,7 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
787
882
|
}
|
|
788
883
|
if (idx < 0) return false;
|
|
789
884
|
if (idx === 0) {
|
|
790
|
-
this.
|
|
885
|
+
this.pop();
|
|
791
886
|
} else if (idx === this.elements.length - 1) {
|
|
792
887
|
this.elements.pop();
|
|
793
888
|
} else {
|
|
@@ -830,6 +925,13 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
830
925
|
|
|
831
926
|
|
|
832
927
|
|
|
928
|
+
|
|
929
|
+
|
|
930
|
+
|
|
931
|
+
|
|
932
|
+
|
|
933
|
+
|
|
934
|
+
|
|
833
935
|
|
|
834
936
|
|
|
835
937
|
|
|
@@ -912,6 +1014,13 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
912
1014
|
|
|
913
1015
|
|
|
914
1016
|
|
|
1017
|
+
|
|
1018
|
+
|
|
1019
|
+
|
|
1020
|
+
|
|
1021
|
+
|
|
1022
|
+
|
|
1023
|
+
|
|
915
1024
|
|
|
916
1025
|
|
|
917
1026
|
|
|
@@ -964,6 +1073,13 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
964
1073
|
|
|
965
1074
|
|
|
966
1075
|
|
|
1076
|
+
|
|
1077
|
+
|
|
1078
|
+
|
|
1079
|
+
|
|
1080
|
+
|
|
1081
|
+
|
|
1082
|
+
|
|
967
1083
|
|
|
968
1084
|
|
|
969
1085
|
|
|
@@ -1015,6 +1131,13 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
1015
1131
|
|
|
1016
1132
|
|
|
1017
1133
|
|
|
1134
|
+
|
|
1135
|
+
|
|
1136
|
+
|
|
1137
|
+
|
|
1138
|
+
|
|
1139
|
+
|
|
1140
|
+
|
|
1018
1141
|
|
|
1019
1142
|
|
|
1020
1143
|
|
|
@@ -1073,6 +1196,13 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
1073
1196
|
|
|
1074
1197
|
|
|
1075
1198
|
|
|
1199
|
+
|
|
1200
|
+
|
|
1201
|
+
|
|
1202
|
+
|
|
1203
|
+
|
|
1204
|
+
|
|
1205
|
+
|
|
1076
1206
|
|
|
1077
1207
|
|
|
1078
1208
|
|
|
@@ -1094,7 +1224,7 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
1094
1224
|
thisArg?: unknown
|
|
1095
1225
|
): Heap<EM, RM> {
|
|
1096
1226
|
const { comparator, toElementFn, ...rest } = options ?? {};
|
|
1097
|
-
if (!comparator)
|
|
1227
|
+
if (!comparator) raise(TypeError, ERR.comparatorRequired('Heap.map'));
|
|
1098
1228
|
const out = this._createLike<EM, RM>([], { ...rest, comparator, toElementFn });
|
|
1099
1229
|
let i = 0;
|
|
1100
1230
|
for (const x of this) {
|
|
@@ -1124,7 +1254,7 @@ export class Heap<E = any, R = any> extends IterableElementBase<E, R> {
|
|
|
1124
1254
|
|
|
1125
1255
|
protected readonly _DEFAULT_COMPARATOR: Comparator<E> = (a: E, b: E): number => {
|
|
1126
1256
|
if (typeof a === 'object' || typeof b === 'object') {
|
|
1127
|
-
|
|
1257
|
+
raise(TypeError, ERR.comparatorRequired('Heap'));
|
|
1128
1258
|
}
|
|
1129
1259
|
if (a > b) return 1;
|
|
1130
1260
|
if (a < b) return -1;
|
|
@@ -1266,7 +1396,7 @@ export class FibonacciHeap<E> {
|
|
|
1266
1396
|
constructor(comparator?: Comparator<E>) {
|
|
1267
1397
|
this.clear();
|
|
1268
1398
|
this._comparator = comparator || this._defaultComparator;
|
|
1269
|
-
if (typeof this.comparator !== 'function')
|
|
1399
|
+
if (typeof this.comparator !== 'function') raise(TypeError, ERR.notAFunction('comparator', 'FibonacciHeap'));
|
|
1270
1400
|
}
|
|
1271
1401
|
|
|
1272
1402
|
protected _root?: FibonacciHeapNode<E>;
|
|
@@ -1319,17 +1449,17 @@ export class FibonacciHeap<E> {
|
|
|
1319
1449
|
* Push an element into the root list.
|
|
1320
1450
|
* @remarks Time O(1) amortized, Space O(1)
|
|
1321
1451
|
* @param element - Element to insert.
|
|
1322
|
-
* @returns
|
|
1452
|
+
* @returns True when the element is added.
|
|
1323
1453
|
*/
|
|
1324
1454
|
|
|
1325
|
-
push(element: E):
|
|
1455
|
+
push(element: E): boolean {
|
|
1326
1456
|
const node = this.createNode(element);
|
|
1327
1457
|
node.left = node;
|
|
1328
1458
|
node.right = node;
|
|
1329
1459
|
this.mergeWithRoot(node);
|
|
1330
1460
|
if (!this.min || this.comparator(node.element, this.min.element) <= 0) this._min = node;
|
|
1331
1461
|
this._size++;
|
|
1332
|
-
return
|
|
1462
|
+
return true;
|
|
1333
1463
|
}
|
|
1334
1464
|
|
|
1335
1465
|
peek(): E | undefined {
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { HeapOptions } from '../../types';
|
|
8
8
|
import { Heap } from './heap';
|
|
9
|
-
import { ERR } from '../../common';
|
|
9
|
+
import { ERR, raise } from '../../common';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* @template E
|
|
@@ -80,7 +80,7 @@ export class MaxHeap<E = any, R = any> extends Heap<E, R> {
|
|
|
80
80
|
super(elements, {
|
|
81
81
|
comparator: (a: E, b: E): number => {
|
|
82
82
|
if (typeof a === 'object' || typeof b === 'object') {
|
|
83
|
-
|
|
83
|
+
raise(TypeError, ERR.comparatorRequired('MaxHeap'));
|
|
84
84
|
}
|
|
85
85
|
if (a < b) return 1;
|
|
86
86
|
if (a > b) return -1;
|
|
@@ -292,6 +292,13 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
|
|
|
292
292
|
|
|
293
293
|
|
|
294
294
|
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
|
|
295
302
|
|
|
296
303
|
|
|
297
304
|
|
|
@@ -360,6 +367,13 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
|
|
|
360
367
|
|
|
361
368
|
|
|
362
369
|
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
|
|
363
377
|
|
|
364
378
|
|
|
365
379
|
|
|
@@ -427,6 +441,13 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
|
|
|
427
441
|
|
|
428
442
|
|
|
429
443
|
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
|
|
430
451
|
|
|
431
452
|
|
|
432
453
|
|
|
@@ -485,6 +506,13 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
|
|
|
485
506
|
|
|
486
507
|
|
|
487
508
|
|
|
509
|
+
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
|
|
515
|
+
|
|
488
516
|
|
|
489
517
|
|
|
490
518
|
|
|
@@ -576,6 +604,13 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
|
|
|
576
604
|
|
|
577
605
|
|
|
578
606
|
|
|
607
|
+
|
|
608
|
+
|
|
609
|
+
|
|
610
|
+
|
|
611
|
+
|
|
612
|
+
|
|
613
|
+
|
|
579
614
|
|
|
580
615
|
|
|
581
616
|
|
|
@@ -624,6 +659,13 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
|
|
|
624
659
|
|
|
625
660
|
|
|
626
661
|
|
|
662
|
+
|
|
663
|
+
|
|
664
|
+
|
|
665
|
+
|
|
666
|
+
|
|
667
|
+
|
|
668
|
+
|
|
627
669
|
|
|
628
670
|
|
|
629
671
|
|
|
@@ -711,6 +753,13 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
|
|
|
711
753
|
|
|
712
754
|
|
|
713
755
|
|
|
756
|
+
|
|
757
|
+
|
|
758
|
+
|
|
759
|
+
|
|
760
|
+
|
|
761
|
+
|
|
762
|
+
|
|
714
763
|
|
|
715
764
|
|
|
716
765
|
|
|
@@ -834,6 +883,13 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
|
|
|
834
883
|
|
|
835
884
|
|
|
836
885
|
|
|
886
|
+
|
|
887
|
+
|
|
888
|
+
|
|
889
|
+
|
|
890
|
+
|
|
891
|
+
|
|
892
|
+
|
|
837
893
|
|
|
838
894
|
|
|
839
895
|
|
|
@@ -889,6 +945,13 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
|
|
|
889
945
|
|
|
890
946
|
|
|
891
947
|
|
|
948
|
+
|
|
949
|
+
|
|
950
|
+
|
|
951
|
+
|
|
952
|
+
|
|
953
|
+
|
|
954
|
+
|
|
892
955
|
|
|
893
956
|
|
|
894
957
|
|
|
@@ -946,6 +1009,13 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
|
|
|
946
1009
|
|
|
947
1010
|
|
|
948
1011
|
|
|
1012
|
+
|
|
1013
|
+
|
|
1014
|
+
|
|
1015
|
+
|
|
1016
|
+
|
|
1017
|
+
|
|
1018
|
+
|
|
949
1019
|
|
|
950
1020
|
|
|
951
1021
|
|
|
@@ -989,6 +1059,13 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
|
|
|
989
1059
|
|
|
990
1060
|
|
|
991
1061
|
|
|
1062
|
+
|
|
1063
|
+
|
|
1064
|
+
|
|
1065
|
+
|
|
1066
|
+
|
|
1067
|
+
|
|
1068
|
+
|
|
992
1069
|
|
|
993
1070
|
|
|
994
1071
|
|
|
@@ -1036,6 +1113,13 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
|
|
|
1036
1113
|
|
|
1037
1114
|
|
|
1038
1115
|
|
|
1116
|
+
|
|
1117
|
+
|
|
1118
|
+
|
|
1119
|
+
|
|
1120
|
+
|
|
1121
|
+
|
|
1122
|
+
|
|
1039
1123
|
|
|
1040
1124
|
|
|
1041
1125
|
|
|
@@ -1089,6 +1173,13 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
|
|
|
1089
1173
|
|
|
1090
1174
|
|
|
1091
1175
|
|
|
1176
|
+
|
|
1177
|
+
|
|
1178
|
+
|
|
1179
|
+
|
|
1180
|
+
|
|
1181
|
+
|
|
1182
|
+
|
|
1092
1183
|
|
|
1093
1184
|
|
|
1094
1185
|
|
|
@@ -1145,6 +1236,13 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
|
|
|
1145
1236
|
|
|
1146
1237
|
|
|
1147
1238
|
|
|
1239
|
+
|
|
1240
|
+
|
|
1241
|
+
|
|
1242
|
+
|
|
1243
|
+
|
|
1244
|
+
|
|
1245
|
+
|
|
1148
1246
|
|
|
1149
1247
|
|
|
1150
1248
|
|
|
@@ -1171,6 +1269,26 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
|
|
|
1171
1269
|
return this;
|
|
1172
1270
|
}
|
|
1173
1271
|
|
|
1272
|
+
/**
|
|
1273
|
+
* Delete the first element that satisfies a predicate.
|
|
1274
|
+
* @remarks Time O(N), Space O(1)
|
|
1275
|
+
* @param predicate - Function (value, index, list) → boolean to decide deletion.
|
|
1276
|
+
* @returns True if a match was removed.
|
|
1277
|
+
*/
|
|
1278
|
+
deleteWhere(predicate: (value: E, index: number, list: this) => boolean): boolean {
|
|
1279
|
+
let current = this.head;
|
|
1280
|
+
let index = 0;
|
|
1281
|
+
while (current) {
|
|
1282
|
+
if (predicate(current.value, index, this)) {
|
|
1283
|
+
this.delete(current);
|
|
1284
|
+
return true;
|
|
1285
|
+
}
|
|
1286
|
+
current = current.next;
|
|
1287
|
+
index++;
|
|
1288
|
+
}
|
|
1289
|
+
return false;
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1174
1292
|
/**
|
|
1175
1293
|
* Set the equality comparator used to compare values.
|
|
1176
1294
|
* @remarks Time O(1), Space O(1)
|
|
@@ -1209,6 +1327,13 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
|
|
|
1209
1327
|
|
|
1210
1328
|
|
|
1211
1329
|
|
|
1330
|
+
|
|
1331
|
+
|
|
1332
|
+
|
|
1333
|
+
|
|
1334
|
+
|
|
1335
|
+
|
|
1336
|
+
|
|
1212
1337
|
|
|
1213
1338
|
|
|
1214
1339
|
|
|
@@ -1261,6 +1386,13 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
|
|
|
1261
1386
|
|
|
1262
1387
|
|
|
1263
1388
|
|
|
1389
|
+
|
|
1390
|
+
|
|
1391
|
+
|
|
1392
|
+
|
|
1393
|
+
|
|
1394
|
+
|
|
1395
|
+
|
|
1264
1396
|
|
|
1265
1397
|
|
|
1266
1398
|
|
|
@@ -1334,6 +1466,13 @@ export class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, D
|
|
|
1334
1466
|
|
|
1335
1467
|
|
|
1336
1468
|
|
|
1469
|
+
|
|
1470
|
+
|
|
1471
|
+
|
|
1472
|
+
|
|
1473
|
+
|
|
1474
|
+
|
|
1475
|
+
|
|
1337
1476
|
|
|
1338
1477
|
|
|
1339
1478
|
|