linked-list-typed 2.4.4 → 2.4.5

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 (45) hide show
  1. package/dist/cjs/index.cjs +52 -26
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +51 -25
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +52 -27
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +51 -26
  8. package/dist/esm-legacy/index.mjs.map +1 -1
  9. package/dist/types/common/error.d.ts +23 -0
  10. package/dist/types/common/index.d.ts +1 -0
  11. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +10 -0
  12. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +7 -1
  13. package/dist/types/data-structures/graph/abstract-graph.d.ts +44 -0
  14. package/dist/types/data-structures/graph/directed-graph.d.ts +1 -0
  15. package/dist/types/data-structures/graph/undirected-graph.d.ts +14 -0
  16. package/dist/types/data-structures/queue/deque.d.ts +41 -1
  17. package/dist/types/types/data-structures/queue/deque.d.ts +6 -0
  18. package/dist/umd/linked-list-typed.js +49 -23
  19. package/dist/umd/linked-list-typed.js.map +1 -1
  20. package/dist/umd/linked-list-typed.min.js +1 -1
  21. package/dist/umd/linked-list-typed.min.js.map +1 -1
  22. package/package.json +2 -2
  23. package/src/common/error.ts +60 -0
  24. package/src/common/index.ts +2 -0
  25. package/src/data-structures/base/iterable-element-base.ts +3 -2
  26. package/src/data-structures/binary-tree/binary-indexed-tree.ts +6 -5
  27. package/src/data-structures/binary-tree/binary-tree.ts +113 -42
  28. package/src/data-structures/binary-tree/bst.ts +11 -3
  29. package/src/data-structures/binary-tree/red-black-tree.ts +20 -0
  30. package/src/data-structures/binary-tree/tree-map.ts +8 -7
  31. package/src/data-structures/binary-tree/tree-multi-map.ts +4 -4
  32. package/src/data-structures/binary-tree/tree-multi-set.ts +5 -4
  33. package/src/data-structures/binary-tree/tree-set.ts +7 -6
  34. package/src/data-structures/graph/abstract-graph.ts +106 -1
  35. package/src/data-structures/graph/directed-graph.ts +4 -0
  36. package/src/data-structures/graph/undirected-graph.ts +95 -0
  37. package/src/data-structures/hash/hash-map.ts +13 -2
  38. package/src/data-structures/heap/heap.ts +4 -3
  39. package/src/data-structures/heap/max-heap.ts +2 -3
  40. package/src/data-structures/matrix/matrix.ts +9 -10
  41. package/src/data-structures/priority-queue/max-priority-queue.ts +2 -3
  42. package/src/data-structures/queue/deque.ts +71 -3
  43. package/src/data-structures/trie/trie.ts +2 -1
  44. package/src/types/data-structures/queue/deque.ts +7 -0
  45. package/src/utils/utils.ts +4 -2
@@ -3,6 +3,55 @@
3
3
  var __defProp = Object.defineProperty;
4
4
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
5
 
6
+ // src/common/error.ts
7
+ var ERR = {
8
+ // Range / index
9
+ indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
10
+ invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
11
+ // Type / argument
12
+ invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
13
+ comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
14
+ invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
15
+ notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
16
+ invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
17
+ invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
18
+ invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
19
+ reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
20
+ callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
21
+ // State / operation
22
+ invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
23
+ // Matrix
24
+ matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
25
+ matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
26
+ matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
27
+ matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
28
+ matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
29
+ };
30
+
31
+ // src/common/index.ts
32
+ var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
33
+ DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
34
+ DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
35
+ return DFSOperation2;
36
+ })(DFSOperation || {});
37
+ var Range = class {
38
+ constructor(low, high, includeLow = true, includeHigh = true) {
39
+ this.low = low;
40
+ this.high = high;
41
+ this.includeLow = includeLow;
42
+ this.includeHigh = includeHigh;
43
+ }
44
+ static {
45
+ __name(this, "Range");
46
+ }
47
+ // Determine whether a key is within the range
48
+ isInRange(key, comparator) {
49
+ const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
50
+ const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
51
+ return lowCheck && highCheck;
52
+ }
53
+ };
54
+
6
55
  // src/data-structures/base/iterable-element-base.ts
7
56
  var IterableElementBase = class {
8
57
  static {
@@ -21,7 +70,7 @@ var IterableElementBase = class {
21
70
  if (options) {
22
71
  const { toElementFn } = options;
23
72
  if (typeof toElementFn === "function") this._toElementFn = toElementFn;
24
- else if (toElementFn) throw new TypeError("toElementFn must be a function type");
73
+ else if (toElementFn) throw new TypeError(ERR.notAFunction("toElementFn"));
25
74
  }
26
75
  }
27
76
  /**
@@ -184,7 +233,7 @@ var IterableElementBase = class {
184
233
  acc = initialValue;
185
234
  } else {
186
235
  const first = iter.next();
187
- if (first.done) throw new TypeError("Reduce of empty structure with no initial value");
236
+ if (first.done) throw new TypeError(ERR.reduceEmpty());
188
237
  acc = first.value;
189
238
  index = 1;
190
239
  }
@@ -2083,30 +2132,6 @@ var SkipList = class {
2083
2132
  return level;
2084
2133
  }
2085
2134
  };
2086
-
2087
- // src/common/index.ts
2088
- var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
2089
- DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
2090
- DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
2091
- return DFSOperation2;
2092
- })(DFSOperation || {});
2093
- var Range = class {
2094
- constructor(low, high, includeLow = true, includeHigh = true) {
2095
- this.low = low;
2096
- this.high = high;
2097
- this.includeLow = includeLow;
2098
- this.includeHigh = includeHigh;
2099
- }
2100
- static {
2101
- __name(this, "Range");
2102
- }
2103
- // Determine whether a key is within the range
2104
- isInRange(key, comparator) {
2105
- const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
2106
- const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
2107
- return lowCheck && highCheck;
2108
- }
2109
- };
2110
2135
  /**
2111
2136
  * data-structure-typed
2112
2137
  *
@@ -2118,6 +2143,7 @@ var Range = class {
2118
2143
  exports.DFSOperation = DFSOperation;
2119
2144
  exports.DoublyLinkedList = DoublyLinkedList;
2120
2145
  exports.DoublyLinkedListNode = DoublyLinkedListNode;
2146
+ exports.ERR = ERR;
2121
2147
  exports.Range = Range;
2122
2148
  exports.SinglyLinkedList = SinglyLinkedList;
2123
2149
  exports.SinglyLinkedListNode = SinglyLinkedListNode;