deque-typed 2.5.3 → 2.6.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/dist/cjs/index.cjs +140 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +140 -1
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +140 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +140 -1
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/data-structures/base/iterable-element-base.d.ts +17 -0
- package/dist/types/data-structures/base/linear-base.d.ts +6 -0
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +36 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +42 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +75 -0
- package/dist/types/data-structures/binary-tree/bst.d.ts +72 -0
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +57 -0
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +18 -0
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +375 -0
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +389 -0
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +330 -0
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +438 -0
- package/dist/types/data-structures/graph/directed-graph.d.ts +30 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +27 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +33 -0
- package/dist/types/data-structures/heap/heap.d.ts +42 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +75 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +45 -0
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +54 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +24 -0
- package/dist/types/data-structures/queue/deque.d.ts +90 -1
- package/dist/types/data-structures/queue/queue.d.ts +36 -0
- package/dist/types/data-structures/stack/stack.d.ts +30 -0
- package/dist/types/data-structures/trie/trie.d.ts +36 -0
- package/dist/umd/deque-typed.js +140 -1
- package/dist/umd/deque-typed.js.map +1 -1
- package/dist/umd/deque-typed.min.js +1 -1
- package/dist/umd/deque-typed.min.js.map +1 -1
- package/package.json +2 -2
- package/src/data-structures/base/iterable-element-base.ts +32 -0
- package/src/data-structures/base/linear-base.ts +11 -0
- package/src/data-structures/binary-tree/avl-tree.ts +36 -0
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +42 -0
- package/src/data-structures/binary-tree/binary-tree.ts +75 -0
- package/src/data-structures/binary-tree/bst.ts +72 -0
- package/src/data-structures/binary-tree/red-black-tree.ts +57 -0
- package/src/data-structures/binary-tree/segment-tree.ts +18 -0
- package/src/data-structures/binary-tree/tree-map.ts +375 -0
- package/src/data-structures/binary-tree/tree-multi-map.ts +392 -0
- package/src/data-structures/binary-tree/tree-multi-set.ts +336 -0
- package/src/data-structures/binary-tree/tree-set.ts +492 -0
- package/src/data-structures/graph/directed-graph.ts +30 -0
- package/src/data-structures/graph/undirected-graph.ts +27 -0
- package/src/data-structures/hash/hash-map.ts +33 -0
- package/src/data-structures/heap/heap.ts +42 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +90 -2
- package/src/data-structures/linked-list/singly-linked-list.ts +45 -0
- package/src/data-structures/linked-list/skip-linked-list.ts +54 -0
- package/src/data-structures/matrix/matrix.ts +24 -0
- package/src/data-structures/queue/deque.ts +103 -1
- package/src/data-structures/queue/queue.ts +36 -0
- package/src/data-structures/stack/stack.ts +30 -0
- package/src/data-structures/trie/trie.ts +36 -0
|
@@ -253,6 +253,9 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
253
253
|
|
|
254
254
|
|
|
255
255
|
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
256
259
|
|
|
257
260
|
|
|
258
261
|
|
|
@@ -311,6 +314,9 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
311
314
|
|
|
312
315
|
|
|
313
316
|
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
|
|
314
320
|
|
|
315
321
|
|
|
316
322
|
|
|
@@ -364,6 +370,9 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
364
370
|
|
|
365
371
|
|
|
366
372
|
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
|
|
367
376
|
|
|
368
377
|
|
|
369
378
|
|
|
@@ -413,6 +422,9 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
413
422
|
|
|
414
423
|
|
|
415
424
|
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
|
|
416
428
|
|
|
417
429
|
|
|
418
430
|
|
|
@@ -461,6 +473,9 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
461
473
|
|
|
462
474
|
|
|
463
475
|
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
|
|
464
479
|
|
|
465
480
|
|
|
466
481
|
|
|
@@ -512,6 +527,9 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
512
527
|
|
|
513
528
|
|
|
514
529
|
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
|
|
515
533
|
|
|
516
534
|
|
|
517
535
|
|
|
@@ -588,6 +606,9 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
588
606
|
|
|
589
607
|
|
|
590
608
|
|
|
609
|
+
|
|
610
|
+
|
|
611
|
+
|
|
591
612
|
|
|
592
613
|
|
|
593
614
|
|
|
@@ -647,6 +668,9 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
647
668
|
|
|
648
669
|
|
|
649
670
|
|
|
671
|
+
|
|
672
|
+
|
|
673
|
+
|
|
650
674
|
|
|
651
675
|
|
|
652
676
|
|
|
@@ -700,6 +724,9 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
700
724
|
|
|
701
725
|
|
|
702
726
|
|
|
727
|
+
|
|
728
|
+
|
|
729
|
+
|
|
703
730
|
|
|
704
731
|
|
|
705
732
|
|
|
@@ -753,6 +780,9 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
753
780
|
|
|
754
781
|
|
|
755
782
|
|
|
783
|
+
|
|
784
|
+
|
|
785
|
+
|
|
756
786
|
|
|
757
787
|
|
|
758
788
|
|
|
@@ -803,6 +833,9 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
803
833
|
|
|
804
834
|
|
|
805
835
|
|
|
836
|
+
|
|
837
|
+
|
|
838
|
+
|
|
806
839
|
|
|
807
840
|
|
|
808
841
|
|
|
@@ -848,6 +881,9 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
848
881
|
|
|
849
882
|
|
|
850
883
|
|
|
884
|
+
|
|
885
|
+
|
|
886
|
+
|
|
851
887
|
|
|
852
888
|
|
|
853
889
|
|
package/dist/umd/deque-typed.js
CHANGED
|
@@ -238,6 +238,35 @@ var dequeTyped = (() => {
|
|
|
238
238
|
for (const ele of this) if (ele === element) return true;
|
|
239
239
|
return false;
|
|
240
240
|
}
|
|
241
|
+
/**
|
|
242
|
+
* Check whether a value exists (Array-compatible alias for `has`).
|
|
243
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
|
|
244
|
+
* @param element - Element to search for (uses `===`).
|
|
245
|
+
* @returns `true` if found.
|
|
246
|
+
*/
|
|
247
|
+
includes(element) {
|
|
248
|
+
return this.has(element);
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Return an iterator of `[index, value]` pairs (Array-compatible).
|
|
252
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
|
|
253
|
+
*/
|
|
254
|
+
*entries() {
|
|
255
|
+
let index = 0;
|
|
256
|
+
for (const value of this) {
|
|
257
|
+
yield [index++, value];
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Return an iterator of numeric indices (Array-compatible).
|
|
262
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
|
|
263
|
+
*/
|
|
264
|
+
*keys() {
|
|
265
|
+
let index = 0;
|
|
266
|
+
for (const _ of this) {
|
|
267
|
+
yield index++;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
241
270
|
/**
|
|
242
271
|
* Reduces all elements to a single accumulated value.
|
|
243
272
|
*
|
|
@@ -497,6 +526,16 @@ var dequeTyped = (() => {
|
|
|
497
526
|
}
|
|
498
527
|
return this;
|
|
499
528
|
}
|
|
529
|
+
/**
|
|
530
|
+
* Return a new instance of the same type with elements in reverse order (non-mutating).
|
|
531
|
+
* @remarks Provided for familiarity when migrating from Array (ES2023 `toReversed`). Time O(n), Space O(n).
|
|
532
|
+
* @returns A new reversed instance.
|
|
533
|
+
*/
|
|
534
|
+
toReversed() {
|
|
535
|
+
const cloned = this.clone();
|
|
536
|
+
cloned.reverse();
|
|
537
|
+
return cloned;
|
|
538
|
+
}
|
|
500
539
|
};
|
|
501
540
|
|
|
502
541
|
// src/data-structures/queue/deque.ts
|
|
@@ -687,7 +726,10 @@ var dequeTyped = (() => {
|
|
|
687
726
|
}
|
|
688
727
|
/**
|
|
689
728
|
* Deque peek at both ends
|
|
690
|
-
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+
|
|
732
|
+
* @example
|
|
691
733
|
* // Deque peek at both ends
|
|
692
734
|
* const deque = new Deque<number>([10, 20, 30, 40, 50]);
|
|
693
735
|
*
|
|
@@ -745,6 +787,9 @@ var dequeTyped = (() => {
|
|
|
745
787
|
|
|
746
788
|
|
|
747
789
|
|
|
790
|
+
|
|
791
|
+
|
|
792
|
+
|
|
748
793
|
|
|
749
794
|
|
|
750
795
|
|
|
@@ -812,6 +857,9 @@ var dequeTyped = (() => {
|
|
|
812
857
|
|
|
813
858
|
|
|
814
859
|
|
|
860
|
+
|
|
861
|
+
|
|
862
|
+
|
|
815
863
|
|
|
816
864
|
|
|
817
865
|
|
|
@@ -892,6 +940,9 @@ var dequeTyped = (() => {
|
|
|
892
940
|
|
|
893
941
|
|
|
894
942
|
|
|
943
|
+
|
|
944
|
+
|
|
945
|
+
|
|
895
946
|
|
|
896
947
|
|
|
897
948
|
|
|
@@ -959,6 +1010,9 @@ var dequeTyped = (() => {
|
|
|
959
1010
|
|
|
960
1011
|
|
|
961
1012
|
|
|
1013
|
+
|
|
1014
|
+
|
|
1015
|
+
|
|
962
1016
|
|
|
963
1017
|
|
|
964
1018
|
|
|
@@ -1027,6 +1081,9 @@ var dequeTyped = (() => {
|
|
|
1027
1081
|
|
|
1028
1082
|
|
|
1029
1083
|
|
|
1084
|
+
|
|
1085
|
+
|
|
1086
|
+
|
|
1030
1087
|
|
|
1031
1088
|
|
|
1032
1089
|
|
|
@@ -1136,6 +1193,9 @@ var dequeTyped = (() => {
|
|
|
1136
1193
|
|
|
1137
1194
|
|
|
1138
1195
|
|
|
1196
|
+
|
|
1197
|
+
|
|
1198
|
+
|
|
1139
1199
|
|
|
1140
1200
|
|
|
1141
1201
|
|
|
@@ -1185,6 +1245,9 @@ var dequeTyped = (() => {
|
|
|
1185
1245
|
|
|
1186
1246
|
|
|
1187
1247
|
|
|
1248
|
+
|
|
1249
|
+
|
|
1250
|
+
|
|
1188
1251
|
|
|
1189
1252
|
|
|
1190
1253
|
|
|
@@ -1238,6 +1301,9 @@ var dequeTyped = (() => {
|
|
|
1238
1301
|
|
|
1239
1302
|
|
|
1240
1303
|
|
|
1304
|
+
|
|
1305
|
+
|
|
1306
|
+
|
|
1241
1307
|
|
|
1242
1308
|
|
|
1243
1309
|
|
|
@@ -1442,6 +1508,9 @@ var dequeTyped = (() => {
|
|
|
1442
1508
|
|
|
1443
1509
|
|
|
1444
1510
|
|
|
1511
|
+
|
|
1512
|
+
|
|
1513
|
+
|
|
1445
1514
|
|
|
1446
1515
|
|
|
1447
1516
|
|
|
@@ -1536,6 +1605,64 @@ var dequeTyped = (() => {
|
|
|
1536
1605
|
|
|
1537
1606
|
|
|
1538
1607
|
|
|
1608
|
+
|
|
1609
|
+
* @example
|
|
1610
|
+
* // Deque for...of iteration and reverse
|
|
1611
|
+
* const deque = new Deque<string>(['A', 'B', 'C', 'D']);
|
|
1612
|
+
*
|
|
1613
|
+
* // Iterate forward
|
|
1614
|
+
* const forward: string[] = [];
|
|
1615
|
+
* for (const item of deque) {
|
|
1616
|
+
* forward.push(item);
|
|
1617
|
+
* }
|
|
1618
|
+
* console.log(forward); // ['A', 'B', 'C', 'D'];
|
|
1619
|
+
*
|
|
1620
|
+
* // Reverse the deque
|
|
1621
|
+
* deque.reverse();
|
|
1622
|
+
* const backward: string[] = [];
|
|
1623
|
+
* for (const item of deque) {
|
|
1624
|
+
* backward.push(item);
|
|
1625
|
+
* }
|
|
1626
|
+
* console.log(backward); // ['D', 'C', 'B', 'A'];
|
|
1627
|
+
*/
|
|
1628
|
+
/**
|
|
1629
|
+
* Find the last value matching a predicate (scans back-to-front).
|
|
1630
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
|
|
1631
|
+
* @param predicate - Function called with (value, index, deque).
|
|
1632
|
+
* @returns Matching value or undefined.
|
|
1633
|
+
* @example
|
|
1634
|
+
* // Find last matching value
|
|
1635
|
+
* const d = new Deque([1, 2, 3, 4, 5]);
|
|
1636
|
+
* console.log(d.findLast(v => v > 2)); // 5;
|
|
1637
|
+
* console.log(d.findLast(v => v % 2 === 0)); // 4;
|
|
1638
|
+
*/
|
|
1639
|
+
findLast(predicate) {
|
|
1640
|
+
for (let i = this.length - 1; i >= 0; i--) {
|
|
1641
|
+
const val = this.at(i);
|
|
1642
|
+
if (predicate(val, i, this)) return val;
|
|
1643
|
+
}
|
|
1644
|
+
return void 0;
|
|
1645
|
+
}
|
|
1646
|
+
/**
|
|
1647
|
+
* Find the index of the last value matching a predicate (scans back-to-front).
|
|
1648
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
|
|
1649
|
+
* @param predicate - Function called with (value, index, deque).
|
|
1650
|
+
* @returns Matching index, or -1 if not found.
|
|
1651
|
+
* @example
|
|
1652
|
+
* // Find last matching index
|
|
1653
|
+
* const d = new Deque([10, 20, 30, 20, 10]);
|
|
1654
|
+
* console.log(d.findLastIndex(v => v === 20)); // 3;
|
|
1655
|
+
* console.log(d.findLastIndex(v => v === 10)); // 4;
|
|
1656
|
+
*/
|
|
1657
|
+
findLastIndex(predicate) {
|
|
1658
|
+
for (let i = this.length - 1; i >= 0; i--) {
|
|
1659
|
+
if (predicate(this.at(i), i, this)) return i;
|
|
1660
|
+
}
|
|
1661
|
+
return -1;
|
|
1662
|
+
}
|
|
1663
|
+
/**
|
|
1664
|
+
* Deque for...of iteration and reverse
|
|
1665
|
+
|
|
1539
1666
|
|
|
1540
1667
|
* @example
|
|
1541
1668
|
* // Deque for...of iteration and reverse
|
|
@@ -1649,6 +1776,9 @@ var dequeTyped = (() => {
|
|
|
1649
1776
|
|
|
1650
1777
|
|
|
1651
1778
|
|
|
1779
|
+
|
|
1780
|
+
|
|
1781
|
+
|
|
1652
1782
|
|
|
1653
1783
|
|
|
1654
1784
|
|
|
@@ -1724,6 +1854,9 @@ var dequeTyped = (() => {
|
|
|
1724
1854
|
|
|
1725
1855
|
|
|
1726
1856
|
|
|
1857
|
+
|
|
1858
|
+
|
|
1859
|
+
|
|
1727
1860
|
|
|
1728
1861
|
|
|
1729
1862
|
|
|
@@ -1782,6 +1915,9 @@ var dequeTyped = (() => {
|
|
|
1782
1915
|
|
|
1783
1916
|
|
|
1784
1917
|
|
|
1918
|
+
|
|
1919
|
+
|
|
1920
|
+
|
|
1785
1921
|
|
|
1786
1922
|
|
|
1787
1923
|
|
|
@@ -1860,6 +1996,9 @@ var dequeTyped = (() => {
|
|
|
1860
1996
|
|
|
1861
1997
|
|
|
1862
1998
|
|
|
1999
|
+
|
|
2000
|
+
|
|
2001
|
+
|
|
1863
2002
|
|
|
1864
2003
|
|
|
1865
2004
|
|