data-structure-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.
Files changed (104) hide show
  1. package/.husky/pre-commit +3 -0
  2. package/CHANGELOG.md +1 -1
  3. package/MIGRATION.md +48 -0
  4. package/README.md +20 -2
  5. package/README_CN.md +20 -2
  6. package/SPECIFICATION.md +24 -0
  7. package/SPECIFICATION.zh-CN.md +24 -0
  8. package/dist/cjs/binary-tree.cjs +1897 -19
  9. package/dist/cjs/graph.cjs +174 -0
  10. package/dist/cjs/hash.cjs +33 -0
  11. package/dist/cjs/heap.cjs +71 -0
  12. package/dist/cjs/index.cjs +2383 -3
  13. package/dist/cjs/linked-list.cjs +224 -2
  14. package/dist/cjs/matrix.cjs +24 -0
  15. package/dist/cjs/priority-queue.cjs +71 -0
  16. package/dist/cjs/queue.cjs +221 -1
  17. package/dist/cjs/stack.cjs +59 -0
  18. package/dist/cjs/trie.cjs +62 -0
  19. package/dist/cjs-legacy/binary-tree.cjs +1897 -19
  20. package/dist/cjs-legacy/graph.cjs +174 -0
  21. package/dist/cjs-legacy/hash.cjs +33 -0
  22. package/dist/cjs-legacy/heap.cjs +71 -0
  23. package/dist/cjs-legacy/index.cjs +2383 -3
  24. package/dist/cjs-legacy/linked-list.cjs +224 -2
  25. package/dist/cjs-legacy/matrix.cjs +24 -0
  26. package/dist/cjs-legacy/priority-queue.cjs +71 -0
  27. package/dist/cjs-legacy/queue.cjs +221 -1
  28. package/dist/cjs-legacy/stack.cjs +59 -0
  29. package/dist/cjs-legacy/trie.cjs +62 -0
  30. package/dist/esm/binary-tree.mjs +1897 -19
  31. package/dist/esm/graph.mjs +174 -0
  32. package/dist/esm/hash.mjs +33 -0
  33. package/dist/esm/heap.mjs +71 -0
  34. package/dist/esm/index.mjs +2383 -3
  35. package/dist/esm/linked-list.mjs +224 -2
  36. package/dist/esm/matrix.mjs +24 -0
  37. package/dist/esm/priority-queue.mjs +71 -0
  38. package/dist/esm/queue.mjs +221 -1
  39. package/dist/esm/stack.mjs +59 -0
  40. package/dist/esm/trie.mjs +62 -0
  41. package/dist/esm-legacy/binary-tree.mjs +1897 -19
  42. package/dist/esm-legacy/graph.mjs +174 -0
  43. package/dist/esm-legacy/hash.mjs +33 -0
  44. package/dist/esm-legacy/heap.mjs +71 -0
  45. package/dist/esm-legacy/index.mjs +2383 -3
  46. package/dist/esm-legacy/linked-list.mjs +224 -2
  47. package/dist/esm-legacy/matrix.mjs +24 -0
  48. package/dist/esm-legacy/priority-queue.mjs +71 -0
  49. package/dist/esm-legacy/queue.mjs +221 -1
  50. package/dist/esm-legacy/stack.mjs +59 -0
  51. package/dist/esm-legacy/trie.mjs +62 -0
  52. package/dist/types/data-structures/base/iterable-element-base.d.ts +17 -0
  53. package/dist/types/data-structures/base/linear-base.d.ts +6 -0
  54. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +36 -0
  55. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +42 -0
  56. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +75 -0
  57. package/dist/types/data-structures/binary-tree/bst.d.ts +72 -0
  58. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +57 -0
  59. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +18 -0
  60. package/dist/types/data-structures/binary-tree/tree-map.d.ts +375 -0
  61. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +389 -0
  62. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +330 -0
  63. package/dist/types/data-structures/binary-tree/tree-set.d.ts +438 -0
  64. package/dist/types/data-structures/graph/directed-graph.d.ts +30 -0
  65. package/dist/types/data-structures/graph/undirected-graph.d.ts +27 -0
  66. package/dist/types/data-structures/hash/hash-map.d.ts +33 -0
  67. package/dist/types/data-structures/heap/heap.d.ts +42 -0
  68. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +75 -2
  69. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +45 -0
  70. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +54 -0
  71. package/dist/types/data-structures/matrix/matrix.d.ts +24 -0
  72. package/dist/types/data-structures/queue/deque.d.ts +90 -1
  73. package/dist/types/data-structures/queue/queue.d.ts +36 -0
  74. package/dist/types/data-structures/stack/stack.d.ts +30 -0
  75. package/dist/types/data-structures/trie/trie.d.ts +36 -0
  76. package/dist/umd/data-structure-typed.js +2383 -3
  77. package/dist/umd/data-structure-typed.min.js +3 -3
  78. package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +14 -10
  79. package/jest.integration.config.js +1 -2
  80. package/package.json +9 -7
  81. package/src/data-structures/base/iterable-element-base.ts +32 -0
  82. package/src/data-structures/base/linear-base.ts +11 -0
  83. package/src/data-structures/binary-tree/avl-tree.ts +36 -0
  84. package/src/data-structures/binary-tree/binary-indexed-tree.ts +42 -0
  85. package/src/data-structures/binary-tree/binary-tree.ts +75 -0
  86. package/src/data-structures/binary-tree/bst.ts +72 -0
  87. package/src/data-structures/binary-tree/red-black-tree.ts +57 -0
  88. package/src/data-structures/binary-tree/segment-tree.ts +18 -0
  89. package/src/data-structures/binary-tree/tree-map.ts +375 -0
  90. package/src/data-structures/binary-tree/tree-multi-map.ts +392 -0
  91. package/src/data-structures/binary-tree/tree-multi-set.ts +336 -0
  92. package/src/data-structures/binary-tree/tree-set.ts +492 -0
  93. package/src/data-structures/graph/directed-graph.ts +30 -0
  94. package/src/data-structures/graph/undirected-graph.ts +27 -0
  95. package/src/data-structures/hash/hash-map.ts +33 -0
  96. package/src/data-structures/heap/heap.ts +42 -0
  97. package/src/data-structures/linked-list/doubly-linked-list.ts +90 -2
  98. package/src/data-structures/linked-list/singly-linked-list.ts +45 -0
  99. package/src/data-structures/linked-list/skip-linked-list.ts +54 -0
  100. package/src/data-structures/matrix/matrix.ts +24 -0
  101. package/src/data-structures/queue/deque.ts +103 -1
  102. package/src/data-structures/queue/queue.ts +36 -0
  103. package/src/data-structures/stack/stack.ts +30 -0
  104. package/src/data-structures/trie/trie.ts +36 -0
@@ -161,6 +161,35 @@ var IterableElementBase = class {
161
161
  for (const ele of this) if (ele === element) return true;
162
162
  return false;
163
163
  }
164
+ /**
165
+ * Check whether a value exists (Array-compatible alias for `has`).
166
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
167
+ * @param element - Element to search for (uses `===`).
168
+ * @returns `true` if found.
169
+ */
170
+ includes(element) {
171
+ return this.has(element);
172
+ }
173
+ /**
174
+ * Return an iterator of `[index, value]` pairs (Array-compatible).
175
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
176
+ */
177
+ *entries() {
178
+ let index = 0;
179
+ for (const value of this) {
180
+ yield [index++, value];
181
+ }
182
+ }
183
+ /**
184
+ * Return an iterator of numeric indices (Array-compatible).
185
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
186
+ */
187
+ *keys() {
188
+ let index = 0;
189
+ for (const _ of this) {
190
+ yield index++;
191
+ }
192
+ }
164
193
  /**
165
194
  * Reduces all elements to a single accumulated value.
166
195
  *
@@ -295,6 +324,9 @@ var Stack = class extends IterableElementBase {
295
324
 
296
325
 
297
326
 
327
+
328
+
329
+
298
330
 
299
331
 
300
332
 
@@ -359,6 +391,9 @@ var Stack = class extends IterableElementBase {
359
391
 
360
392
 
361
393
 
394
+
395
+
396
+
362
397
 
363
398
 
364
399
 
@@ -412,6 +447,9 @@ var Stack = class extends IterableElementBase {
412
447
 
413
448
 
414
449
 
450
+
451
+
452
+
415
453
 
416
454
 
417
455
 
@@ -465,6 +503,9 @@ var Stack = class extends IterableElementBase {
465
503
 
466
504
 
467
505
 
506
+
507
+
508
+
468
509
 
469
510
 
470
511
 
@@ -527,6 +568,9 @@ var Stack = class extends IterableElementBase {
527
568
 
528
569
 
529
570
 
571
+
572
+
573
+
530
574
 
531
575
 
532
576
 
@@ -604,6 +648,9 @@ var Stack = class extends IterableElementBase {
604
648
 
605
649
 
606
650
 
651
+
652
+
653
+
607
654
 
608
655
 
609
656
 
@@ -681,6 +728,9 @@ var Stack = class extends IterableElementBase {
681
728
 
682
729
 
683
730
 
731
+
732
+
733
+
684
734
 
685
735
 
686
736
 
@@ -731,6 +781,9 @@ var Stack = class extends IterableElementBase {
731
781
 
732
782
 
733
783
 
784
+
785
+
786
+
734
787
 
735
788
 
736
789
 
@@ -787,6 +840,9 @@ var Stack = class extends IterableElementBase {
787
840
 
788
841
 
789
842
 
843
+
844
+
845
+
790
846
 
791
847
 
792
848
 
@@ -863,6 +919,9 @@ var Stack = class extends IterableElementBase {
863
919
 
864
920
 
865
921
 
922
+
923
+
924
+
866
925
 
867
926
 
868
927
 
package/dist/cjs/trie.cjs CHANGED
@@ -186,6 +186,35 @@ var IterableElementBase = class {
186
186
  for (const ele of this) if (ele === element) return true;
187
187
  return false;
188
188
  }
189
+ /**
190
+ * Check whether a value exists (Array-compatible alias for `has`).
191
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
192
+ * @param element - Element to search for (uses `===`).
193
+ * @returns `true` if found.
194
+ */
195
+ includes(element) {
196
+ return this.has(element);
197
+ }
198
+ /**
199
+ * Return an iterator of `[index, value]` pairs (Array-compatible).
200
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
201
+ */
202
+ *entries() {
203
+ let index = 0;
204
+ for (const value of this) {
205
+ yield [index++, value];
206
+ }
207
+ }
208
+ /**
209
+ * Return an iterator of numeric indices (Array-compatible).
210
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
211
+ */
212
+ *keys() {
213
+ let index = 0;
214
+ for (const _ of this) {
215
+ yield index++;
216
+ }
217
+ }
189
218
  /**
190
219
  * Reduces all elements to a single accumulated value.
191
220
  *
@@ -423,6 +452,9 @@ var Trie = class extends IterableElementBase {
423
452
 
424
453
 
425
454
 
455
+
456
+
457
+
426
458
 
427
459
 
428
460
 
@@ -499,6 +531,9 @@ var Trie = class extends IterableElementBase {
499
531
 
500
532
 
501
533
 
534
+
535
+
536
+
502
537
 
503
538
 
504
539
 
@@ -562,6 +597,9 @@ var Trie = class extends IterableElementBase {
562
597
 
563
598
 
564
599
 
600
+
601
+
602
+
565
603
 
566
604
 
567
605
 
@@ -620,6 +658,9 @@ var Trie = class extends IterableElementBase {
620
658
 
621
659
 
622
660
 
661
+
662
+
663
+
623
664
 
624
665
 
625
666
 
@@ -670,6 +711,9 @@ var Trie = class extends IterableElementBase {
670
711
 
671
712
 
672
713
 
714
+
715
+
716
+
673
717
 
674
718
 
675
719
 
@@ -724,6 +768,9 @@ var Trie = class extends IterableElementBase {
724
768
 
725
769
 
726
770
 
771
+
772
+
773
+
727
774
 
728
775
 
729
776
 
@@ -860,6 +907,9 @@ var Trie = class extends IterableElementBase {
860
907
 
861
908
 
862
909
 
910
+
911
+
912
+
863
913
 
864
914
 
865
915
 
@@ -940,6 +990,9 @@ var Trie = class extends IterableElementBase {
940
990
 
941
991
 
942
992
 
993
+
994
+
995
+
943
996
 
944
997
 
945
998
 
@@ -1003,6 +1056,9 @@ var Trie = class extends IterableElementBase {
1003
1056
 
1004
1057
 
1005
1058
 
1059
+
1060
+
1061
+
1006
1062
 
1007
1063
 
1008
1064
 
@@ -1084,6 +1140,9 @@ var Trie = class extends IterableElementBase {
1084
1140
 
1085
1141
 
1086
1142
 
1143
+
1144
+
1145
+
1087
1146
 
1088
1147
 
1089
1148
 
@@ -1138,6 +1197,9 @@ var Trie = class extends IterableElementBase {
1138
1197
 
1139
1198
 
1140
1199
 
1200
+
1201
+
1202
+
1141
1203
 
1142
1204
 
1143
1205