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