singly-linked-list-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.
Files changed (75) hide show
  1. package/dist/cjs/index.cjs +163 -51
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +162 -50
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +163 -52
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +162 -51
  8. package/dist/esm-legacy/index.mjs.map +1 -1
  9. package/dist/types/common/error.d.ts +9 -0
  10. package/dist/types/common/index.d.ts +1 -1
  11. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +86 -2
  12. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +98 -0
  13. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +189 -13
  14. package/dist/types/data-structures/binary-tree/bst.d.ts +270 -3
  15. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +136 -8
  16. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +42 -0
  17. package/dist/types/data-structures/binary-tree/tree-map.d.ts +1089 -161
  18. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1243 -350
  19. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +980 -255
  20. package/dist/types/data-structures/binary-tree/tree-set.d.ts +1174 -284
  21. package/dist/types/data-structures/graph/directed-graph.d.ts +70 -0
  22. package/dist/types/data-structures/graph/undirected-graph.d.ts +63 -0
  23. package/dist/types/data-structures/hash/hash-map.d.ts +84 -6
  24. package/dist/types/data-structures/heap/heap.d.ts +140 -12
  25. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +126 -0
  26. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +106 -1
  27. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +126 -0
  28. package/dist/types/data-structures/matrix/matrix.d.ts +56 -0
  29. package/dist/types/data-structures/queue/deque.d.ts +127 -0
  30. package/dist/types/data-structures/queue/queue.d.ts +97 -0
  31. package/dist/types/data-structures/stack/stack.d.ts +72 -2
  32. package/dist/types/data-structures/trie/trie.d.ts +84 -0
  33. package/dist/types/interfaces/binary-tree.d.ts +2 -3
  34. package/dist/types/types/data-structures/binary-tree/bst.d.ts +1 -0
  35. package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
  36. package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
  37. package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
  38. package/dist/umd/singly-linked-list-typed.js +160 -49
  39. package/dist/umd/singly-linked-list-typed.js.map +1 -1
  40. package/dist/umd/singly-linked-list-typed.min.js +1 -1
  41. package/dist/umd/singly-linked-list-typed.min.js.map +1 -1
  42. package/package.json +2 -2
  43. package/src/common/error.ts +19 -1
  44. package/src/common/index.ts +1 -1
  45. package/src/data-structures/base/iterable-element-base.ts +3 -2
  46. package/src/data-structures/binary-tree/avl-tree.ts +99 -5
  47. package/src/data-structures/binary-tree/binary-indexed-tree.ts +102 -4
  48. package/src/data-structures/binary-tree/binary-tree.ts +239 -78
  49. package/src/data-structures/binary-tree/bst.ts +542 -13
  50. package/src/data-structures/binary-tree/red-black-tree.ts +155 -15
  51. package/src/data-structures/binary-tree/segment-tree.ts +42 -0
  52. package/src/data-structures/binary-tree/tree-map.ts +1223 -261
  53. package/src/data-structures/binary-tree/tree-multi-map.ts +939 -30
  54. package/src/data-structures/binary-tree/tree-multi-set.ts +746 -10
  55. package/src/data-structures/binary-tree/tree-set.ts +1018 -99
  56. package/src/data-structures/graph/abstract-graph.ts +2 -2
  57. package/src/data-structures/graph/directed-graph.ts +71 -1
  58. package/src/data-structures/graph/undirected-graph.ts +64 -1
  59. package/src/data-structures/hash/hash-map.ts +102 -16
  60. package/src/data-structures/heap/heap.ts +153 -23
  61. package/src/data-structures/heap/max-heap.ts +2 -2
  62. package/src/data-structures/linked-list/doubly-linked-list.ts +139 -0
  63. package/src/data-structures/linked-list/singly-linked-list.ts +106 -1
  64. package/src/data-structures/linked-list/skip-linked-list.ts +131 -5
  65. package/src/data-structures/matrix/matrix.ts +65 -9
  66. package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
  67. package/src/data-structures/queue/deque.ts +130 -0
  68. package/src/data-structures/queue/queue.ts +109 -0
  69. package/src/data-structures/stack/stack.ts +75 -5
  70. package/src/data-structures/trie/trie.ts +86 -2
  71. package/src/interfaces/binary-tree.ts +1 -9
  72. package/src/types/data-structures/binary-tree/bst.ts +1 -0
  73. package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
  74. package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
  75. package/src/types/data-structures/binary-tree/tree-set.ts +5 -0
@@ -1,6 +1,61 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
 
4
+ // src/common/error.ts
5
+ function raise(ErrorClass, message) {
6
+ throw new ErrorClass(message);
7
+ }
8
+ __name(raise, "raise");
9
+ var ERR = {
10
+ // Range / index
11
+ indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
12
+ invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
13
+ // Type / argument
14
+ invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
15
+ comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
16
+ invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
17
+ notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
18
+ invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
19
+ invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
20
+ invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
21
+ reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
22
+ callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
23
+ // State / operation
24
+ invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
25
+ // Matrix
26
+ matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
27
+ matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
28
+ matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
29
+ matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
30
+ matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch"),
31
+ // Order statistic
32
+ orderStatisticNotEnabled: /* @__PURE__ */ __name((method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`, "orderStatisticNotEnabled")
33
+ };
34
+
35
+ // src/common/index.ts
36
+ var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
37
+ DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
38
+ DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
39
+ return DFSOperation2;
40
+ })(DFSOperation || {});
41
+ var Range = class {
42
+ constructor(low, high, includeLow = true, includeHigh = true) {
43
+ this.low = low;
44
+ this.high = high;
45
+ this.includeLow = includeLow;
46
+ this.includeHigh = includeHigh;
47
+ }
48
+ static {
49
+ __name(this, "Range");
50
+ }
51
+ // Determine whether a key is within the range
52
+ isInRange(key, comparator) {
53
+ const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
54
+ const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
55
+ return lowCheck && highCheck;
56
+ }
57
+ };
58
+
4
59
  // src/data-structures/base/iterable-element-base.ts
5
60
  var IterableElementBase = class {
6
61
  static {
@@ -19,7 +74,7 @@ var IterableElementBase = class {
19
74
  if (options) {
20
75
  const { toElementFn } = options;
21
76
  if (typeof toElementFn === "function") this._toElementFn = toElementFn;
22
- else if (toElementFn) throw new TypeError("toElementFn must be a function type");
77
+ else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
23
78
  }
24
79
  }
25
80
  /**
@@ -182,7 +237,7 @@ var IterableElementBase = class {
182
237
  acc = initialValue;
183
238
  } else {
184
239
  const first = iter.next();
185
- if (first.done) throw new TypeError("Reduce of empty structure with no initial value");
240
+ if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
186
241
  acc = first.value;
187
242
  index = 1;
188
243
  }
@@ -751,6 +806,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
751
806
 
752
807
 
753
808
 
809
+
810
+
811
+
812
+
813
+
814
+
815
+
754
816
 
755
817
 
756
818
 
@@ -815,6 +877,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
815
877
 
816
878
 
817
879
 
880
+
881
+
882
+
883
+
884
+
885
+
886
+
818
887
 
819
888
 
820
889
 
@@ -884,6 +953,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
884
953
 
885
954
 
886
955
 
956
+
957
+
958
+
959
+
960
+
961
+
962
+
887
963
 
888
964
 
889
965
 
@@ -935,6 +1011,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
935
1011
 
936
1012
 
937
1013
 
1014
+
1015
+
1016
+
1017
+
1018
+
1019
+
1020
+
938
1021
 
939
1022
 
940
1023
 
@@ -1047,6 +1130,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1047
1130
 
1048
1131
 
1049
1132
 
1133
+
1134
+
1135
+
1136
+
1137
+
1138
+
1139
+
1050
1140
 
1051
1141
 
1052
1142
 
@@ -1103,6 +1193,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1103
1193
 
1104
1194
 
1105
1195
 
1196
+
1197
+
1198
+
1199
+
1200
+
1201
+
1202
+
1106
1203
 
1107
1204
 
1108
1205
 
@@ -1148,6 +1245,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1148
1245
 
1149
1246
 
1150
1247
 
1248
+
1249
+
1250
+
1251
+
1252
+
1253
+
1254
+
1151
1255
 
1152
1256
 
1153
1257
 
@@ -1199,6 +1303,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1199
1303
 
1200
1304
 
1201
1305
 
1306
+
1307
+
1308
+
1309
+
1310
+
1311
+
1312
+
1202
1313
 
1203
1314
 
1204
1315
 
@@ -1255,6 +1366,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1255
1366
 
1256
1367
 
1257
1368
 
1369
+
1370
+
1371
+
1372
+
1373
+
1374
+
1375
+
1258
1376
 
1259
1377
 
1260
1378
 
@@ -1319,6 +1437,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1319
1437
 
1320
1438
 
1321
1439
 
1440
+
1441
+
1442
+
1443
+
1444
+
1445
+
1446
+
1322
1447
 
1323
1448
 
1324
1449
 
@@ -1360,6 +1485,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1360
1485
 
1361
1486
 
1362
1487
 
1488
+
1489
+
1490
+
1491
+
1492
+
1493
+
1494
+
1363
1495
 
1364
1496
 
1365
1497
 
@@ -1407,6 +1539,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1407
1539
 
1408
1540
 
1409
1541
 
1542
+
1543
+
1544
+
1545
+
1546
+
1547
+
1548
+
1410
1549
 
1411
1550
 
1412
1551
 
@@ -1620,6 +1759,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1620
1759
 
1621
1760
 
1622
1761
 
1762
+
1763
+
1764
+
1765
+
1766
+
1767
+
1768
+
1623
1769
 
1624
1770
 
1625
1771
 
@@ -1671,6 +1817,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1671
1817
 
1672
1818
 
1673
1819
 
1820
+
1821
+
1822
+
1823
+
1824
+
1825
+
1826
+
1674
1827
 
1675
1828
 
1676
1829
 
@@ -1750,6 +1903,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1750
1903
 
1751
1904
 
1752
1905
 
1906
+
1907
+
1908
+
1909
+
1910
+
1911
+
1912
+
1753
1913
 
1754
1914
 
1755
1915
 
@@ -1897,55 +2057,6 @@ function elementOrPredicate(input, equals) {
1897
2057
  return (node) => equals(node.value, value);
1898
2058
  }
1899
2059
  __name(elementOrPredicate, "elementOrPredicate");
1900
-
1901
- // src/common/error.ts
1902
- var ERR = {
1903
- // Range / index
1904
- indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
1905
- invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
1906
- // Type / argument
1907
- invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
1908
- comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
1909
- invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
1910
- notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
1911
- invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
1912
- invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
1913
- invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
1914
- reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
1915
- callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
1916
- // State / operation
1917
- invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
1918
- // Matrix
1919
- matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
1920
- matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
1921
- matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
1922
- matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
1923
- matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
1924
- };
1925
-
1926
- // src/common/index.ts
1927
- var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
1928
- DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
1929
- DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
1930
- return DFSOperation2;
1931
- })(DFSOperation || {});
1932
- var Range = class {
1933
- constructor(low, high, includeLow = true, includeHigh = true) {
1934
- this.low = low;
1935
- this.high = high;
1936
- this.includeLow = includeLow;
1937
- this.includeHigh = includeHigh;
1938
- }
1939
- static {
1940
- __name(this, "Range");
1941
- }
1942
- // Determine whether a key is within the range
1943
- isInRange(key, comparator) {
1944
- const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
1945
- const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
1946
- return lowCheck && highCheck;
1947
- }
1948
- };
1949
2060
  /**
1950
2061
  * data-structure-typed
1951
2062
  *
@@ -1954,6 +2065,6 @@ var Range = class {
1954
2065
  * @license MIT License
1955
2066
  */
1956
2067
 
1957
- export { DFSOperation, ERR, Range, SinglyLinkedList, SinglyLinkedListNode };
2068
+ export { DFSOperation, ERR, Range, SinglyLinkedList, SinglyLinkedListNode, raise };
1958
2069
  //# sourceMappingURL=index.mjs.map
1959
2070
  //# sourceMappingURL=index.mjs.map