binary-tree-typed 2.4.3 → 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 +153 -71
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +151 -69
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +153 -72
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +151 -70
- 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/base/iterable-element-base.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +15 -5
- package/dist/types/data-structures/binary-tree/bst.d.ts +1 -1
- 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 +3 -2
- package/dist/types/data-structures/graph/undirected-graph.d.ts +16 -2
- package/dist/types/data-structures/hash/hash-map.d.ts +2 -2
- package/dist/types/data-structures/heap/heap.d.ts +3 -7
- package/dist/types/data-structures/queue/deque.d.ts +41 -1
- package/dist/types/types/data-structures/binary-tree/avl-tree.d.ts +1 -1
- package/dist/types/types/data-structures/binary-tree/red-black-tree.d.ts +1 -1
- package/dist/types/types/data-structures/linked-list/doubly-linked-list.d.ts +1 -1
- package/dist/types/types/data-structures/linked-list/singly-linked-list.d.ts +1 -1
- package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/types/types/data-structures/queue/deque.d.ts +6 -0
- package/dist/types/types/data-structures/stack/stack.d.ts +1 -1
- package/dist/umd/binary-tree-typed.js +150 -68
- package/dist/umd/binary-tree-typed.js.map +1 -1
- package/dist/umd/binary-tree-typed.min.js +3 -3
- package/dist/umd/binary-tree-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 +5 -4
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +6 -5
- package/src/data-structures/binary-tree/binary-tree.ts +121 -49
- package/src/data-structures/binary-tree/bst.ts +12 -4
- 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 +10 -9
- package/src/data-structures/binary-tree/tree-set.ts +7 -6
- package/src/data-structures/graph/abstract-graph.ts +124 -19
- package/src/data-structures/graph/directed-graph.ts +8 -4
- package/src/data-structures/graph/map-graph.ts +1 -1
- package/src/data-structures/graph/undirected-graph.ts +99 -4
- package/src/data-structures/hash/hash-map.ts +19 -6
- package/src/data-structures/heap/heap.ts +21 -17
- package/src/data-structures/heap/max-heap.ts +2 -3
- package/src/data-structures/linked-list/doubly-linked-list.ts +4 -4
- package/src/data-structures/linked-list/singly-linked-list.ts +15 -9
- 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 +72 -4
- package/src/data-structures/stack/stack.ts +1 -1
- package/src/data-structures/trie/trie.ts +12 -6
- package/src/types/data-structures/binary-tree/avl-tree.ts +1 -1
- package/src/types/data-structures/binary-tree/red-black-tree.ts +1 -1
- package/src/types/data-structures/linked-list/doubly-linked-list.ts +1 -1
- package/src/types/data-structures/linked-list/singly-linked-list.ts +1 -1
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -1
- package/src/types/data-structures/queue/deque.ts +7 -0
- package/src/types/data-structures/stack/stack.ts +1 -1
- package/src/utils/utils.ts +4 -2
|
@@ -61,6 +61,54 @@ function makeTrampoline(fn) {
|
|
|
61
61
|
}
|
|
62
62
|
__name(makeTrampoline, "makeTrampoline");
|
|
63
63
|
|
|
64
|
+
// src/common/error.ts
|
|
65
|
+
var ERR = {
|
|
66
|
+
// Range / index
|
|
67
|
+
indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
|
|
68
|
+
invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
|
|
69
|
+
// Type / argument
|
|
70
|
+
invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
|
|
71
|
+
comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
|
|
72
|
+
invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
|
|
73
|
+
notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
|
|
74
|
+
invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
|
|
75
|
+
invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
|
|
76
|
+
invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
|
|
77
|
+
reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
|
|
78
|
+
callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
|
|
79
|
+
// State / operation
|
|
80
|
+
invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
|
|
81
|
+
// Matrix
|
|
82
|
+
matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
|
|
83
|
+
matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
|
|
84
|
+
matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
|
|
85
|
+
matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
|
|
86
|
+
matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// src/common/index.ts
|
|
90
|
+
var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
|
|
91
|
+
DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
|
|
92
|
+
DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
|
|
93
|
+
return DFSOperation2;
|
|
94
|
+
})(DFSOperation || {});
|
|
95
|
+
var _Range = class _Range {
|
|
96
|
+
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
97
|
+
this.low = low;
|
|
98
|
+
this.high = high;
|
|
99
|
+
this.includeLow = includeLow;
|
|
100
|
+
this.includeHigh = includeHigh;
|
|
101
|
+
}
|
|
102
|
+
// Determine whether a key is within the range
|
|
103
|
+
isInRange(key, comparator) {
|
|
104
|
+
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
105
|
+
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
106
|
+
return lowCheck && highCheck;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
__name(_Range, "Range");
|
|
110
|
+
var Range = _Range;
|
|
111
|
+
|
|
64
112
|
// src/data-structures/base/iterable-element-base.ts
|
|
65
113
|
var _IterableElementBase = class _IterableElementBase {
|
|
66
114
|
/**
|
|
@@ -83,7 +131,7 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
83
131
|
if (options) {
|
|
84
132
|
const { toElementFn } = options;
|
|
85
133
|
if (typeof toElementFn === "function") this._toElementFn = toElementFn;
|
|
86
|
-
else if (toElementFn) throw new TypeError("toElementFn
|
|
134
|
+
else if (toElementFn) throw new TypeError(ERR.notAFunction("toElementFn"));
|
|
87
135
|
}
|
|
88
136
|
}
|
|
89
137
|
/**
|
|
@@ -239,7 +287,7 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
239
287
|
acc = initialValue;
|
|
240
288
|
} else {
|
|
241
289
|
const first = iter.next();
|
|
242
|
-
if (first.done) throw new TypeError(
|
|
290
|
+
if (first.done) throw new TypeError(ERR.reduceEmpty());
|
|
243
291
|
acc = first.value;
|
|
244
292
|
index = 1;
|
|
245
293
|
}
|
|
@@ -1025,29 +1073,6 @@ var _IterableEntryBase = class _IterableEntryBase {
|
|
|
1025
1073
|
__name(_IterableEntryBase, "IterableEntryBase");
|
|
1026
1074
|
var IterableEntryBase = _IterableEntryBase;
|
|
1027
1075
|
|
|
1028
|
-
// src/common/index.ts
|
|
1029
|
-
var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
|
|
1030
|
-
DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
|
|
1031
|
-
DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
|
|
1032
|
-
return DFSOperation2;
|
|
1033
|
-
})(DFSOperation || {});
|
|
1034
|
-
var _Range = class _Range {
|
|
1035
|
-
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
1036
|
-
this.low = low;
|
|
1037
|
-
this.high = high;
|
|
1038
|
-
this.includeLow = includeLow;
|
|
1039
|
-
this.includeHigh = includeHigh;
|
|
1040
|
-
}
|
|
1041
|
-
// Determine whether a key is within the range
|
|
1042
|
-
isInRange(key, comparator) {
|
|
1043
|
-
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
1044
|
-
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
1045
|
-
return lowCheck && highCheck;
|
|
1046
|
-
}
|
|
1047
|
-
};
|
|
1048
|
-
__name(_Range, "Range");
|
|
1049
|
-
var Range = _Range;
|
|
1050
|
-
|
|
1051
1076
|
// src/data-structures/binary-tree/binary-tree.ts
|
|
1052
1077
|
var _BinaryTreeNode = class _BinaryTreeNode {
|
|
1053
1078
|
/**
|
|
@@ -1213,14 +1238,14 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
1213
1238
|
* @param node - The node.
|
|
1214
1239
|
* @returns The node's key or undefined.
|
|
1215
1240
|
*/
|
|
1216
|
-
__publicField(this, "_DEFAULT_NODE_CALLBACK", /* @__PURE__ */ __name((node) => node
|
|
1241
|
+
__publicField(this, "_DEFAULT_NODE_CALLBACK", /* @__PURE__ */ __name((node) => node == null ? void 0 : node.key, "_DEFAULT_NODE_CALLBACK"));
|
|
1217
1242
|
if (options) {
|
|
1218
1243
|
const { iterationType, toEntryFn, isMapMode, isDuplicate } = options;
|
|
1219
1244
|
if (iterationType) this.iterationType = iterationType;
|
|
1220
1245
|
if (isMapMode !== void 0) this._isMapMode = isMapMode;
|
|
1221
1246
|
if (isDuplicate !== void 0) this._isDuplicate = isDuplicate;
|
|
1222
1247
|
if (typeof toEntryFn === "function") this._toEntryFn = toEntryFn;
|
|
1223
|
-
else if (toEntryFn) throw TypeError("toEntryFn
|
|
1248
|
+
else if (toEntryFn) throw new TypeError(ERR.notAFunction("toEntryFn", "BinaryTree"));
|
|
1224
1249
|
}
|
|
1225
1250
|
if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
|
|
1226
1251
|
}
|
|
@@ -1448,7 +1473,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
1448
1473
|
if (!this._root) {
|
|
1449
1474
|
this._setRoot(newNode);
|
|
1450
1475
|
if (this._isMapMode && newNode !== null && newNode !== void 0) this._store.set(newNode.key, newNode);
|
|
1451
|
-
this._size = 1;
|
|
1476
|
+
if (newNode !== null) this._size = 1;
|
|
1452
1477
|
return true;
|
|
1453
1478
|
}
|
|
1454
1479
|
const queue = new Queue([this._root]);
|
|
@@ -1480,7 +1505,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
1480
1505
|
potentialParent.right = newNode;
|
|
1481
1506
|
}
|
|
1482
1507
|
if (this._isMapMode && newNode !== null && newNode !== void 0) this._store.set(newNode.key, newNode);
|
|
1483
|
-
this._size++;
|
|
1508
|
+
if (newNode !== null) this._size++;
|
|
1484
1509
|
return true;
|
|
1485
1510
|
}
|
|
1486
1511
|
return false;
|
|
@@ -2049,7 +2074,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2049
2074
|
}
|
|
2050
2075
|
/**
|
|
2051
2076
|
* Finds all leaf nodes in the tree.
|
|
2052
|
-
* @remarks Time O(N), visits every node. Space O(H) for recursive
|
|
2077
|
+
* @remarks Time O(N), visits every node. Space O(H) for recursive or iterative stack.
|
|
2053
2078
|
*
|
|
2054
2079
|
* @template C - The type of the callback function.
|
|
2055
2080
|
* @param [callback=this._DEFAULT_NODE_CALLBACK] - Function to call on each leaf node.
|
|
@@ -2072,15 +2097,15 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2072
2097
|
}, "dfs");
|
|
2073
2098
|
dfs(startNode);
|
|
2074
2099
|
} else {
|
|
2075
|
-
const
|
|
2076
|
-
while (
|
|
2077
|
-
const cur =
|
|
2100
|
+
const stack = [startNode];
|
|
2101
|
+
while (stack.length > 0) {
|
|
2102
|
+
const cur = stack.pop();
|
|
2078
2103
|
if (this.isRealNode(cur)) {
|
|
2079
2104
|
if (this.isLeaf(cur)) {
|
|
2080
2105
|
leaves.push(callback(cur));
|
|
2081
2106
|
}
|
|
2082
|
-
if (this.isRealNode(cur.
|
|
2083
|
-
if (this.isRealNode(cur.
|
|
2107
|
+
if (this.isRealNode(cur.right)) stack.push(cur.right);
|
|
2108
|
+
if (this.isRealNode(cur.left)) stack.push(cur.left);
|
|
2084
2109
|
}
|
|
2085
2110
|
}
|
|
2086
2111
|
}
|
|
@@ -2536,42 +2561,98 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2536
2561
|
_displayAux(node, options) {
|
|
2537
2562
|
const { isShowNull, isShowUndefined, isShowRedBlackNIL } = options;
|
|
2538
2563
|
const emptyDisplayLayout = [["\u2500"], 1, 0, 0];
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
const
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2564
|
+
const newFrame = /* @__PURE__ */ __name((n) => ({
|
|
2565
|
+
node: n,
|
|
2566
|
+
stage: 0,
|
|
2567
|
+
leftLayout: emptyDisplayLayout,
|
|
2568
|
+
rightLayout: emptyDisplayLayout
|
|
2569
|
+
}), "newFrame");
|
|
2570
|
+
const stack = [newFrame(node)];
|
|
2571
|
+
let result = emptyDisplayLayout;
|
|
2572
|
+
const setChildResult = /* @__PURE__ */ __name((layout) => {
|
|
2573
|
+
if (stack.length === 0) {
|
|
2574
|
+
result = layout;
|
|
2575
|
+
return;
|
|
2576
|
+
}
|
|
2577
|
+
const parent = stack[stack.length - 1];
|
|
2578
|
+
if (parent.stage === 1) parent.leftLayout = layout;
|
|
2579
|
+
else parent.rightLayout = layout;
|
|
2580
|
+
}, "setChildResult");
|
|
2581
|
+
while (stack.length > 0) {
|
|
2582
|
+
const frame = stack[stack.length - 1];
|
|
2583
|
+
const cur = frame.node;
|
|
2584
|
+
if (frame.stage === 0) {
|
|
2585
|
+
if (this._isDisplayLeaf(cur, options)) {
|
|
2586
|
+
stack.pop();
|
|
2587
|
+
const layout = this._resolveDisplayLeaf(cur, options, emptyDisplayLayout);
|
|
2588
|
+
setChildResult(layout);
|
|
2589
|
+
continue;
|
|
2590
|
+
}
|
|
2591
|
+
frame.stage = 1;
|
|
2592
|
+
stack.push(newFrame(cur.left));
|
|
2593
|
+
} else if (frame.stage === 1) {
|
|
2594
|
+
frame.stage = 2;
|
|
2595
|
+
stack.push(newFrame(cur.right));
|
|
2596
|
+
} else {
|
|
2597
|
+
stack.pop();
|
|
2598
|
+
const line = this.isNIL(cur) ? "S" : String(cur.key);
|
|
2599
|
+
const layout = _BinaryTree._buildNodeDisplay(line, line.length, frame.leftLayout, frame.rightLayout);
|
|
2600
|
+
setChildResult(layout);
|
|
2567
2601
|
}
|
|
2568
|
-
return [
|
|
2569
|
-
mergedLines,
|
|
2570
|
-
leftWidth + width + rightWidth,
|
|
2571
|
-
Math.max(leftHeight, rightHeight) + 2,
|
|
2572
|
-
leftWidth + Math.floor(width / 2)
|
|
2573
|
-
];
|
|
2574
2602
|
}
|
|
2603
|
+
return result;
|
|
2604
|
+
}
|
|
2605
|
+
static _buildNodeDisplay(line, width, left, right) {
|
|
2606
|
+
const [leftLines, leftWidth, leftHeight, leftMiddle] = left;
|
|
2607
|
+
const [rightLines, rightWidth, rightHeight, rightMiddle] = right;
|
|
2608
|
+
const firstLine = " ".repeat(Math.max(0, leftMiddle + 1)) + "_".repeat(Math.max(0, leftWidth - leftMiddle - 1)) + line + "_".repeat(Math.max(0, rightMiddle)) + " ".repeat(Math.max(0, rightWidth - rightMiddle));
|
|
2609
|
+
const secondLine = (leftHeight > 0 ? " ".repeat(leftMiddle) + "/" + " ".repeat(leftWidth - leftMiddle - 1) : " ".repeat(leftWidth)) + " ".repeat(width) + (rightHeight > 0 ? " ".repeat(rightMiddle) + "\\" + " ".repeat(rightWidth - rightMiddle - 1) : " ".repeat(rightWidth));
|
|
2610
|
+
const mergedLines = [firstLine, secondLine];
|
|
2611
|
+
for (let i = 0; i < Math.max(leftHeight, rightHeight); i++) {
|
|
2612
|
+
const leftLine = i < leftHeight ? leftLines[i] : " ".repeat(leftWidth);
|
|
2613
|
+
const rightLine = i < rightHeight ? rightLines[i] : " ".repeat(rightWidth);
|
|
2614
|
+
mergedLines.push(leftLine + " ".repeat(width) + rightLine);
|
|
2615
|
+
}
|
|
2616
|
+
return [
|
|
2617
|
+
mergedLines,
|
|
2618
|
+
leftWidth + width + rightWidth,
|
|
2619
|
+
Math.max(leftHeight, rightHeight) + 2,
|
|
2620
|
+
leftWidth + Math.floor(width / 2)
|
|
2621
|
+
];
|
|
2622
|
+
}
|
|
2623
|
+
/**
|
|
2624
|
+
* Check if a node is a display leaf (empty, null, undefined, NIL, or real leaf).
|
|
2625
|
+
*/
|
|
2626
|
+
_isDisplayLeaf(node, options) {
|
|
2627
|
+
const { isShowNull, isShowUndefined, isShowRedBlackNIL } = options;
|
|
2628
|
+
if (node === null && !isShowNull) return true;
|
|
2629
|
+
if (node === void 0 && !isShowUndefined) return true;
|
|
2630
|
+
if (this.isNIL(node) && !isShowRedBlackNIL) return true;
|
|
2631
|
+
if (node === null || node === void 0) return true;
|
|
2632
|
+
const hasDisplayableLeft = this._hasDisplayableChild(node.left, options);
|
|
2633
|
+
const hasDisplayableRight = this._hasDisplayableChild(node.right, options);
|
|
2634
|
+
return !hasDisplayableLeft && !hasDisplayableRight;
|
|
2635
|
+
}
|
|
2636
|
+
_hasDisplayableChild(child, options) {
|
|
2637
|
+
if (child === null) return !!options.isShowNull;
|
|
2638
|
+
if (child === void 0) return !!options.isShowUndefined;
|
|
2639
|
+
if (this.isNIL(child)) return !!options.isShowRedBlackNIL;
|
|
2640
|
+
return true;
|
|
2641
|
+
}
|
|
2642
|
+
/**
|
|
2643
|
+
* Resolve a display leaf node to its layout.
|
|
2644
|
+
*/
|
|
2645
|
+
_resolveDisplayLeaf(node, options, emptyDisplayLayout) {
|
|
2646
|
+
const { isShowNull, isShowUndefined, isShowRedBlackNIL } = options;
|
|
2647
|
+
if (node === null && !isShowNull) return emptyDisplayLayout;
|
|
2648
|
+
if (node === void 0 && !isShowUndefined) return emptyDisplayLayout;
|
|
2649
|
+
if (this.isNIL(node) && !isShowRedBlackNIL) return emptyDisplayLayout;
|
|
2650
|
+
if (node !== null && node !== void 0) {
|
|
2651
|
+
const line2 = this.isNIL(node) ? "S" : String(node.key);
|
|
2652
|
+
return _BinaryTree._buildNodeDisplay(line2, line2.length, emptyDisplayLayout, emptyDisplayLayout);
|
|
2653
|
+
}
|
|
2654
|
+
const line = node === void 0 ? "U" : "N";
|
|
2655
|
+
return _BinaryTree._buildNodeDisplay(line, line.length, [[""], 1, 0, 0], [[""], 1, 0, 0]);
|
|
2575
2656
|
}
|
|
2576
2657
|
/**
|
|
2577
2658
|
* (Protected) Swaps the key/value properties of two nodes.
|
|
@@ -2720,6 +2801,7 @@ var BinaryTree = _BinaryTree;
|
|
|
2720
2801
|
exports.BinaryTree = BinaryTree;
|
|
2721
2802
|
exports.BinaryTreeNode = BinaryTreeNode;
|
|
2722
2803
|
exports.DFSOperation = DFSOperation;
|
|
2804
|
+
exports.ERR = ERR;
|
|
2723
2805
|
exports.Range = Range;
|
|
2724
2806
|
//# sourceMappingURL=index.cjs.map
|
|
2725
2807
|
//# sourceMappingURL=index.cjs.map
|