graph-typed 2.2.5 → 2.2.6
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 +8 -34
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +8 -34
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +8 -34
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +8 -34
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/data-structures/base/iterable-entry-base.d.ts +6 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +14 -57
- package/dist/types/data-structures/binary-tree/bst.d.ts +46 -126
- package/dist/umd/graph-typed.js +8 -31
- package/dist/umd/graph-typed.js.map +1 -1
- package/dist/umd/graph-typed.min.js +1 -1
- package/dist/umd/graph-typed.min.js.map +1 -1
- package/package.json +2 -2
- package/src/common/index.ts +2 -4
- package/src/data-structures/base/iterable-entry-base.ts +9 -0
- package/src/data-structures/binary-tree/binary-tree.ts +67 -0
- package/src/data-structures/binary-tree/bst.ts +295 -89
|
@@ -23,38 +23,6 @@ var arrayRemove = /* @__PURE__ */ __name(function(array, predicate) {
|
|
|
23
23
|
}
|
|
24
24
|
return result;
|
|
25
25
|
}, "arrayRemove");
|
|
26
|
-
function isPrimitiveComparable(value) {
|
|
27
|
-
const valueType = typeof value;
|
|
28
|
-
if (valueType === "number") return true;
|
|
29
|
-
return valueType === "bigint" || valueType === "string" || valueType === "boolean";
|
|
30
|
-
}
|
|
31
|
-
__name(isPrimitiveComparable, "isPrimitiveComparable");
|
|
32
|
-
function tryObjectToPrimitive(obj) {
|
|
33
|
-
if (typeof obj.valueOf === "function") {
|
|
34
|
-
const valueOfResult = obj.valueOf();
|
|
35
|
-
if (valueOfResult !== obj) {
|
|
36
|
-
if (isPrimitiveComparable(valueOfResult)) return valueOfResult;
|
|
37
|
-
if (typeof valueOfResult === "object" && valueOfResult !== null) return tryObjectToPrimitive(valueOfResult);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
if (typeof obj.toString === "function") {
|
|
41
|
-
const stringResult = obj.toString();
|
|
42
|
-
if (stringResult !== "[object Object]") return stringResult;
|
|
43
|
-
}
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
__name(tryObjectToPrimitive, "tryObjectToPrimitive");
|
|
47
|
-
function isComparable(value, isForceObjectComparable = false) {
|
|
48
|
-
if (value === null || value === void 0) return false;
|
|
49
|
-
if (isPrimitiveComparable(value)) return true;
|
|
50
|
-
if (typeof value !== "object") return false;
|
|
51
|
-
if (value instanceof Date) return true;
|
|
52
|
-
if (isForceObjectComparable) return true;
|
|
53
|
-
const comparableValue = tryObjectToPrimitive(value);
|
|
54
|
-
if (comparableValue === null || comparableValue === void 0) return false;
|
|
55
|
-
return isPrimitiveComparable(comparableValue);
|
|
56
|
-
}
|
|
57
|
-
__name(isComparable, "isComparable");
|
|
58
26
|
|
|
59
27
|
// src/data-structures/base/iterable-entry-base.ts
|
|
60
28
|
var _IterableEntryBase = class _IterableEntryBase {
|
|
@@ -210,6 +178,14 @@ var _IterableEntryBase = class _IterableEntryBase {
|
|
|
210
178
|
}
|
|
211
179
|
return accumulator;
|
|
212
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* Converts data structure to `[key, value]` pairs.
|
|
183
|
+
* @returns Array of entries.
|
|
184
|
+
* @remarks Time O(n), Space O(n)
|
|
185
|
+
*/
|
|
186
|
+
toArray() {
|
|
187
|
+
return [...this];
|
|
188
|
+
}
|
|
213
189
|
/**
|
|
214
190
|
* Visualize the iterable as an array of `[key, value]` pairs (or a custom string).
|
|
215
191
|
* @returns Array of entries (default) or a string.
|
|
@@ -3248,8 +3224,6 @@ var _Range = class _Range {
|
|
|
3248
3224
|
this.high = high;
|
|
3249
3225
|
this.includeLow = includeLow;
|
|
3250
3226
|
this.includeHigh = includeHigh;
|
|
3251
|
-
if (!(isComparable(low) && isComparable(high))) throw new RangeError("low or high is not comparable");
|
|
3252
|
-
if (low > high) throw new RangeError("low must be less than or equal to high");
|
|
3253
3227
|
}
|
|
3254
3228
|
// Determine whether a key is within the range
|
|
3255
3229
|
isInRange(key, comparator) {
|