singly-linked-list-typed 2.5.1 → 2.5.2

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 (73) hide show
  1. package/dist/cjs/index.cjs +103 -51
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +102 -50
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +103 -52
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +102 -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 +36 -0
  12. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +42 -0
  13. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +77 -2
  14. package/dist/types/data-structures/binary-tree/bst.d.ts +171 -0
  15. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +57 -0
  16. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +18 -0
  17. package/dist/types/data-structures/binary-tree/tree-map.d.ts +409 -0
  18. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +411 -6
  19. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +339 -6
  20. package/dist/types/data-structures/binary-tree/tree-set.d.ts +391 -0
  21. package/dist/types/data-structures/graph/directed-graph.d.ts +30 -0
  22. package/dist/types/data-structures/graph/undirected-graph.d.ts +27 -0
  23. package/dist/types/data-structures/hash/hash-map.d.ts +33 -0
  24. package/dist/types/data-structures/heap/heap.d.ts +42 -0
  25. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +51 -0
  26. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +45 -0
  27. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +54 -0
  28. package/dist/types/data-structures/matrix/matrix.d.ts +24 -0
  29. package/dist/types/data-structures/queue/deque.d.ts +45 -0
  30. package/dist/types/data-structures/queue/queue.d.ts +36 -0
  31. package/dist/types/data-structures/stack/stack.d.ts +30 -0
  32. package/dist/types/data-structures/trie/trie.d.ts +36 -0
  33. package/dist/types/types/data-structures/binary-tree/bst.d.ts +1 -0
  34. package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
  35. package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
  36. package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
  37. package/dist/umd/singly-linked-list-typed.js +100 -49
  38. package/dist/umd/singly-linked-list-typed.js.map +1 -1
  39. package/dist/umd/singly-linked-list-typed.min.js +1 -1
  40. package/dist/umd/singly-linked-list-typed.min.js.map +1 -1
  41. package/package.json +2 -2
  42. package/src/common/error.ts +19 -1
  43. package/src/common/index.ts +1 -1
  44. package/src/data-structures/base/iterable-element-base.ts +3 -2
  45. package/src/data-structures/binary-tree/avl-tree.ts +47 -0
  46. package/src/data-structures/binary-tree/binary-indexed-tree.ts +46 -4
  47. package/src/data-structures/binary-tree/binary-tree.ts +79 -4
  48. package/src/data-structures/binary-tree/bst.ts +441 -6
  49. package/src/data-structures/binary-tree/red-black-tree.ts +73 -0
  50. package/src/data-structures/binary-tree/segment-tree.ts +18 -0
  51. package/src/data-structures/binary-tree/tree-map.ts +434 -9
  52. package/src/data-structures/binary-tree/tree-multi-map.ts +426 -5
  53. package/src/data-structures/binary-tree/tree-multi-set.ts +350 -6
  54. package/src/data-structures/binary-tree/tree-set.ts +410 -8
  55. package/src/data-structures/graph/abstract-graph.ts +2 -2
  56. package/src/data-structures/graph/directed-graph.ts +30 -0
  57. package/src/data-structures/graph/undirected-graph.ts +27 -0
  58. package/src/data-structures/hash/hash-map.ts +35 -4
  59. package/src/data-structures/heap/heap.ts +46 -4
  60. package/src/data-structures/heap/max-heap.ts +2 -2
  61. package/src/data-structures/linked-list/doubly-linked-list.ts +51 -0
  62. package/src/data-structures/linked-list/singly-linked-list.ts +45 -0
  63. package/src/data-structures/linked-list/skip-linked-list.ts +59 -5
  64. package/src/data-structures/matrix/matrix.ts +33 -9
  65. package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
  66. package/src/data-structures/queue/deque.ts +45 -0
  67. package/src/data-structures/queue/queue.ts +36 -0
  68. package/src/data-structures/stack/stack.ts +30 -0
  69. package/src/data-structures/trie/trie.ts +38 -2
  70. package/src/types/data-structures/binary-tree/bst.ts +1 -0
  71. package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
  72. package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
  73. package/src/types/data-structures/binary-tree/tree-set.ts +5 -0
@@ -3,6 +3,60 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
3
3
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
4
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
5
 
6
+ // src/common/error.ts
7
+ function raise(ErrorClass, message) {
8
+ throw new ErrorClass(message);
9
+ }
10
+ __name(raise, "raise");
11
+ var ERR = {
12
+ // Range / index
13
+ indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
14
+ invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
15
+ // Type / argument
16
+ invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
17
+ comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
18
+ invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
19
+ notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
20
+ invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
21
+ invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
22
+ invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
23
+ reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
24
+ callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
25
+ // State / operation
26
+ invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
27
+ // Matrix
28
+ matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
29
+ matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
30
+ matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
31
+ matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
32
+ matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch"),
33
+ // Order statistic
34
+ orderStatisticNotEnabled: /* @__PURE__ */ __name((method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`, "orderStatisticNotEnabled")
35
+ };
36
+
37
+ // src/common/index.ts
38
+ var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
39
+ DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
40
+ DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
41
+ return DFSOperation2;
42
+ })(DFSOperation || {});
43
+ var _Range = class _Range {
44
+ constructor(low, high, includeLow = true, includeHigh = true) {
45
+ this.low = low;
46
+ this.high = high;
47
+ this.includeLow = includeLow;
48
+ this.includeHigh = includeHigh;
49
+ }
50
+ // Determine whether a key is within the range
51
+ isInRange(key, comparator) {
52
+ const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
53
+ const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
54
+ return lowCheck && highCheck;
55
+ }
56
+ };
57
+ __name(_Range, "Range");
58
+ var Range = _Range;
59
+
6
60
  // src/data-structures/base/iterable-element-base.ts
7
61
  var _IterableElementBase = class _IterableElementBase {
8
62
  /**
@@ -25,7 +79,7 @@ var _IterableElementBase = class _IterableElementBase {
25
79
  if (options) {
26
80
  const { toElementFn } = options;
27
81
  if (typeof toElementFn === "function") this._toElementFn = toElementFn;
28
- else if (toElementFn) throw new TypeError("toElementFn must be a function type");
82
+ else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
29
83
  }
30
84
  }
31
85
  /**
@@ -181,7 +235,7 @@ var _IterableElementBase = class _IterableElementBase {
181
235
  acc = initialValue;
182
236
  } else {
183
237
  const first = iter.next();
184
- if (first.done) throw new TypeError("Reduce of empty structure with no initial value");
238
+ if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
185
239
  acc = first.value;
186
240
  index = 1;
187
241
  }
@@ -751,6 +805,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
751
805
 
752
806
 
753
807
 
808
+
809
+
810
+
754
811
 
755
812
 
756
813
 
@@ -815,6 +872,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
815
872
 
816
873
 
817
874
 
875
+
876
+
877
+
818
878
 
819
879
 
820
880
 
@@ -885,6 +945,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
885
945
 
886
946
 
887
947
 
948
+
949
+
950
+
888
951
 
889
952
 
890
953
 
@@ -936,6 +999,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
936
999
 
937
1000
 
938
1001
 
1002
+
1003
+
1004
+
939
1005
 
940
1006
 
941
1007
 
@@ -1048,6 +1114,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1048
1114
 
1049
1115
 
1050
1116
 
1117
+
1118
+
1119
+
1051
1120
 
1052
1121
 
1053
1122
 
@@ -1104,6 +1173,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1104
1173
 
1105
1174
 
1106
1175
 
1176
+
1177
+
1178
+
1107
1179
 
1108
1180
 
1109
1181
 
@@ -1149,6 +1221,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1149
1221
 
1150
1222
 
1151
1223
 
1224
+
1225
+
1226
+
1152
1227
 
1153
1228
 
1154
1229
 
@@ -1200,6 +1275,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1200
1275
 
1201
1276
 
1202
1277
 
1278
+
1279
+
1280
+
1203
1281
 
1204
1282
 
1205
1283
 
@@ -1256,6 +1334,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1256
1334
 
1257
1335
 
1258
1336
 
1337
+
1338
+
1339
+
1259
1340
 
1260
1341
 
1261
1342
 
@@ -1320,6 +1401,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1320
1401
 
1321
1402
 
1322
1403
 
1404
+
1405
+
1406
+
1323
1407
 
1324
1408
 
1325
1409
 
@@ -1361,6 +1445,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1361
1445
 
1362
1446
 
1363
1447
 
1448
+
1449
+
1450
+
1364
1451
 
1365
1452
 
1366
1453
 
@@ -1408,6 +1495,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1408
1495
 
1409
1496
 
1410
1497
 
1498
+
1499
+
1500
+
1411
1501
 
1412
1502
 
1413
1503
 
@@ -1621,6 +1711,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1621
1711
 
1622
1712
 
1623
1713
 
1714
+
1715
+
1716
+
1624
1717
 
1625
1718
 
1626
1719
 
@@ -1672,6 +1765,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1672
1765
 
1673
1766
 
1674
1767
 
1768
+
1769
+
1770
+
1675
1771
 
1676
1772
 
1677
1773
 
@@ -1751,6 +1847,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1751
1847
 
1752
1848
 
1753
1849
 
1850
+
1851
+
1852
+
1754
1853
 
1755
1854
 
1756
1855
 
@@ -1896,54 +1995,6 @@ function elementOrPredicate(input, equals) {
1896
1995
  return (node) => equals(node.value, value);
1897
1996
  }
1898
1997
  __name(elementOrPredicate, "elementOrPredicate");
1899
-
1900
- // src/common/error.ts
1901
- var ERR = {
1902
- // Range / index
1903
- indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
1904
- invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
1905
- // Type / argument
1906
- invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
1907
- comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
1908
- invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
1909
- notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
1910
- invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
1911
- invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
1912
- invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
1913
- reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
1914
- callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
1915
- // State / operation
1916
- invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
1917
- // Matrix
1918
- matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
1919
- matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
1920
- matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
1921
- matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
1922
- matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
1923
- };
1924
-
1925
- // src/common/index.ts
1926
- var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
1927
- DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
1928
- DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
1929
- return DFSOperation2;
1930
- })(DFSOperation || {});
1931
- var _Range = class _Range {
1932
- constructor(low, high, includeLow = true, includeHigh = true) {
1933
- this.low = low;
1934
- this.high = high;
1935
- this.includeLow = includeLow;
1936
- this.includeHigh = includeHigh;
1937
- }
1938
- // Determine whether a key is within the range
1939
- isInRange(key, comparator) {
1940
- const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
1941
- const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
1942
- return lowCheck && highCheck;
1943
- }
1944
- };
1945
- __name(_Range, "Range");
1946
- var Range = _Range;
1947
1998
  /**
1948
1999
  * data-structure-typed
1949
2000
  *
@@ -1952,6 +2003,6 @@ var Range = _Range;
1952
2003
  * @license MIT License
1953
2004
  */
1954
2005
 
1955
- export { DFSOperation, ERR, Range, SinglyLinkedList, SinglyLinkedListNode };
2006
+ export { DFSOperation, ERR, Range, SinglyLinkedList, SinglyLinkedListNode, raise };
1956
2007
  //# sourceMappingURL=index.mjs.map
1957
2008
  //# sourceMappingURL=index.mjs.map