data-structure-typed 1.54.2 → 1.54.3
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/CHANGELOG.md +1 -1
- package/LICENSE +2 -2
- package/README.md +14 -1
- package/README_zh-CN.md +1 -1
- package/benchmark/report.html +4 -1
- package/benchmark/report.json +76 -17
- package/dist/cjs/data-structures/binary-tree/avl-tree-counter.d.ts +21 -20
- package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js +8 -7
- package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +12 -12
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +2 -2
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +25 -21
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +12 -8
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +111 -225
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +177 -144
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +59 -53
- package/dist/cjs/data-structures/binary-tree/bst.js +75 -119
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/red-black-tree.d.ts +18 -18
- package/dist/cjs/data-structures/binary-tree/red-black-tree.js +6 -6
- package/dist/cjs/data-structures/binary-tree/red-black-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-counter.d.ts +19 -19
- package/dist/cjs/data-structures/binary-tree/tree-counter.js +12 -12
- package/dist/cjs/data-structures/binary-tree/tree-counter.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +12 -12
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +2 -2
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -0
- package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +1 -1
- package/dist/cjs/utils/utils.d.ts +2 -2
- package/dist/esm/data-structures/binary-tree/avl-tree-counter.d.ts +21 -20
- package/dist/esm/data-structures/binary-tree/avl-tree-counter.js +9 -8
- package/dist/esm/data-structures/binary-tree/avl-tree-counter.js.map +1 -1
- package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.d.ts +12 -12
- package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js +3 -3
- package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
- package/dist/esm/data-structures/binary-tree/avl-tree.d.ts +25 -21
- package/dist/esm/data-structures/binary-tree/avl-tree.js +13 -9
- package/dist/esm/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/esm/data-structures/binary-tree/binary-tree.d.ts +111 -225
- package/dist/esm/data-structures/binary-tree/binary-tree.js +181 -148
- package/dist/esm/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/esm/data-structures/binary-tree/bst.d.ts +59 -53
- package/dist/esm/data-structures/binary-tree/bst.js +76 -120
- package/dist/esm/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/esm/data-structures/binary-tree/red-black-tree.d.ts +18 -18
- package/dist/esm/data-structures/binary-tree/red-black-tree.js +7 -7
- package/dist/esm/data-structures/binary-tree/red-black-tree.js.map +1 -1
- package/dist/esm/data-structures/binary-tree/tree-counter.d.ts +19 -19
- package/dist/esm/data-structures/binary-tree/tree-counter.js +13 -13
- package/dist/esm/data-structures/binary-tree/tree-counter.js.map +1 -1
- package/dist/esm/data-structures/binary-tree/tree-multi-map.d.ts +12 -12
- package/dist/esm/data-structures/binary-tree/tree-multi-map.js +3 -3
- package/dist/esm/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/esm/types/data-structures/binary-tree/binary-tree.d.ts +1 -0
- package/dist/esm/types/data-structures/binary-tree/bst.d.ts +1 -1
- package/dist/esm/utils/utils.d.ts +2 -2
- package/dist/umd/data-structure-typed.js +296 -279
- package/dist/umd/data-structure-typed.min.js +5 -12
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +7 -7
- package/src/data-structures/binary-tree/avl-tree-counter.ts +30 -23
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +25 -15
- package/src/data-structures/binary-tree/avl-tree.ts +35 -29
- package/src/data-structures/binary-tree/binary-tree.ts +469 -252
- package/src/data-structures/binary-tree/bst.ts +141 -143
- package/src/data-structures/binary-tree/red-black-tree.ts +27 -35
- package/src/data-structures/binary-tree/tree-counter.ts +33 -27
- package/src/data-structures/binary-tree/tree-multi-map.ts +25 -17
- package/src/types/data-structures/binary-tree/binary-tree.ts +1 -0
- package/src/types/data-structures/binary-tree/bst.ts +1 -1
- package/src/utils/utils.ts +2 -2
- package/test/integration/compile.mjs +21 -21
- package/test/performance/data-structures/binary-tree/avl-tree.test.mjs +71 -0
- package/test/performance/data-structures/binary-tree/red-black-tree.test.mjs +81 -0
- package/test/performance/{reportor.js → reportor.mjs} +264 -8
- package/test/performance/reportor.ts +1 -1
- package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +7 -7
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +4 -5
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +72 -5
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +132 -82
- package/test/unit/data-structures/binary-tree/bst.test.ts +12 -12
- package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +4 -12
- package/test/unit/data-structures/binary-tree/tree-counter.test.ts +4 -4
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +5 -5
- package/test/utils/json2html.ts +0 -154
- package/test/performance/data-structures/binary-tree/avl-tree.test.js +0 -45
- /package/test/performance/data-structures/binary-tree/{rb-tree.test.ts → red-black-tree.test.ts} +0 -0
|
@@ -7463,7 +7463,7 @@ var dataStructureTyped = (() => {
|
|
|
7463
7463
|
* This TypeScript constructor function initializes a binary tree with optional options and adds
|
|
7464
7464
|
* elements based on the provided input.
|
|
7465
7465
|
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor is an
|
|
7466
|
-
* iterable that can contain either objects of type `
|
|
7466
|
+
* iterable that can contain either objects of type `K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined ` or `R`. It
|
|
7467
7467
|
* is used to initialize the binary tree with keys, nodes, entries, or raw data.
|
|
7468
7468
|
* @param [options] - The `options` parameter in the constructor is an optional object that can
|
|
7469
7469
|
* contain the following properties:
|
|
@@ -7472,6 +7472,7 @@ var dataStructureTyped = (() => {
|
|
|
7472
7472
|
super();
|
|
7473
7473
|
__publicField(this, "iterationType", "ITERATIVE");
|
|
7474
7474
|
__publicField(this, "_isMapMode", true);
|
|
7475
|
+
__publicField(this, "_isDuplicate", false);
|
|
7475
7476
|
__publicField(this, "_store", /* @__PURE__ */ new Map());
|
|
7476
7477
|
__publicField(this, "_root");
|
|
7477
7478
|
__publicField(this, "_size", 0);
|
|
@@ -7479,9 +7480,10 @@ var dataStructureTyped = (() => {
|
|
|
7479
7480
|
__publicField(this, "_toEntryFn");
|
|
7480
7481
|
__publicField(this, "_DEFAULT_NODE_CALLBACK", (node) => node ? node.key : void 0);
|
|
7481
7482
|
if (options) {
|
|
7482
|
-
const { iterationType, toEntryFn, isMapMode } = options;
|
|
7483
|
+
const { iterationType, toEntryFn, isMapMode, isDuplicate } = options;
|
|
7483
7484
|
if (iterationType) this.iterationType = iterationType;
|
|
7484
7485
|
if (isMapMode !== void 0) this._isMapMode = isMapMode;
|
|
7486
|
+
if (isDuplicate !== void 0) this._isDuplicate = isDuplicate;
|
|
7485
7487
|
if (typeof toEntryFn === "function") this._toEntryFn = toEntryFn;
|
|
7486
7488
|
else if (toEntryFn) throw TypeError("toEntryFn must be a function type");
|
|
7487
7489
|
}
|
|
@@ -7490,6 +7492,9 @@ var dataStructureTyped = (() => {
|
|
|
7490
7492
|
get isMapMode() {
|
|
7491
7493
|
return this._isMapMode;
|
|
7492
7494
|
}
|
|
7495
|
+
get isDuplicate() {
|
|
7496
|
+
return this._isDuplicate;
|
|
7497
|
+
}
|
|
7493
7498
|
get store() {
|
|
7494
7499
|
return this._store;
|
|
7495
7500
|
}
|
|
@@ -7544,8 +7549,8 @@ var dataStructureTyped = (() => {
|
|
|
7544
7549
|
*
|
|
7545
7550
|
* The function `ensureNode` in TypeScript checks if a given input is a node, entry, key, or raw
|
|
7546
7551
|
* value and returns the corresponding node or null.
|
|
7547
|
-
* @param {
|
|
7548
|
-
* parameter in the `ensureNode` function can be of type `
|
|
7552
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The `keyNodeOrEntry`
|
|
7553
|
+
* parameter in the `ensureNode` function can be of type `K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined ` or `R`. It
|
|
7549
7554
|
* is used to determine whether the input is a key, node, entry, or raw data. The
|
|
7550
7555
|
* @param {IterationType} iterationType - The `iterationType` parameter in the `ensureNode` function
|
|
7551
7556
|
* is used to specify the type of iteration to be performed. It has a default value of
|
|
@@ -7571,7 +7576,7 @@ var dataStructureTyped = (() => {
|
|
|
7571
7576
|
* Space Complexity: O(1)
|
|
7572
7577
|
*
|
|
7573
7578
|
* The function isNode checks if the input is an instance of BinaryTreeNode.
|
|
7574
|
-
* @param {
|
|
7579
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The parameter
|
|
7575
7580
|
* `keyNodeOrEntry` can be either a key, a node, an entry, or raw data. The function is
|
|
7576
7581
|
* checking if the input is an instance of a `BinaryTreeNode` and returning a boolean value
|
|
7577
7582
|
* accordingly.
|
|
@@ -7588,7 +7593,7 @@ var dataStructureTyped = (() => {
|
|
|
7588
7593
|
* Space Complexity: O(1)
|
|
7589
7594
|
*
|
|
7590
7595
|
* The function `isRaw` checks if the input parameter is of type `R` by verifying if it is an object.
|
|
7591
|
-
* @param {
|
|
7596
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R} keyNodeEntryOrRaw - K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined
|
|
7592
7597
|
* @returns The function `isRaw` is checking if the `keyNodeEntryOrRaw` parameter is of type `R` by
|
|
7593
7598
|
* checking if it is an object. If the parameter is an object, the function will return `true`,
|
|
7594
7599
|
* indicating that it is of type `R`.
|
|
@@ -7601,8 +7606,8 @@ var dataStructureTyped = (() => {
|
|
|
7601
7606
|
* Space Complexity: O(1)
|
|
7602
7607
|
*
|
|
7603
7608
|
* The function `isRealNode` checks if a given input is a valid node in a binary tree.
|
|
7604
|
-
* @param {
|
|
7605
|
-
* parameter in the `isRealNode` function can be of type `
|
|
7609
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The `keyNodeOrEntry`
|
|
7610
|
+
* parameter in the `isRealNode` function can be of type `K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined ` or `R`.
|
|
7606
7611
|
* The function checks if the input parameter is a `BinaryTreeNode<K, V>` type by verifying if it is not equal
|
|
7607
7612
|
* @returns The function `isRealNode` is checking if the input `keyNodeOrEntry` is a valid
|
|
7608
7613
|
* node by comparing it to `this._NIL`, `null`, and `undefined`. If the input is not one of these
|
|
@@ -7618,7 +7623,7 @@ var dataStructureTyped = (() => {
|
|
|
7618
7623
|
* Space Complexity: O(1)
|
|
7619
7624
|
*
|
|
7620
7625
|
* The function checks if a given input is a valid node or null.
|
|
7621
|
-
* @param {
|
|
7626
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The parameter
|
|
7622
7627
|
* `keyNodeOrEntry` in the `isRealNodeOrNull` function can be of type `BTNRep<K,
|
|
7623
7628
|
* V, BinaryTreeNode<K, V>>` or `R`. It is a union type that can either be a key, a node, an entry, or
|
|
7624
7629
|
* @returns The function `isRealNodeOrNull` is returning a boolean value. It checks if the input
|
|
@@ -7633,7 +7638,7 @@ var dataStructureTyped = (() => {
|
|
|
7633
7638
|
* Space Complexity: O(1)
|
|
7634
7639
|
*
|
|
7635
7640
|
* The function isNIL checks if a given key, node, entry, or raw value is equal to the _NIL value.
|
|
7636
|
-
* @param {
|
|
7641
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - BTNRep<K, V,
|
|
7637
7642
|
* BinaryTreeNode<K, V>>
|
|
7638
7643
|
* @returns The function is checking if the `keyNodeOrEntry` parameter is equal to the `_NIL`
|
|
7639
7644
|
* property of the current object and returning a boolean value based on that comparison.
|
|
@@ -7646,9 +7651,9 @@ var dataStructureTyped = (() => {
|
|
|
7646
7651
|
* Space Complexity: O(1)
|
|
7647
7652
|
*
|
|
7648
7653
|
* The function `isRange` checks if the input parameter is an instance of the `Range` class.
|
|
7649
|
-
* @param {
|
|
7650
|
-
*
|
|
7651
|
-
* of type `
|
|
7654
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BinaryTreeNode<K, V>> | Range<K>} keyNodeEntryOrPredicate
|
|
7655
|
+
* - The `keyNodeEntryOrPredicate` parameter in the `isRange` function can be
|
|
7656
|
+
* of type `K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined `, `NodePredicate<BinaryTreeNode<K, V>>`, or
|
|
7652
7657
|
* `Range<K>`. The function checks if the `keyNodeEntry
|
|
7653
7658
|
* @returns The `isRange` function is checking if the `keyNodeEntryOrPredicate` parameter is an
|
|
7654
7659
|
* instance of the `Range` class. If it is an instance of `Range`, the function will return `true`,
|
|
@@ -7664,8 +7669,8 @@ var dataStructureTyped = (() => {
|
|
|
7664
7669
|
*
|
|
7665
7670
|
* The function determines whether a given key, node, entry, or raw data is a leaf node in a binary
|
|
7666
7671
|
* tree.
|
|
7667
|
-
* @param {
|
|
7668
|
-
* `keyNodeOrEntry` can be of type `
|
|
7672
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The parameter
|
|
7673
|
+
* `keyNodeOrEntry` can be of type `K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined ` or `R`. It represents a
|
|
7669
7674
|
* key, node, entry, or raw data in a binary tree structure. The function `isLeaf` checks whether the
|
|
7670
7675
|
* provided
|
|
7671
7676
|
* @returns The function `isLeaf` returns a boolean value indicating whether the input
|
|
@@ -7683,8 +7688,8 @@ var dataStructureTyped = (() => {
|
|
|
7683
7688
|
*
|
|
7684
7689
|
* The function `isEntry` checks if the input is a BTNEntry object by verifying if it is an array
|
|
7685
7690
|
* with a length of 2.
|
|
7686
|
-
* @param {
|
|
7687
|
-
* parameter in the `isEntry` function can be of type `
|
|
7691
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The `keyNodeOrEntry`
|
|
7692
|
+
* parameter in the `isEntry` function can be of type `K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined ` or type `R`.
|
|
7688
7693
|
* The function checks if the provided `keyNodeOrEntry` is of type `BTN
|
|
7689
7694
|
* @returns The `isEntry` function is checking if the `keyNodeOrEntry` parameter is an array
|
|
7690
7695
|
* with a length of 2. If it is, then it returns `true`, indicating that the parameter is of type
|
|
@@ -7714,7 +7719,7 @@ var dataStructureTyped = (() => {
|
|
|
7714
7719
|
*
|
|
7715
7720
|
* The `add` function in TypeScript adds a new node to a binary tree while handling duplicate keys
|
|
7716
7721
|
* and finding the correct insertion position.
|
|
7717
|
-
* @param {
|
|
7722
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The `add` method you provided
|
|
7718
7723
|
* seems to be for adding a new node to a binary tree structure. The `keyNodeOrEntry`
|
|
7719
7724
|
* parameter in the method can accept different types of values:
|
|
7720
7725
|
* @param {V} [value] - The `value` parameter in the `add` method represents the value associated
|
|
@@ -7739,10 +7744,12 @@ var dataStructureTyped = (() => {
|
|
|
7739
7744
|
while (queue.size > 0) {
|
|
7740
7745
|
const cur = queue.shift();
|
|
7741
7746
|
if (!cur) continue;
|
|
7742
|
-
if (
|
|
7743
|
-
|
|
7744
|
-
|
|
7745
|
-
|
|
7747
|
+
if (!this._isDuplicate) {
|
|
7748
|
+
if (newNode !== null && cur.key === newNode.key) {
|
|
7749
|
+
this._replaceNode(cur, newNode);
|
|
7750
|
+
if (this._isMapMode) this._setValue(cur.key, newValue);
|
|
7751
|
+
return true;
|
|
7752
|
+
}
|
|
7746
7753
|
}
|
|
7747
7754
|
if (potentialParent === void 0 && (cur.left === void 0 || cur.right === void 0)) {
|
|
7748
7755
|
potentialParent = cur;
|
|
@@ -7775,7 +7782,7 @@ var dataStructureTyped = (() => {
|
|
|
7775
7782
|
* each insertion was successful.
|
|
7776
7783
|
* @param keysNodesEntriesOrRaws - `keysNodesEntriesOrRaws` is an iterable that can contain a
|
|
7777
7784
|
* mix of keys, nodes, entries, or raw values. Each element in this iterable can be of type
|
|
7778
|
-
* `
|
|
7785
|
+
* `K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined ` or `R`.
|
|
7779
7786
|
* @param [values] - The `values` parameter in the `addMany` function is an optional parameter that
|
|
7780
7787
|
* accepts an iterable of values. These values correspond to the keys or nodes being added in the
|
|
7781
7788
|
* `keysNodesEntriesOrRaws` parameter. If provided, the function will iterate over the values and
|
|
@@ -7821,7 +7828,7 @@ var dataStructureTyped = (() => {
|
|
|
7821
7828
|
* The `refill` function clears the existing data structure and then adds new key-value pairs based
|
|
7822
7829
|
* on the provided input.
|
|
7823
7830
|
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the `refill`
|
|
7824
|
-
* method can accept an iterable containing a mix of `
|
|
7831
|
+
* method can accept an iterable containing a mix of `K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined ` objects or `R`
|
|
7825
7832
|
* objects.
|
|
7826
7833
|
* @param [values] - The `values` parameter in the `refill` method is an optional parameter that
|
|
7827
7834
|
* accepts an iterable of values of type `V` or `undefined`.
|
|
@@ -7836,7 +7843,7 @@ var dataStructureTyped = (() => {
|
|
|
7836
7843
|
*
|
|
7837
7844
|
* The function `delete` in TypeScript implements the deletion of a node in a binary tree and returns
|
|
7838
7845
|
* the deleted node along with information for tree balancing.
|
|
7839
|
-
* @param {
|
|
7846
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry
|
|
7840
7847
|
* - The `delete` method you provided is used to delete a node from a binary tree based on the key,
|
|
7841
7848
|
* node, entry or raw data. The method returns an array of
|
|
7842
7849
|
* `BinaryTreeDeleteResult` objects containing information about the deleted node and whether
|
|
@@ -7890,15 +7897,15 @@ var dataStructureTyped = (() => {
|
|
|
7890
7897
|
*
|
|
7891
7898
|
* The `search` function in TypeScript performs a depth-first or breadth-first search on a tree
|
|
7892
7899
|
* structure based on a given predicate or key, with options to return multiple results or just one.
|
|
7893
|
-
* @param {
|
|
7900
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate - The
|
|
7894
7901
|
* `keyNodeEntryOrPredicate` parameter in the `search` function can accept three types of values:
|
|
7895
7902
|
* @param [onlyOne=false] - The `onlyOne` parameter in the `search` function is a boolean flag that
|
|
7896
7903
|
* determines whether the search should stop after finding the first matching node. If `onlyOne` is
|
|
7897
7904
|
* set to `true`, the search will return as soon as a matching node is found. If `onlyOne` is
|
|
7898
7905
|
* @param {C} callback - The `callback` parameter in the `search` function is a callback function
|
|
7899
7906
|
* that will be called on each node that matches the search criteria. It is of type `C`, which
|
|
7900
|
-
* extends `NodeCallback<BinaryTreeNode<K, V
|
|
7901
|
-
* @param {
|
|
7907
|
+
* extends `NodeCallback<BinaryTreeNode<K, V> | null>`. The default value for `callback` is `this._DEFAULT_NODE_CALLBACK` if
|
|
7908
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the `search` function is
|
|
7902
7909
|
* used to specify the node from which the search operation should begin. It represents the starting
|
|
7903
7910
|
* point in the binary tree where the search will be performed. If no specific `startNode` is
|
|
7904
7911
|
* provided, the search operation will start from the root
|
|
@@ -7948,12 +7955,12 @@ var dataStructureTyped = (() => {
|
|
|
7948
7955
|
*
|
|
7949
7956
|
* The function `getNodes` retrieves nodes from a binary tree based on a key, node, entry, raw data,
|
|
7950
7957
|
* or predicate, with options for recursive or iterative traversal.
|
|
7951
|
-
* @param {
|
|
7958
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate
|
|
7952
7959
|
* - The `getNodes` function you provided takes several parameters:
|
|
7953
7960
|
* @param [onlyOne=false] - The `onlyOne` parameter in the `getNodes` function is a boolean flag that
|
|
7954
7961
|
* determines whether to return only the first node that matches the criteria specified by the
|
|
7955
7962
|
* `keyNodeEntryOrPredicate` parameter. If `onlyOne` is set to `true`, the function will
|
|
7956
|
-
* @param {
|
|
7963
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the
|
|
7957
7964
|
* `getNodes` function is used to specify the starting point for traversing the binary tree. It
|
|
7958
7965
|
* represents the root node of the binary tree or the node from which the traversal should begin. If
|
|
7959
7966
|
* not provided, the default value is set to `this._root
|
|
@@ -7972,10 +7979,10 @@ var dataStructureTyped = (() => {
|
|
|
7972
7979
|
*
|
|
7973
7980
|
* The `getNode` function retrieves a node based on the provided key, node, entry, raw data, or
|
|
7974
7981
|
* predicate.
|
|
7975
|
-
* @param {
|
|
7982
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate
|
|
7976
7983
|
* - The `keyNodeEntryOrPredicate` parameter in the `getNode` function can accept a key,
|
|
7977
7984
|
* node, entry, raw data, or a predicate function.
|
|
7978
|
-
* @param {
|
|
7985
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the
|
|
7979
7986
|
* `getNode` function is used to specify the starting point for searching for a node in a binary
|
|
7980
7987
|
* tree. If no specific starting point is provided, the default value is set to `this._root`, which
|
|
7981
7988
|
* is typically the root node of the binary tree.
|
|
@@ -7995,10 +8002,10 @@ var dataStructureTyped = (() => {
|
|
|
7995
8002
|
*
|
|
7996
8003
|
* This function overrides the `get` method to retrieve the value associated with a specified key,
|
|
7997
8004
|
* node, entry, raw data, or predicate in a data structure.
|
|
7998
|
-
* @param {
|
|
8005
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate
|
|
7999
8006
|
* - The `keyNodeEntryOrPredicate` parameter in the `get` method can accept one of the
|
|
8000
8007
|
* following types:
|
|
8001
|
-
* @param {
|
|
8008
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the `get`
|
|
8002
8009
|
* method is used to specify the starting point for searching for a key or node in the binary tree.
|
|
8003
8010
|
* If no specific starting point is provided, the default starting point is the root of the binary
|
|
8004
8011
|
* tree (`this._root`).
|
|
@@ -8026,10 +8033,10 @@ var dataStructureTyped = (() => {
|
|
|
8026
8033
|
*
|
|
8027
8034
|
* The `has` function in TypeScript checks if a specified key, node, entry, raw data, or predicate
|
|
8028
8035
|
* exists in the data structure.
|
|
8029
|
-
* @param {
|
|
8036
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate
|
|
8030
8037
|
* - The `keyNodeEntryOrPredicate` parameter in the `override has` method can accept one of
|
|
8031
8038
|
* the following types:
|
|
8032
|
-
* @param {
|
|
8039
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the
|
|
8033
8040
|
* `override` method is used to specify the starting point for the search operation within the data
|
|
8034
8041
|
* structure. It defaults to `this._root` if not provided explicitly.
|
|
8035
8042
|
* @param {IterationType} iterationType - The `iterationType` parameter in the `override has` method
|
|
@@ -8072,7 +8079,7 @@ var dataStructureTyped = (() => {
|
|
|
8072
8079
|
*
|
|
8073
8080
|
* The function checks if a binary tree is perfectly balanced by comparing its minimum height with
|
|
8074
8081
|
* its height.
|
|
8075
|
-
* @param {
|
|
8082
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter is the starting
|
|
8076
8083
|
* point for checking if the binary tree is perfectly balanced. It represents the root node of the
|
|
8077
8084
|
* binary tree or a specific node from which the balance check should begin.
|
|
8078
8085
|
* @returns The method `isPerfectlyBalanced` is returning a boolean value, which indicates whether
|
|
@@ -8090,7 +8097,7 @@ var dataStructureTyped = (() => {
|
|
|
8090
8097
|
*
|
|
8091
8098
|
* The function `isBST` in TypeScript checks if a binary search tree is valid using either recursive
|
|
8092
8099
|
* or iterative methods.
|
|
8093
|
-
* @param {
|
|
8100
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the `isBST`
|
|
8094
8101
|
* function represents the starting point for checking whether a binary search tree (BST) is valid.
|
|
8095
8102
|
* It can be a node in the BST or a reference to the root of the BST. If no specific node is
|
|
8096
8103
|
* provided, the function will default to
|
|
@@ -8142,10 +8149,10 @@ var dataStructureTyped = (() => {
|
|
|
8142
8149
|
* Space Complexity: O(log n)
|
|
8143
8150
|
*
|
|
8144
8151
|
* The `getDepth` function calculates the depth between two nodes in a binary tree.
|
|
8145
|
-
* @param {
|
|
8152
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } dist - The `dist` parameter in the `getDepth`
|
|
8146
8153
|
* function represents the node or entry in a binary tree map, or a reference to a node in the tree.
|
|
8147
8154
|
* It is the target node for which you want to calculate the depth from the `startNode` node.
|
|
8148
|
-
* @param {
|
|
8155
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the
|
|
8149
8156
|
* `getDepth` function represents the starting point from which you want to calculate the depth of a
|
|
8150
8157
|
* given node or entry in a binary tree. If no specific starting point is provided, the default value
|
|
8151
8158
|
* for `startNode` is set to the root of the binary
|
|
@@ -8172,7 +8179,7 @@ var dataStructureTyped = (() => {
|
|
|
8172
8179
|
*
|
|
8173
8180
|
* The `getHeight` function calculates the maximum height of a binary tree using either a recursive
|
|
8174
8181
|
* or iterative approach in TypeScript.
|
|
8175
|
-
* @param {
|
|
8182
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter is the starting
|
|
8176
8183
|
* point from which the height of the binary tree will be calculated. It can be a node in the binary
|
|
8177
8184
|
* tree or a reference to the root of the tree. If not provided, it defaults to the root of the
|
|
8178
8185
|
* binary tree data structure.
|
|
@@ -8212,7 +8219,7 @@ var dataStructureTyped = (() => {
|
|
|
8212
8219
|
*
|
|
8213
8220
|
* The `getMinHeight` function calculates the minimum height of a binary tree using either a
|
|
8214
8221
|
* recursive or iterative approach in TypeScript.
|
|
8215
|
-
* @param {
|
|
8222
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the
|
|
8216
8223
|
* `getMinHeight` function represents the starting node from which the minimum height of the binary
|
|
8217
8224
|
* tree will be calculated. It is either a node in the binary tree or a reference to the root of the
|
|
8218
8225
|
* tree. If not provided, the default value is the root
|
|
@@ -8271,7 +8278,7 @@ var dataStructureTyped = (() => {
|
|
|
8271
8278
|
* the path to the root. It is expected to be a function that takes a node as an argument and returns
|
|
8272
8279
|
* a value based on that node. The return type of the callback function is determined by the generic
|
|
8273
8280
|
* type `C
|
|
8274
|
-
* @param {
|
|
8281
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } beginNode - The `beginNode` parameter in the
|
|
8275
8282
|
* `getPathToRoot` function can be either a key, a node, an entry, or any other value of type `R`.
|
|
8276
8283
|
* @param [isReverse=true] - The `isReverse` parameter in the `getPathToRoot` function determines
|
|
8277
8284
|
* whether the resulting path from the given `beginNode` to the root should be in reverse order or
|
|
@@ -8301,7 +8308,7 @@ var dataStructureTyped = (() => {
|
|
|
8301
8308
|
* @param {C} callback - The `callback` parameter is a function that will be called with the leftmost
|
|
8302
8309
|
* node of a binary tree or with `undefined` if the tree is empty. It is provided with a default
|
|
8303
8310
|
* value of `_DEFAULT_NODE_CALLBACK` if not specified.
|
|
8304
|
-
* @param {
|
|
8311
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the
|
|
8305
8312
|
* `getLeftMost` function represents the starting point for finding the leftmost node in a binary
|
|
8306
8313
|
* tree. It can be either a key, a node, or an entry in the binary tree structure. If no specific
|
|
8307
8314
|
* starting point is provided, the function will default
|
|
@@ -8341,7 +8348,7 @@ var dataStructureTyped = (() => {
|
|
|
8341
8348
|
* of finding the rightmost node in a binary tree. It is of type `NodeCallback<OptNodeOrNull<BinaryTreeNode<K, V>>>`,
|
|
8342
8349
|
* which means it is a callback function that can accept either an optional binary tree node or null
|
|
8343
8350
|
* as
|
|
8344
|
-
* @param {
|
|
8351
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the
|
|
8345
8352
|
* `getRightMost` function represents the starting point for finding the rightmost node in a binary
|
|
8346
8353
|
* tree. It can be either a key, a node, or an entry in the binary tree structure. If no specific
|
|
8347
8354
|
* starting point is provided, the function will default
|
|
@@ -8427,32 +8434,34 @@ var dataStructureTyped = (() => {
|
|
|
8427
8434
|
* Time complexity: O(n)
|
|
8428
8435
|
* Space complexity: O(n)
|
|
8429
8436
|
*
|
|
8430
|
-
* The function
|
|
8431
|
-
*
|
|
8432
|
-
* @param {C} callback - The `callback` parameter is a
|
|
8433
|
-
*
|
|
8434
|
-
*
|
|
8435
|
-
* @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `dfs`
|
|
8436
|
-
* order in which the
|
|
8437
|
-
*
|
|
8438
|
-
* @param {
|
|
8439
|
-
*
|
|
8440
|
-
*
|
|
8441
|
-
*
|
|
8442
|
-
* @param {
|
|
8443
|
-
*
|
|
8444
|
-
*
|
|
8445
|
-
*
|
|
8446
|
-
*
|
|
8447
|
-
*
|
|
8448
|
-
* `
|
|
8449
|
-
*
|
|
8450
|
-
*
|
|
8451
|
-
|
|
8452
|
-
|
|
8437
|
+
* The function performs a depth-first search on a binary tree structure based on the specified
|
|
8438
|
+
* parameters.
|
|
8439
|
+
* @param {C} callback - The `callback` parameter is a function that will be called for each node
|
|
8440
|
+
* visited during the depth-first search. It should accept a `BinaryTreeNode` as an argument and
|
|
8441
|
+
* return an optional node or null. The default value for this parameter is `_DEFAULT_NODE_CALLBACK`.
|
|
8442
|
+
* @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `dfs` function specifies
|
|
8443
|
+
* the order in which the nodes are visited during a depth-first search traversal. The possible
|
|
8444
|
+
* values for the `pattern` parameter are:
|
|
8445
|
+
* @param {boolean} [onlyOne=false] - The `onlyOne` parameter in the `dfs` function is a boolean flag
|
|
8446
|
+
* that determines whether the depth-first search should stop after finding the first matching node
|
|
8447
|
+
* or continue searching for all matching nodes. If `onlyOne` is set to `true`, the search will stop
|
|
8448
|
+
* after finding the first matching node
|
|
8449
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined}
|
|
8450
|
+
* startNode - The `startNode` parameter in the `dfs` function can be one of the following types:
|
|
8451
|
+
* @param {IterationType} iterationType - The `iterationType` parameter in the `dfs` function
|
|
8452
|
+
* specifies the type of iteration to be performed during the Depth-First Search traversal. It is
|
|
8453
|
+
* used to determine the order in which nodes are visited during the traversal. The possible values
|
|
8454
|
+
* for `iterationType` are typically defined as an enum or a
|
|
8455
|
+
* @param [includeNull=false] - The `includeNull` parameter in the `dfs` function determines whether
|
|
8456
|
+
* null nodes should be included in the depth-first search traversal. If `includeNull` is set to
|
|
8457
|
+
* `true`, null nodes will be included in the traversal process. If it is set to `false`, null nodes
|
|
8458
|
+
* will be skipped
|
|
8459
|
+
* @returns The `dfs` method is returning an array of the return type of the callback function `C`.
|
|
8460
|
+
*/
|
|
8461
|
+
dfs(callback = this._DEFAULT_NODE_CALLBACK, pattern = "IN", onlyOne = false, startNode = this._root, iterationType = this.iterationType, includeNull = false) {
|
|
8453
8462
|
startNode = this.ensureNode(startNode);
|
|
8454
8463
|
if (!startNode) return [];
|
|
8455
|
-
return this._dfs(callback, pattern, startNode, iterationType, includeNull);
|
|
8464
|
+
return this._dfs(callback, pattern, onlyOne, startNode, iterationType, includeNull);
|
|
8456
8465
|
}
|
|
8457
8466
|
/**
|
|
8458
8467
|
* Time complexity: O(n)
|
|
@@ -8463,7 +8472,7 @@ var dataStructureTyped = (() => {
|
|
|
8463
8472
|
* @param {C} callback - The `callback` parameter in the `bfs` function is a function that will be
|
|
8464
8473
|
* called on each node visited during the breadth-first search traversal. It is a generic type `C`
|
|
8465
8474
|
* that extends the `NodeCallback` type, which takes a parameter of type `BinaryTreeNode<K, V>` or `null`.
|
|
8466
|
-
* @param {
|
|
8475
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the `bfs`
|
|
8467
8476
|
* function represents the starting point for the breadth-first search traversal in a binary tree. It
|
|
8468
8477
|
* can be specified as a key, node, or entry in the binary tree structure. If not provided, the
|
|
8469
8478
|
* default value is the root node of the binary
|
|
@@ -8526,7 +8535,7 @@ var dataStructureTyped = (() => {
|
|
|
8526
8535
|
* structure based on a specified callback and iteration type.
|
|
8527
8536
|
* @param {C} callback - The `callback` parameter is a function that will be called on each leaf node
|
|
8528
8537
|
* in the binary tree. It is optional and defaults to a default callback function if not provided.
|
|
8529
|
-
* @param {
|
|
8538
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the `leaves`
|
|
8530
8539
|
* method is used to specify the starting point for finding and processing the leaves of a binary
|
|
8531
8540
|
* tree. It can be provided as either a key, a node, or an entry in the binary tree structure. If not
|
|
8532
8541
|
* explicitly provided, the default value
|
|
@@ -8574,7 +8583,7 @@ var dataStructureTyped = (() => {
|
|
|
8574
8583
|
* @param {C} callback - The `callback` parameter is a function that will be applied to each node in
|
|
8575
8584
|
* the binary tree during the traversal. It is used to process each node and determine what
|
|
8576
8585
|
* information to include in the output for each level of the tree.
|
|
8577
|
-
* @param {
|
|
8586
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the
|
|
8578
8587
|
* `listLevels` function represents the starting point for traversing the binary tree. It can be
|
|
8579
8588
|
* either a key, a node, or an entry in the binary tree. If not provided, the default value is the
|
|
8580
8589
|
* root of the binary tree.
|
|
@@ -8632,11 +8641,11 @@ var dataStructureTyped = (() => {
|
|
|
8632
8641
|
* Morris Traversal algorithm with different order patterns.
|
|
8633
8642
|
* @param {C} callback - The `callback` parameter in the `morris` function is a function that will be
|
|
8634
8643
|
* called on each node in the binary tree during the traversal. It is of type `C`, which extends the
|
|
8635
|
-
* `NodeCallback<BinaryTreeNode<K, V
|
|
8644
|
+
* `NodeCallback<BinaryTreeNode<K, V> | null>` type. The default value for `callback` is `this._DEFAULT
|
|
8636
8645
|
* @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `morris` function specifies
|
|
8637
8646
|
* the type of Depth-First Search (DFS) order pattern to traverse the binary tree. The possible
|
|
8638
8647
|
* values for the `pattern` parameter are:
|
|
8639
|
-
* @param {
|
|
8648
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the `morris`
|
|
8640
8649
|
* function is the starting point for the Morris traversal algorithm. It represents the root node of
|
|
8641
8650
|
* the binary tree or the node from which the traversal should begin. It can be provided as either a
|
|
8642
8651
|
* key, a node, an entry, or a reference
|
|
@@ -8740,21 +8749,6 @@ var dataStructureTyped = (() => {
|
|
|
8740
8749
|
this._clone(cloned);
|
|
8741
8750
|
return cloned;
|
|
8742
8751
|
}
|
|
8743
|
-
_clone(cloned) {
|
|
8744
|
-
this.bfs(
|
|
8745
|
-
(node) => {
|
|
8746
|
-
if (node === null) cloned.add(null);
|
|
8747
|
-
else {
|
|
8748
|
-
if (this._isMapMode) cloned.add([node.key, this._store.get(node.key)]);
|
|
8749
|
-
else cloned.add([node.key, node.value]);
|
|
8750
|
-
}
|
|
8751
|
-
},
|
|
8752
|
-
this._root,
|
|
8753
|
-
this.iterationType,
|
|
8754
|
-
true
|
|
8755
|
-
);
|
|
8756
|
-
if (this._isMapMode) cloned._store = this._store;
|
|
8757
|
-
}
|
|
8758
8752
|
/**
|
|
8759
8753
|
* Time Complexity: O(n)
|
|
8760
8754
|
* Space Complexity: O(n)
|
|
@@ -8814,7 +8808,7 @@ var dataStructureTyped = (() => {
|
|
|
8814
8808
|
*
|
|
8815
8809
|
* The function `toVisual` in TypeScript overrides the visual representation of a binary tree with
|
|
8816
8810
|
* customizable options for displaying undefined, null, and sentinel nodes.
|
|
8817
|
-
* @param {
|
|
8811
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the
|
|
8818
8812
|
* `toVisual` method is used to specify the starting point for visualizing the binary tree structure.
|
|
8819
8813
|
* It can be a node, key, entry, or the root of the tree. If no specific starting point is provided,
|
|
8820
8814
|
* the default is set to the root
|
|
@@ -8858,7 +8852,7 @@ var dataStructureTyped = (() => {
|
|
|
8858
8852
|
* printing options for the binary tree. It is an optional parameter that allows you to customize how
|
|
8859
8853
|
* the binary tree is printed, such as choosing between different traversal orders or formatting
|
|
8860
8854
|
* options.
|
|
8861
|
-
* @param {
|
|
8855
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the
|
|
8862
8856
|
* `override print` method is used to specify the starting point for printing the binary tree. It can
|
|
8863
8857
|
* be either a key, a node, an entry, or the root of the tree. If no specific starting point is
|
|
8864
8858
|
* provided, the default value is set to
|
|
@@ -8866,21 +8860,36 @@ var dataStructureTyped = (() => {
|
|
|
8866
8860
|
print(options, startNode = this._root) {
|
|
8867
8861
|
console.log(this.toVisual(startNode, options));
|
|
8868
8862
|
}
|
|
8863
|
+
_clone(cloned) {
|
|
8864
|
+
this.bfs(
|
|
8865
|
+
(node) => {
|
|
8866
|
+
if (node === null) cloned.add(null);
|
|
8867
|
+
else {
|
|
8868
|
+
if (this._isMapMode) cloned.add([node.key, this._store.get(node.key)]);
|
|
8869
|
+
else cloned.add([node.key, node.value]);
|
|
8870
|
+
}
|
|
8871
|
+
},
|
|
8872
|
+
this._root,
|
|
8873
|
+
this.iterationType,
|
|
8874
|
+
true
|
|
8875
|
+
);
|
|
8876
|
+
if (this._isMapMode) cloned._store = this._store;
|
|
8877
|
+
}
|
|
8869
8878
|
/**
|
|
8870
8879
|
* Time Complexity: O(1)
|
|
8871
8880
|
* Space Complexity: O(1)
|
|
8872
8881
|
*
|
|
8873
8882
|
* The function `keyValueNodeEntryRawToNodeAndValue` converts various input types into a node object
|
|
8874
8883
|
* or returns null.
|
|
8875
|
-
* @param {
|
|
8884
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The
|
|
8876
8885
|
* `keyValueNodeEntryRawToNodeAndValue` function takes in a parameter `keyNodeOrEntry`, which
|
|
8877
|
-
* can be of type `
|
|
8886
|
+
* can be of type `K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined ` or `R`. This parameter represents either a key, a
|
|
8878
8887
|
* node, an entry
|
|
8879
8888
|
* @param {V} [value] - The `value` parameter in the `keyValueNodeEntryRawToNodeAndValue` function is
|
|
8880
8889
|
* an optional parameter of type `V`. It represents the value associated with the key in the node
|
|
8881
8890
|
* being created. If a `value` is provided, it will be used when creating the node. If
|
|
8882
8891
|
* @returns The `keyValueNodeEntryRawToNodeAndValue` function returns an optional node
|
|
8883
|
-
* (`
|
|
8892
|
+
* (`BinaryTreeNode<K, V> | null | undefined`) based on the input parameters provided. The function checks the type of the
|
|
8884
8893
|
* input parameter (`keyNodeOrEntry`) and processes it accordingly to return a node or null
|
|
8885
8894
|
* value.
|
|
8886
8895
|
*/
|
|
@@ -8901,45 +8910,48 @@ var dataStructureTyped = (() => {
|
|
|
8901
8910
|
* Time complexity: O(n)
|
|
8902
8911
|
* Space complexity: O(n)
|
|
8903
8912
|
*
|
|
8904
|
-
* The `_dfs` function performs a depth-first search traversal on a binary tree
|
|
8905
|
-
*
|
|
8913
|
+
* The `_dfs` function performs a depth-first search traversal on a binary tree, with customizable
|
|
8914
|
+
* options for traversal order and node processing.
|
|
8906
8915
|
* @param {C} callback - The `callback` parameter in the `_dfs` method is a function that will be
|
|
8907
|
-
* called on each node visited during the depth-first search traversal. It is
|
|
8908
|
-
* extends `NodeCallback<
|
|
8916
|
+
* called on each node visited during the depth-first search traversal. It is a generic type `C` that
|
|
8917
|
+
* extends `NodeCallback<BinaryTreeNode<K, V> | null>`. The default value for `callback`
|
|
8909
8918
|
* @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `_dfs` method specifies the
|
|
8910
|
-
* order in which the nodes are visited during
|
|
8911
|
-
*
|
|
8912
|
-
* @param {
|
|
8913
|
-
*
|
|
8914
|
-
*
|
|
8915
|
-
*
|
|
8919
|
+
* order in which the nodes are visited during a depth-first search traversal. It can have one of the
|
|
8920
|
+
* following values:
|
|
8921
|
+
* @param {boolean} [onlyOne=false] - The `onlyOne` parameter in the `_dfs` method is a boolean flag
|
|
8922
|
+
* that determines whether the traversal should stop after processing a single node. If `onlyOne` is
|
|
8923
|
+
* set to `true`, the traversal will return as soon as a single node is processed. If it is set to
|
|
8924
|
+
* `false
|
|
8925
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined}
|
|
8926
|
+
* startNode - The `startNode` parameter in the `_dfs` method is used to specify the starting node
|
|
8927
|
+
* for the depth-first search traversal. It can be provided in different forms:
|
|
8916
8928
|
* @param {IterationType} iterationType - The `iterationType` parameter in the `_dfs` method
|
|
8917
|
-
* specifies the
|
|
8918
|
-
*
|
|
8919
|
-
* @param [includeNull=false] - The `includeNull` parameter in the `_dfs` method
|
|
8920
|
-
*
|
|
8921
|
-
*
|
|
8922
|
-
*
|
|
8923
|
-
* @param shouldVisitLeft - The `shouldVisitLeft` parameter
|
|
8924
|
-
*
|
|
8925
|
-
*
|
|
8926
|
-
*
|
|
8927
|
-
* @param shouldVisitRight - The `shouldVisitRight` parameter
|
|
8928
|
-
*
|
|
8929
|
-
*
|
|
8930
|
-
*
|
|
8931
|
-
* @param shouldVisitRoot - The `shouldVisitRoot` parameter
|
|
8932
|
-
*
|
|
8933
|
-
*
|
|
8934
|
-
*
|
|
8935
|
-
* @param shouldProcessRoot - The `shouldProcessRoot` parameter
|
|
8936
|
-
*
|
|
8937
|
-
*
|
|
8938
|
-
*
|
|
8939
|
-
* @returns The
|
|
8940
|
-
*
|
|
8941
|
-
*/
|
|
8942
|
-
_dfs(callback = this._DEFAULT_NODE_CALLBACK, pattern = "IN", startNode = this._root, iterationType = this.iterationType, includeNull = false, shouldVisitLeft = (node) => !!node, shouldVisitRight = (node) => !!node, shouldVisitRoot = (node) => {
|
|
8929
|
+
* specifies whether the traversal should be done recursively or iteratively. It can have two
|
|
8930
|
+
* possible values:
|
|
8931
|
+
* @param [includeNull=false] - The `includeNull` parameter in the `_dfs` method determines whether
|
|
8932
|
+
* null nodes should be included in the traversal process. If `includeNull` is set to `true`, the
|
|
8933
|
+
* method will consider null nodes as valid nodes to visit or process. If `includeNull` is set to
|
|
8934
|
+
* `false`,
|
|
8935
|
+
* @param shouldVisitLeft - The `shouldVisitLeft` parameter in the `_dfs` method is a function that
|
|
8936
|
+
* determines whether the left child of a node should be visited during the Depth-First Search
|
|
8937
|
+
* traversal. By default, it checks if the node is not null or undefined before visiting the left
|
|
8938
|
+
* child. You can customize this behavior
|
|
8939
|
+
* @param shouldVisitRight - The `shouldVisitRight` parameter in the `_dfs` method is a function that
|
|
8940
|
+
* determines whether to visit the right child node of the current node during a depth-first search
|
|
8941
|
+
* traversal. The default implementation of this function checks if the node is not null or undefined
|
|
8942
|
+
* before deciding to visit it.
|
|
8943
|
+
* @param shouldVisitRoot - The `shouldVisitRoot` parameter in the `_dfs` method is a function that
|
|
8944
|
+
* determines whether a given node should be visited during the depth-first search traversal. The
|
|
8945
|
+
* function takes a node as an argument and returns a boolean value indicating whether the node
|
|
8946
|
+
* should be visited.
|
|
8947
|
+
* @param shouldProcessRoot - The `shouldProcessRoot` parameter in the `_dfs` method is a function
|
|
8948
|
+
* that determines whether the root node should be processed during the Depth-First Search traversal.
|
|
8949
|
+
* It takes a node (BinaryTreeNode<K, V> | null | undefined) as input and returns a boolean value. If
|
|
8950
|
+
* the function
|
|
8951
|
+
* @returns The `_dfs` method returns an array of the return type of the provided callback function
|
|
8952
|
+
* `C`.
|
|
8953
|
+
*/
|
|
8954
|
+
_dfs(callback = this._DEFAULT_NODE_CALLBACK, pattern = "IN", onlyOne = false, startNode = this._root, iterationType = this.iterationType, includeNull = false, shouldVisitLeft = (node) => !!node, shouldVisitRight = (node) => !!node, shouldVisitRoot = (node) => {
|
|
8943
8955
|
if (includeNull) return this.isRealNodeOrNull(node);
|
|
8944
8956
|
return this.isRealNode(node);
|
|
8945
8957
|
}, shouldProcessRoot = (node) => this.isRealNodeOrNull(node)) {
|
|
@@ -8950,26 +8962,35 @@ var dataStructureTyped = (() => {
|
|
|
8950
8962
|
const dfs = (node) => {
|
|
8951
8963
|
if (!shouldVisitRoot(node)) return;
|
|
8952
8964
|
const visitLeft = () => {
|
|
8953
|
-
if (shouldVisitLeft(node)) dfs(node == null ? void 0 : node.left);
|
|
8965
|
+
if (shouldVisitLeft(node) && (node == null ? void 0 : node.left) !== void 0) dfs(node == null ? void 0 : node.left);
|
|
8954
8966
|
};
|
|
8955
8967
|
const visitRight = () => {
|
|
8956
|
-
if (shouldVisitRight(node)) dfs(node == null ? void 0 : node.right);
|
|
8968
|
+
if (shouldVisitRight(node) && (node == null ? void 0 : node.right) !== void 0) dfs(node == null ? void 0 : node.right);
|
|
8957
8969
|
};
|
|
8958
8970
|
switch (pattern) {
|
|
8959
8971
|
case "IN":
|
|
8960
8972
|
visitLeft();
|
|
8961
|
-
if (shouldProcessRoot(node))
|
|
8973
|
+
if (shouldProcessRoot(node)) {
|
|
8974
|
+
ans.push(callback(node));
|
|
8975
|
+
if (onlyOne) return;
|
|
8976
|
+
}
|
|
8962
8977
|
visitRight();
|
|
8963
8978
|
break;
|
|
8964
8979
|
case "PRE":
|
|
8965
|
-
if (shouldProcessRoot(node))
|
|
8980
|
+
if (shouldProcessRoot(node)) {
|
|
8981
|
+
ans.push(callback(node));
|
|
8982
|
+
if (onlyOne) return;
|
|
8983
|
+
}
|
|
8966
8984
|
visitLeft();
|
|
8967
8985
|
visitRight();
|
|
8968
8986
|
break;
|
|
8969
8987
|
case "POST":
|
|
8970
8988
|
visitLeft();
|
|
8971
8989
|
visitRight();
|
|
8972
|
-
if (shouldProcessRoot(node))
|
|
8990
|
+
if (shouldProcessRoot(node)) {
|
|
8991
|
+
ans.push(callback(node));
|
|
8992
|
+
if (onlyOne) return;
|
|
8993
|
+
}
|
|
8973
8994
|
break;
|
|
8974
8995
|
}
|
|
8975
8996
|
};
|
|
@@ -8992,7 +9013,10 @@ var dataStructureTyped = (() => {
|
|
|
8992
9013
|
if (cur === void 0) continue;
|
|
8993
9014
|
if (!shouldVisitRoot(cur.node)) continue;
|
|
8994
9015
|
if (cur.opt === 1 /* PROCESS */) {
|
|
8995
|
-
if (shouldProcessRoot(cur.node)
|
|
9016
|
+
if (shouldProcessRoot(cur.node) && cur.node !== void 0) {
|
|
9017
|
+
ans.push(callback(cur.node));
|
|
9018
|
+
if (onlyOne) return ans;
|
|
9019
|
+
}
|
|
8996
9020
|
} else {
|
|
8997
9021
|
switch (pattern) {
|
|
8998
9022
|
case "IN":
|
|
@@ -9119,12 +9143,12 @@ var dataStructureTyped = (() => {
|
|
|
9119
9143
|
* Space Complexity: O(1)
|
|
9120
9144
|
*
|
|
9121
9145
|
* The _swapProperties function swaps key and value properties between two nodes in a binary tree.
|
|
9122
|
-
* @param {
|
|
9146
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } srcNode - The `srcNode` parameter in the
|
|
9123
9147
|
* `_swapProperties` method can be either a BTNRep object containing key and value
|
|
9124
9148
|
* properties, or it can be of type R.
|
|
9125
|
-
* @param {
|
|
9149
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } destNode - The `destNode` parameter in the
|
|
9126
9150
|
* `_swapProperties` method represents the node or entry where the properties will be swapped with
|
|
9127
|
-
* the `srcNode`. It can be of type `
|
|
9151
|
+
* the `srcNode`. It can be of type `K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined ` or `R`. The method ensures that
|
|
9128
9152
|
* both `srcNode
|
|
9129
9153
|
* @returns The `_swapProperties` method returns either the `destNode` with its key and value swapped
|
|
9130
9154
|
* with the `srcNode`, or `undefined` if either `srcNode` or `destNode` is falsy.
|
|
@@ -9181,7 +9205,7 @@ var dataStructureTyped = (() => {
|
|
|
9181
9205
|
*
|
|
9182
9206
|
* The function _setRoot sets the root node of a data structure while updating the parent reference
|
|
9183
9207
|
* of the previous root node.
|
|
9184
|
-
* @param v - The parameter `v` in the `_setRoot` method is of type `
|
|
9208
|
+
* @param v - The parameter `v` in the `_setRoot` method is of type `BinaryTreeNode<K, V> | null | undefined`, which means
|
|
9185
9209
|
* it can either be an optional `BinaryTreeNode<K, V>` type or `null`.
|
|
9186
9210
|
*/
|
|
9187
9211
|
_setRoot(v) {
|
|
@@ -9196,7 +9220,7 @@ var dataStructureTyped = (() => {
|
|
|
9196
9220
|
*
|
|
9197
9221
|
* The function `_ensurePredicate` in TypeScript ensures that the input is converted into a valid
|
|
9198
9222
|
* predicate function for a binary tree node.
|
|
9199
|
-
* @param {
|
|
9223
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate - The
|
|
9200
9224
|
* `_ensurePredicate` method in the provided code snippet is responsible for ensuring that the input
|
|
9201
9225
|
* parameter `keyNodeEntryOrPredicate` is transformed into a valid predicate function that can be
|
|
9202
9226
|
* used for filtering nodes in a binary tree.
|
|
@@ -9210,9 +9234,15 @@ var dataStructureTyped = (() => {
|
|
|
9210
9234
|
return (node) => node === keyNodeEntryOrPredicate;
|
|
9211
9235
|
if (this.isEntry(keyNodeEntryOrPredicate)) {
|
|
9212
9236
|
const [key] = keyNodeEntryOrPredicate;
|
|
9213
|
-
return (node) =>
|
|
9237
|
+
return (node) => {
|
|
9238
|
+
if (!node) return false;
|
|
9239
|
+
return node.key === key;
|
|
9240
|
+
};
|
|
9214
9241
|
}
|
|
9215
|
-
return (node) =>
|
|
9242
|
+
return (node) => {
|
|
9243
|
+
if (!node) return false;
|
|
9244
|
+
return node.key === keyNodeEntryOrPredicate;
|
|
9245
|
+
};
|
|
9216
9246
|
}
|
|
9217
9247
|
/**
|
|
9218
9248
|
* Time Complexity: O(1)
|
|
@@ -9235,8 +9265,8 @@ var dataStructureTyped = (() => {
|
|
|
9235
9265
|
*
|
|
9236
9266
|
* The function `_extractKey` in TypeScript returns the key from a given input, which can be a node,
|
|
9237
9267
|
* entry, raw data, or null/undefined.
|
|
9238
|
-
* @param {
|
|
9239
|
-
* TypeScript method that takes in a parameter `keyNodeOrEntry` of type `
|
|
9268
|
+
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The `_extractKey` method you provided is a
|
|
9269
|
+
* TypeScript method that takes in a parameter `keyNodeOrEntry` of type `K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined `,
|
|
9240
9270
|
* where `BTNRep` is a generic type with keys `K`, `V`, and `BinaryTreeNode<K, V>`, and `
|
|
9241
9271
|
* @returns The `_extractKey` method returns the key value extracted from the `keyNodeOrEntry`
|
|
9242
9272
|
* parameter. The return value can be a key value of type `K`, `null`, or `undefined`, depending on
|
|
@@ -9331,7 +9361,7 @@ var dataStructureTyped = (() => {
|
|
|
9331
9361
|
* This TypeScript constructor initializes a binary search tree with optional options and adds
|
|
9332
9362
|
* elements if provided.
|
|
9333
9363
|
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor is an
|
|
9334
|
-
* iterable that can contain elements of type `
|
|
9364
|
+
* iterable that can contain elements of type `K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined ` or `R`. It is used to
|
|
9335
9365
|
* initialize the binary search tree with keys, nodes, entries, or raw data.
|
|
9336
9366
|
* @param [options] - The `options` parameter is an optional object that can contain the following
|
|
9337
9367
|
* properties:
|
|
@@ -9417,7 +9447,7 @@ var dataStructureTyped = (() => {
|
|
|
9417
9447
|
*
|
|
9418
9448
|
* The function ensures the existence of a node in a data structure and returns it, or undefined if
|
|
9419
9449
|
* it doesn't exist.
|
|
9420
|
-
* @param {
|
|
9450
|
+
* @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The parameter
|
|
9421
9451
|
* `keyNodeOrEntry` can accept a value of type `R`, which represents the key, node,
|
|
9422
9452
|
* entry, or raw element that needs to be ensured in the tree.
|
|
9423
9453
|
* @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
|
|
@@ -9435,8 +9465,8 @@ var dataStructureTyped = (() => {
|
|
|
9435
9465
|
* Space Complexity: O(1)
|
|
9436
9466
|
*
|
|
9437
9467
|
* The function checks if the input is an instance of the BSTNode class.
|
|
9438
|
-
* @param {
|
|
9439
|
-
* `keyNodeOrEntry` can be of type `R` or `
|
|
9468
|
+
* @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The parameter
|
|
9469
|
+
* `keyNodeOrEntry` can be of type `R` or `K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined `.
|
|
9440
9470
|
* @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
|
|
9441
9471
|
* an instance of the `BSTNode` class.
|
|
9442
9472
|
*/
|
|
@@ -9462,8 +9492,8 @@ var dataStructureTyped = (() => {
|
|
|
9462
9492
|
* Space Complexity: O(log n)
|
|
9463
9493
|
*
|
|
9464
9494
|
* The `add` function in TypeScript adds a new node to a binary search tree based on the key value.
|
|
9465
|
-
* @param {
|
|
9466
|
-
* `keyNodeOrEntry` can accept a value of type `R` or `
|
|
9495
|
+
* @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The parameter
|
|
9496
|
+
* `keyNodeOrEntry` can accept a value of type `R` or `K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined `.
|
|
9467
9497
|
* @param {V} [value] - The `value` parameter is an optional value that can be associated with the
|
|
9468
9498
|
* key in the binary search tree. If provided, it will be stored in the node along with the key.
|
|
9469
9499
|
* @returns a boolean value.
|
|
@@ -9616,7 +9646,7 @@ var dataStructureTyped = (() => {
|
|
|
9616
9646
|
*
|
|
9617
9647
|
* The function `search` in TypeScript overrides the search behavior in a binary tree structure based
|
|
9618
9648
|
* on specified criteria.
|
|
9619
|
-
* @param {
|
|
9649
|
+
* @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>>} keyNodeEntryOrPredicate - The
|
|
9620
9650
|
* `keyNodeEntryOrPredicate` parameter in the `override search` method can accept one of the
|
|
9621
9651
|
* following types:
|
|
9622
9652
|
* @param [onlyOne=false] - The `onlyOne` parameter is a boolean flag that determines whether the
|
|
@@ -9624,9 +9654,9 @@ var dataStructureTyped = (() => {
|
|
|
9624
9654
|
* search will return as soon as a matching node is found. If `onlyOne` is set to `false`, the
|
|
9625
9655
|
* @param {C} callback - The `callback` parameter in the `override search` function is a function
|
|
9626
9656
|
* that will be called on each node that matches the search criteria. It is of type `C`, which
|
|
9627
|
-
* extends `NodeCallback<BSTNode<K, V
|
|
9657
|
+
* extends `NodeCallback<BSTNode<K, V> | null>`. The callback function should accept a node of type `BSTNode<K, V>` as its
|
|
9628
9658
|
* argument and
|
|
9629
|
-
* @param {
|
|
9659
|
+
* @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the `override search`
|
|
9630
9660
|
* method represents the node from which the search operation will begin. It is the starting point
|
|
9631
9661
|
* for searching within the tree data structure. The method ensures that the `startNode` is a valid
|
|
9632
9662
|
* node before proceeding with the search operation. If the `
|
|
@@ -9646,75 +9676,58 @@ var dataStructureTyped = (() => {
|
|
|
9646
9676
|
let predicate;
|
|
9647
9677
|
const isRange = this.isRange(keyNodeEntryOrPredicate);
|
|
9648
9678
|
if (isRange) {
|
|
9649
|
-
predicate = (node) =>
|
|
9679
|
+
predicate = (node) => {
|
|
9680
|
+
if (!node) return false;
|
|
9681
|
+
return keyNodeEntryOrPredicate.isInRange(node.key, this._comparator);
|
|
9682
|
+
};
|
|
9650
9683
|
} else {
|
|
9651
9684
|
predicate = this._ensurePredicate(keyNodeEntryOrPredicate);
|
|
9652
9685
|
}
|
|
9653
|
-
const
|
|
9686
|
+
const shouldVisitLeft = (cur) => {
|
|
9687
|
+
if (!cur) return false;
|
|
9688
|
+
if (!this.isRealNode(cur.left)) return false;
|
|
9654
9689
|
if (isRange) {
|
|
9655
9690
|
const range = keyNodeEntryOrPredicate;
|
|
9656
9691
|
const leftS = this.isReverse ? range.high : range.low;
|
|
9657
9692
|
const leftI = this.isReverse ? range.includeHigh : range.includeLow;
|
|
9658
9693
|
return leftI && this._compare(cur.key, leftS) >= 0 || !leftI && this._compare(cur.key, leftS) > 0;
|
|
9659
9694
|
}
|
|
9660
|
-
|
|
9695
|
+
if (!isRange && !this._isPredicate(keyNodeEntryOrPredicate)) {
|
|
9696
|
+
const benchmarkKey = this._extractKey(keyNodeEntryOrPredicate);
|
|
9697
|
+
return benchmarkKey !== null && benchmarkKey !== void 0 && this._compare(cur.key, benchmarkKey) > 0;
|
|
9698
|
+
}
|
|
9699
|
+
return true;
|
|
9661
9700
|
};
|
|
9662
|
-
const
|
|
9701
|
+
const shouldVisitRight = (cur) => {
|
|
9702
|
+
if (!cur) return false;
|
|
9703
|
+
if (!this.isRealNode(cur.right)) return false;
|
|
9663
9704
|
if (isRange) {
|
|
9664
9705
|
const range = keyNodeEntryOrPredicate;
|
|
9665
9706
|
const rightS = this.isReverse ? range.low : range.high;
|
|
9666
9707
|
const rightI = this.isReverse ? range.includeLow : range.includeLow;
|
|
9667
9708
|
return rightI && this._compare(cur.key, rightS) <= 0 || !rightI && this._compare(cur.key, rightS) < 0;
|
|
9668
9709
|
}
|
|
9669
|
-
|
|
9710
|
+
if (!isRange && !this._isPredicate(keyNodeEntryOrPredicate)) {
|
|
9711
|
+
const benchmarkKey = this._extractKey(keyNodeEntryOrPredicate);
|
|
9712
|
+
return benchmarkKey !== null && benchmarkKey !== void 0 && this._compare(cur.key, benchmarkKey) < 0;
|
|
9713
|
+
}
|
|
9714
|
+
return true;
|
|
9670
9715
|
};
|
|
9671
|
-
|
|
9672
|
-
|
|
9673
|
-
|
|
9674
|
-
|
|
9675
|
-
|
|
9676
|
-
|
|
9677
|
-
|
|
9678
|
-
|
|
9679
|
-
|
|
9680
|
-
|
|
9681
|
-
|
|
9682
|
-
|
|
9683
|
-
|
|
9684
|
-
if (this.isRealNode(cur.left) && benchmarkKey !== null && benchmarkKey !== void 0 && this._compare(cur.key, benchmarkKey) > 0)
|
|
9685
|
-
dfs(cur.left);
|
|
9686
|
-
if (this.isRealNode(cur.right) && benchmarkKey !== null && benchmarkKey !== void 0 && this._compare(cur.key, benchmarkKey) < 0)
|
|
9687
|
-
dfs(cur.right);
|
|
9688
|
-
} else {
|
|
9689
|
-
if (this.isRealNode(cur.left)) dfs(cur.left);
|
|
9690
|
-
if (this.isRealNode(cur.right)) dfs(cur.right);
|
|
9691
|
-
}
|
|
9692
|
-
};
|
|
9693
|
-
dfs(startNode);
|
|
9694
|
-
} else {
|
|
9695
|
-
const stack = [startNode];
|
|
9696
|
-
while (stack.length > 0) {
|
|
9697
|
-
const cur = stack.pop();
|
|
9698
|
-
if (predicate(cur)) {
|
|
9699
|
-
ans.push(callback(cur));
|
|
9700
|
-
if (onlyOne) return ans;
|
|
9701
|
-
}
|
|
9702
|
-
if (isRange) {
|
|
9703
|
-
if (this.isRealNode(cur.left) && isToLeftByRange(cur)) stack.push(cur.left);
|
|
9704
|
-
if (this.isRealNode(cur.right) && isToRightByRange(cur)) stack.push(cur.right);
|
|
9705
|
-
} else if (!this._isPredicate(keyNodeEntryOrPredicate)) {
|
|
9706
|
-
const benchmarkKey = this._extractKey(keyNodeEntryOrPredicate);
|
|
9707
|
-
if (this.isRealNode(cur.right) && benchmarkKey !== null && benchmarkKey !== void 0 && this._compare(cur.key, benchmarkKey) < 0)
|
|
9708
|
-
stack.push(cur.right);
|
|
9709
|
-
if (this.isRealNode(cur.left) && benchmarkKey !== null && benchmarkKey !== void 0 && this._compare(cur.key, benchmarkKey) > 0)
|
|
9710
|
-
stack.push(cur.left);
|
|
9711
|
-
} else {
|
|
9712
|
-
if (this.isRealNode(cur.right)) stack.push(cur.right);
|
|
9713
|
-
if (this.isRealNode(cur.left)) stack.push(cur.left);
|
|
9714
|
-
}
|
|
9716
|
+
return super._dfs(
|
|
9717
|
+
callback,
|
|
9718
|
+
"IN",
|
|
9719
|
+
onlyOne,
|
|
9720
|
+
startNode,
|
|
9721
|
+
iterationType,
|
|
9722
|
+
false,
|
|
9723
|
+
shouldVisitLeft,
|
|
9724
|
+
shouldVisitRight,
|
|
9725
|
+
() => true,
|
|
9726
|
+
(cur) => {
|
|
9727
|
+
if (cur) return predicate(cur);
|
|
9728
|
+
return false;
|
|
9715
9729
|
}
|
|
9716
|
-
|
|
9717
|
-
return ans;
|
|
9730
|
+
);
|
|
9718
9731
|
}
|
|
9719
9732
|
/**
|
|
9720
9733
|
* Time Complexity: O(log n)
|
|
@@ -9725,9 +9738,9 @@ var dataStructureTyped = (() => {
|
|
|
9725
9738
|
* either a `Range` object or an array of two elements representing the range boundaries.
|
|
9726
9739
|
* @param {C} callback - The `callback` parameter in the `rangeSearch` function is a callback
|
|
9727
9740
|
* function that is used to process each node that is found within the specified range during the
|
|
9728
|
-
* search operation. It is of type `NodeCallback<BSTNode<K, V
|
|
9741
|
+
* search operation. It is of type `NodeCallback<BSTNode<K, V> | null>`, where `BSTNode<K, V>` is the type of nodes in the
|
|
9729
9742
|
* data structure.
|
|
9730
|
-
* @param {
|
|
9743
|
+
* @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the `rangeSearch`
|
|
9731
9744
|
* function represents the node from which the search for nodes within the specified range will
|
|
9732
9745
|
* begin. It is the starting point for the range search operation.
|
|
9733
9746
|
* @param {IterationType} iterationType - The `iterationType` parameter in the `rangeSearch` function
|
|
@@ -9746,8 +9759,8 @@ var dataStructureTyped = (() => {
|
|
|
9746
9759
|
* Space Complexity: O(log n)
|
|
9747
9760
|
*
|
|
9748
9761
|
* This function retrieves a node based on a given keyNodeEntryOrPredicate within a binary search tree structure.
|
|
9749
|
-
* @param {
|
|
9750
|
-
* parameter can be of type `
|
|
9762
|
+
* @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>>} keyNodeEntryOrPredicate - The `keyNodeEntryOrPredicate`
|
|
9763
|
+
* parameter can be of type `K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined `, `R`, or `NodePredicate<BSTNode<K, V>>`.
|
|
9751
9764
|
* @param {BSTNOptKeyOrNode<K, BSTNode<K, V>>} startNode - The `startNode` parameter in the `getNode` method
|
|
9752
9765
|
* is used to specify the starting point for searching nodes in the binary search tree. If no
|
|
9753
9766
|
* specific starting point is provided, the default value is set to `this._root`, which is the root
|
|
@@ -9769,24 +9782,30 @@ var dataStructureTyped = (() => {
|
|
|
9769
9782
|
* Time complexity: O(n)
|
|
9770
9783
|
* Space complexity: O(n)
|
|
9771
9784
|
*
|
|
9772
|
-
* The function overrides the
|
|
9773
|
-
* the
|
|
9785
|
+
* The function `dfs` in TypeScript overrides the base class method with default parameters and
|
|
9786
|
+
* returns the result of the super class `dfs` method.
|
|
9774
9787
|
* @param {C} callback - The `callback` parameter is a function that will be called for each node
|
|
9775
|
-
* during the
|
|
9776
|
-
* `
|
|
9777
|
-
* @param {DFSOrderPattern} [pattern=IN] - The
|
|
9778
|
-
* order in which the Depth-First Search (DFS)
|
|
9779
|
-
*
|
|
9780
|
-
* @param {
|
|
9781
|
-
*
|
|
9782
|
-
*
|
|
9783
|
-
*
|
|
9784
|
-
*
|
|
9785
|
-
* following
|
|
9786
|
-
* @
|
|
9788
|
+
* visited during the Depth-First Search traversal. It is a generic type `C` that extends the
|
|
9789
|
+
* `NodeCallback` interface for `BSTNode<K, V>`. The default value for `callback` is `this._
|
|
9790
|
+
* @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `override dfs` method
|
|
9791
|
+
* specifies the order in which the Depth-First Search (DFS) traversal should be performed on the
|
|
9792
|
+
* Binary Search Tree (BST). The possible values for the `pattern` parameter are:
|
|
9793
|
+
* @param {boolean} [onlyOne=false] - The `onlyOne` parameter in the `override dfs` method is a
|
|
9794
|
+
* boolean flag that indicates whether you want to stop the depth-first search traversal after
|
|
9795
|
+
* finding the first matching node or continue searching for all matching nodes. If `onlyOne` is set
|
|
9796
|
+
* to `true`, the traversal will stop after finding
|
|
9797
|
+
* @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} startNode -
|
|
9798
|
+
* The `startNode` parameter in the `override dfs` method can be one of the following types:
|
|
9799
|
+
* @param {IterationType} iterationType - The `iterationType` parameter in the `override dfs` method
|
|
9800
|
+
* specifies the type of iteration to be performed during the Depth-First Search (DFS) traversal of a
|
|
9801
|
+
* Binary Search Tree (BST). It is used to determine the order in which nodes are visited during the
|
|
9802
|
+
* traversal. The possible values for `
|
|
9803
|
+
* @returns The `override` function is returning the result of calling the `dfs` method from the
|
|
9804
|
+
* superclass, with the provided arguments `callback`, `pattern`, `onlyOne`, `startNode`, and
|
|
9805
|
+
* `iterationType`. The return type is an array of the return type of the callback function `C`.
|
|
9787
9806
|
*/
|
|
9788
|
-
dfs(callback = this._DEFAULT_NODE_CALLBACK, pattern = "IN", startNode = this._root, iterationType = this.iterationType) {
|
|
9789
|
-
return super.dfs(callback, pattern, startNode, iterationType);
|
|
9807
|
+
dfs(callback = this._DEFAULT_NODE_CALLBACK, pattern = "IN", onlyOne = false, startNode = this._root, iterationType = this.iterationType) {
|
|
9808
|
+
return super.dfs(callback, pattern, onlyOne, startNode, iterationType);
|
|
9790
9809
|
}
|
|
9791
9810
|
/**
|
|
9792
9811
|
* Time complexity: O(n)
|
|
@@ -9797,7 +9816,7 @@ var dataStructureTyped = (() => {
|
|
|
9797
9816
|
* @param {C} callback - The `callback` parameter is a function that will be called for each node
|
|
9798
9817
|
* visited during the breadth-first search. It should take a single argument, which is the current
|
|
9799
9818
|
* node being visited, and it can return a value of any type.
|
|
9800
|
-
* @param {
|
|
9819
|
+
* @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter is the starting
|
|
9801
9820
|
* point for the breadth-first search. It can be either a root node, a key-value pair, or an entry
|
|
9802
9821
|
* object. If no value is provided, the default value is the root of the tree.
|
|
9803
9822
|
* @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
|
|
@@ -9815,9 +9834,9 @@ var dataStructureTyped = (() => {
|
|
|
9815
9834
|
* The function overrides the listLevels method from the superclass and returns an array of arrays
|
|
9816
9835
|
* containing the results of the callback function applied to each level of the tree.
|
|
9817
9836
|
* @param {C} callback - The `callback` parameter is a generic type `C` that extends
|
|
9818
|
-
* `NodeCallback<BSTNode<K, V
|
|
9837
|
+
* `NodeCallback<BSTNode<K, V> | null>`. It represents a callback function that will be called for each node in the
|
|
9819
9838
|
* tree during the iteration process.
|
|
9820
|
-
* @param {
|
|
9839
|
+
* @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter is the starting
|
|
9821
9840
|
* point for listing the levels of the binary tree. It can be either a root node of the tree, a
|
|
9822
9841
|
* key-value pair representing a node in the tree, or a key representing a node in the tree. If no
|
|
9823
9842
|
* value is provided, the root of
|
|
@@ -9841,7 +9860,7 @@ var dataStructureTyped = (() => {
|
|
|
9841
9860
|
* @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to
|
|
9842
9861
|
* traverse nodes that are lesser, greater, or both than the `targetNode`. It accepts the values -1,
|
|
9843
9862
|
* 0, or 1, where:
|
|
9844
|
-
* @param {
|
|
9863
|
+
* @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } targetNode - The `targetNode` parameter is the node in
|
|
9845
9864
|
* the binary tree that you want to start traversing from. It can be specified either by providing
|
|
9846
9865
|
* the key of the node, the node itself, or an entry containing the key and value of the node. If no
|
|
9847
9866
|
* `targetNode` is provided,
|
|
@@ -9900,8 +9919,8 @@ var dataStructureTyped = (() => {
|
|
|
9900
9919
|
if (l > r) return;
|
|
9901
9920
|
const m = l + Math.floor((r - l) / 2);
|
|
9902
9921
|
const midNode = sorted[m];
|
|
9903
|
-
if (this._isMapMode) this.add(midNode.key);
|
|
9904
|
-
else this.add([midNode.key, midNode.value]);
|
|
9922
|
+
if (this._isMapMode && midNode !== null) this.add(midNode.key);
|
|
9923
|
+
else if (midNode !== null) this.add([midNode.key, midNode.value]);
|
|
9905
9924
|
buildBalanceBST(l, m - 1);
|
|
9906
9925
|
buildBalanceBST(m + 1, r);
|
|
9907
9926
|
};
|
|
@@ -9916,8 +9935,8 @@ var dataStructureTyped = (() => {
|
|
|
9916
9935
|
if (l <= r) {
|
|
9917
9936
|
const m = l + Math.floor((r - l) / 2);
|
|
9918
9937
|
const midNode = sorted[m];
|
|
9919
|
-
if (this._isMapMode) this.add(midNode.key);
|
|
9920
|
-
else this.add([midNode.key, midNode.value]);
|
|
9938
|
+
if (this._isMapMode && midNode !== null) this.add(midNode.key);
|
|
9939
|
+
else if (midNode !== null) this.add([midNode.key, midNode.value]);
|
|
9921
9940
|
stack.push([m + 1, r]);
|
|
9922
9941
|
stack.push([l, m - 1]);
|
|
9923
9942
|
}
|
|
@@ -10020,8 +10039,8 @@ var dataStructureTyped = (() => {
|
|
|
10020
10039
|
* Space Complexity: O(1)
|
|
10021
10040
|
*
|
|
10022
10041
|
* The function overrides a method and converts a key, value pair or entry or raw element to a node.
|
|
10023
|
-
* @param {
|
|
10024
|
-
* type R or
|
|
10042
|
+
* @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - A variable that can be of
|
|
10043
|
+
* type R or K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined . It represents either a key, a node, an entry, or a raw
|
|
10025
10044
|
* element.
|
|
10026
10045
|
* @param {V} [value] - The `value` parameter is an optional value of type `V`. It represents the
|
|
10027
10046
|
* value associated with a key in a key-value pair.
|
|
@@ -10669,7 +10688,8 @@ var dataStructureTyped = (() => {
|
|
|
10669
10688
|
* This TypeScript constructor initializes an AVLTree with keys, nodes, entries, or raw data provided
|
|
10670
10689
|
* in an iterable format.
|
|
10671
10690
|
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor is an
|
|
10672
|
-
* iterable that can contain either `
|
|
10691
|
+
* iterable that can contain either `
|
|
10692
|
+
K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined ` objects or `R` objects. It is
|
|
10673
10693
|
* used to initialize the AVLTree with key-value pairs or raw data entries. If provided
|
|
10674
10694
|
* @param [options] - The `options` parameter in the constructor is of type `AVLTreeOptions<K, V,
|
|
10675
10695
|
* R>`. It is an optional parameter that allows you to specify additional options for configuring the
|
|
@@ -10719,8 +10739,9 @@ var dataStructureTyped = (() => {
|
|
|
10719
10739
|
* Space Complexity: O(1)
|
|
10720
10740
|
*
|
|
10721
10741
|
* The function checks if the input is an instance of AVLTreeNode.
|
|
10722
|
-
* @param {
|
|
10723
|
-
* `keyNodeOrEntry` can be of type `R` or `
|
|
10742
|
+
* @param {K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The parameter
|
|
10743
|
+
* `keyNodeOrEntry` can be of type `R` or `
|
|
10744
|
+
K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined `.
|
|
10724
10745
|
* @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
|
|
10725
10746
|
* an instance of the `AVLTreeNode` class.
|
|
10726
10747
|
*/
|
|
@@ -10733,8 +10754,9 @@ var dataStructureTyped = (() => {
|
|
|
10733
10754
|
*
|
|
10734
10755
|
* The function overrides the add method of a class and inserts a key-value pair into a data
|
|
10735
10756
|
* structure, then balances the path.
|
|
10736
|
-
* @param {
|
|
10737
|
-
* `keyNodeOrEntry` can accept values of type `R`, `
|
|
10757
|
+
* @param { K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The parameter
|
|
10758
|
+
* `keyNodeOrEntry` can accept values of type `R`, `
|
|
10759
|
+
K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined `
|
|
10738
10760
|
* @param {V} [value] - The `value` parameter is an optional value that you want to associate with
|
|
10739
10761
|
* the key or node being added to the data structure.
|
|
10740
10762
|
* @returns The method is returning a boolean value.
|
|
@@ -10751,7 +10773,7 @@ var dataStructureTyped = (() => {
|
|
|
10751
10773
|
*
|
|
10752
10774
|
* The function overrides the delete method in a TypeScript class, performs deletion, and then
|
|
10753
10775
|
* balances the tree if necessary.
|
|
10754
|
-
* @param {
|
|
10776
|
+
* @param { K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The `keyNodeOrEntry`
|
|
10755
10777
|
* parameter in the `override delete` method can be one of the following types:
|
|
10756
10778
|
* @returns The `delete` method is being overridden in this code snippet. It first calls the `delete`
|
|
10757
10779
|
* method from the superclass (presumably a parent class) with the provided `predicate`, which could
|
|
@@ -11035,8 +11057,9 @@ var dataStructureTyped = (() => {
|
|
|
11035
11057
|
*
|
|
11036
11058
|
* The `_balancePath` function is used to update the heights of nodes and perform rotation operations
|
|
11037
11059
|
* to restore balance in an AVL tree after inserting a node.
|
|
11038
|
-
* @param {
|
|
11039
|
-
* `
|
|
11060
|
+
* @param { K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } node - The `node` parameter can be of type `R` or
|
|
11061
|
+
* `
|
|
11062
|
+
K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined `.
|
|
11040
11063
|
*/
|
|
11041
11064
|
_balancePath(node) {
|
|
11042
11065
|
node = this.ensureNode(node);
|
|
@@ -11129,7 +11152,7 @@ var dataStructureTyped = (() => {
|
|
|
11129
11152
|
* This TypeScript constructor initializes a Red-Black Tree with optional keys, nodes, entries, or
|
|
11130
11153
|
* raw data.
|
|
11131
11154
|
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor is an
|
|
11132
|
-
* iterable that can contain either `
|
|
11155
|
+
* iterable that can contain either `K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined` objects or `R` objects. It
|
|
11133
11156
|
* is used to initialize the Red-Black Tree with keys, nodes, entries, or
|
|
11134
11157
|
* @param [options] - The `options` parameter in the constructor is of type `RedBlackTreeOptions<K,
|
|
11135
11158
|
* V, R>`. It is an optional parameter that allows you to specify additional options for the
|
|
@@ -11189,8 +11212,8 @@ var dataStructureTyped = (() => {
|
|
|
11189
11212
|
* Space Complexity: O(1)
|
|
11190
11213
|
*
|
|
11191
11214
|
* The function checks if the input is an instance of the RedBlackTreeNode class.
|
|
11192
|
-
* @param {
|
|
11193
|
-
* `keyNodeOrEntry` can be of type `R` or `
|
|
11215
|
+
* @param {K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The parameter
|
|
11216
|
+
* `keyNodeOrEntry` can be of type `R` or `K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined`.
|
|
11194
11217
|
* @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
|
|
11195
11218
|
* an instance of the `RedBlackTreeNode` class.
|
|
11196
11219
|
*/
|
|
@@ -11214,8 +11237,8 @@ var dataStructureTyped = (() => {
|
|
|
11214
11237
|
*
|
|
11215
11238
|
* The function adds a new node to a binary search tree and returns true if the node was successfully
|
|
11216
11239
|
* added.
|
|
11217
|
-
* @param {
|
|
11218
|
-
* `keyNodeOrEntry` can accept a value of type `R` or `
|
|
11240
|
+
* @param {K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The parameter
|
|
11241
|
+
* `keyNodeOrEntry` can accept a value of type `R` or `K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined`.
|
|
11219
11242
|
* @param {V} [value] - The `value` parameter is an optional value that you want to associate with
|
|
11220
11243
|
* the key in the data structure. It represents the value that you want to add or update in the data
|
|
11221
11244
|
* structure.
|
|
@@ -11249,7 +11272,7 @@ var dataStructureTyped = (() => {
|
|
|
11249
11272
|
*
|
|
11250
11273
|
* The function overrides the delete method in a binary tree data structure to remove a node based on
|
|
11251
11274
|
* a given predicate and maintain the binary search tree properties.
|
|
11252
|
-
* @param {
|
|
11275
|
+
* @param {K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The `keyNodeOrEntry`
|
|
11253
11276
|
* parameter in the `override delete` method is used to specify the condition or key based on which a
|
|
11254
11277
|
* node should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate
|
|
11255
11278
|
* function that determines which node(s) should be deleted.
|
|
@@ -11715,7 +11738,7 @@ var dataStructureTyped = (() => {
|
|
|
11715
11738
|
*
|
|
11716
11739
|
* The function `add` in TypeScript overrides the superclass method to add key-value pairs to an AVL
|
|
11717
11740
|
* tree multi-map.
|
|
11718
|
-
* @param {
|
|
11741
|
+
* @param {K | AVLTreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined | K} keyNodeOrEntry - The `keyNodeOrEntry`
|
|
11719
11742
|
* parameter in the `override add` method can be either a key-value pair entry or just a key. If it
|
|
11720
11743
|
* is a key-value pair entry, it will be in the format `[key, values]`, where `key` is the key and
|
|
11721
11744
|
* `values`
|
|
@@ -11762,7 +11785,7 @@ var dataStructureTyped = (() => {
|
|
|
11762
11785
|
*
|
|
11763
11786
|
* The function `deleteValue` removes a specific value from a key in an AVLTreeMultiMap data
|
|
11764
11787
|
* structure and deletes the entire node if no values are left for that key.
|
|
11765
|
-
* @param {
|
|
11788
|
+
* @param {K | AVLTreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined | K} keyNodeOrEntry - The `keyNodeOrEntry`
|
|
11766
11789
|
* parameter in the `deleteValue` function can be either a `BTNRep` object representing a key-value
|
|
11767
11790
|
* pair in the AVLTreeMultiMapNode, or just the key itself.
|
|
11768
11791
|
* @param {V} value - The `value` parameter in the `deleteValue` function represents the specific
|
|
@@ -11894,7 +11917,7 @@ var dataStructureTyped = (() => {
|
|
|
11894
11917
|
*
|
|
11895
11918
|
* The function `add` in TypeScript overrides the superclass method to add key-value pairs to a
|
|
11896
11919
|
* TreeMultiMapNode, handling different input types and scenarios.
|
|
11897
|
-
* @param {
|
|
11920
|
+
* @param {K | TreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined} keyNodeOrEntry - The `keyNodeOrEntry`
|
|
11898
11921
|
* parameter in the `override add` method can be either a `BTNRep` object containing a key, an array
|
|
11899
11922
|
* of values, and a `TreeMultiMapNode`, or just a key.
|
|
11900
11923
|
* @param {V} [value] - The `value` parameter in the `override add` method represents the value that
|
|
@@ -11940,7 +11963,7 @@ var dataStructureTyped = (() => {
|
|
|
11940
11963
|
*
|
|
11941
11964
|
* The function `deleteValue` removes a specific value from a key in a TreeMultiMap data structure
|
|
11942
11965
|
* and deletes the entire node if no values are left for that key.
|
|
11943
|
-
* @param {
|
|
11966
|
+
* @param {K | TreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined} keyNodeOrEntry - The `keyNodeOrEntry`
|
|
11944
11967
|
* parameter in the `deleteValue` function can be either a `BTNRep` object containing a key and an
|
|
11945
11968
|
* array of values, or just a key itself.
|
|
11946
11969
|
* @param {V} value - The `value` parameter in the `deleteValue` function represents the specific
|
|
@@ -12049,7 +12072,7 @@ var dataStructureTyped = (() => {
|
|
|
12049
12072
|
*/
|
|
12050
12073
|
getComputedCount() {
|
|
12051
12074
|
let sum = 0;
|
|
12052
|
-
this.dfs((node) => sum += node.count);
|
|
12075
|
+
this.dfs((node) => sum += node ? node.count : 0);
|
|
12053
12076
|
return sum;
|
|
12054
12077
|
}
|
|
12055
12078
|
/**
|
|
@@ -12086,8 +12109,8 @@ var dataStructureTyped = (() => {
|
|
|
12086
12109
|
}
|
|
12087
12110
|
/**
|
|
12088
12111
|
* The function checks if the input is an instance of the TreeCounterNode class.
|
|
12089
|
-
* @param {
|
|
12090
|
-
* `keyNodeOrEntry` can be of type `R` or `
|
|
12112
|
+
* @param {K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The parameter
|
|
12113
|
+
* `keyNodeOrEntry` can be of type `R` or `K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined`.
|
|
12091
12114
|
* @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
|
|
12092
12115
|
* an instance of the `TreeCounterNode` class.
|
|
12093
12116
|
*/
|
|
@@ -12100,7 +12123,7 @@ var dataStructureTyped = (() => {
|
|
|
12100
12123
|
*
|
|
12101
12124
|
* The function overrides the add method of a class and adds a new node to a data structure, updating
|
|
12102
12125
|
* the count and returning a boolean indicating success.
|
|
12103
|
-
* @param {
|
|
12126
|
+
* @param {K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The
|
|
12104
12127
|
* `keyNodeOrEntry` parameter can accept one of the following types:
|
|
12105
12128
|
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
12106
12129
|
* data structure. It is an optional parameter, so it can be omitted if not needed.
|
|
@@ -12127,7 +12150,7 @@ var dataStructureTyped = (() => {
|
|
|
12127
12150
|
*
|
|
12128
12151
|
* The function `delete` in TypeScript overrides the deletion operation in a binary tree data
|
|
12129
12152
|
* structure, handling cases where nodes have children and maintaining balance in the tree.
|
|
12130
|
-
* @param {
|
|
12153
|
+
* @param {K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The `predicate`
|
|
12131
12154
|
* parameter in the `delete` method is used to specify the condition or key based on which a node
|
|
12132
12155
|
* should be deleted from the binary tree. It can be a key, a node, or an entry.
|
|
12133
12156
|
* @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
|
|
@@ -12253,8 +12276,8 @@ var dataStructureTyped = (() => {
|
|
|
12253
12276
|
if (l > r) return;
|
|
12254
12277
|
const m = l + Math.floor((r - l) / 2);
|
|
12255
12278
|
const midNode = sorted[m];
|
|
12256
|
-
if (this._isMapMode) this.add(midNode.key, void 0, midNode.count);
|
|
12257
|
-
else this.add(midNode.key, midNode.value, midNode.count);
|
|
12279
|
+
if (this._isMapMode && midNode !== null) this.add(midNode.key, void 0, midNode.count);
|
|
12280
|
+
else if (midNode !== null) this.add(midNode.key, midNode.value, midNode.count);
|
|
12258
12281
|
buildBalanceBST(l, m - 1);
|
|
12259
12282
|
buildBalanceBST(m + 1, r);
|
|
12260
12283
|
};
|
|
@@ -12269,8 +12292,8 @@ var dataStructureTyped = (() => {
|
|
|
12269
12292
|
if (l <= r) {
|
|
12270
12293
|
const m = l + Math.floor((r - l) / 2);
|
|
12271
12294
|
const midNode = sorted[m];
|
|
12272
|
-
if (this._isMapMode) this.add(midNode.key, void 0, midNode.count);
|
|
12273
|
-
else this.add(midNode.key, midNode.value, midNode.count);
|
|
12295
|
+
if (this._isMapMode && midNode !== null) this.add(midNode.key, void 0, midNode.count);
|
|
12296
|
+
else if (midNode !== null) this.add(midNode.key, midNode.value, midNode.count);
|
|
12274
12297
|
stack.push([m + 1, r]);
|
|
12275
12298
|
stack.push([l, m - 1]);
|
|
12276
12299
|
}
|
|
@@ -12288,7 +12311,7 @@ var dataStructureTyped = (() => {
|
|
|
12288
12311
|
*/
|
|
12289
12312
|
clone() {
|
|
12290
12313
|
const cloned = this.createTree();
|
|
12291
|
-
this.bfs((node) => cloned.add(node.key, void 0, node.count));
|
|
12314
|
+
this.bfs((node) => cloned.add(node === null ? null : node.key, void 0, node === null ? 0 : node.count));
|
|
12292
12315
|
if (this._isMapMode) cloned._store = this._store;
|
|
12293
12316
|
return cloned;
|
|
12294
12317
|
}
|
|
@@ -12318,8 +12341,8 @@ var dataStructureTyped = (() => {
|
|
|
12318
12341
|
/**
|
|
12319
12342
|
* The function `keyValueNodeEntryRawToNodeAndValue` takes in a key, value, and count and returns a
|
|
12320
12343
|
* node based on the input.
|
|
12321
|
-
* @param {
|
|
12322
|
-
* `keyNodeOrEntry` can be of type `R` or `
|
|
12344
|
+
* @param {K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The parameter
|
|
12345
|
+
* `keyNodeOrEntry` can be of type `R` or `K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined`.
|
|
12323
12346
|
* @param {V} [value] - The `value` parameter is an optional value that represents the value
|
|
12324
12347
|
* associated with the key in the node. It is used when creating a new node or updating the value of
|
|
12325
12348
|
* an existing node.
|
|
@@ -12495,8 +12518,8 @@ var dataStructureTyped = (() => {
|
|
|
12495
12518
|
}
|
|
12496
12519
|
/**
|
|
12497
12520
|
* The function checks if the input is an instance of AVLTreeCounterNode.
|
|
12498
|
-
* @param {
|
|
12499
|
-
* `keyNodeOrEntry` can be of type `R` or `
|
|
12521
|
+
* @param {K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The parameter
|
|
12522
|
+
* `keyNodeOrEntry` can be of type `R` or `K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined`.
|
|
12500
12523
|
* @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
|
|
12501
12524
|
* an instance of the `AVLTreeCounterNode` class.
|
|
12502
12525
|
*/
|
|
@@ -12509,9 +12532,9 @@ var dataStructureTyped = (() => {
|
|
|
12509
12532
|
*
|
|
12510
12533
|
* The function overrides the add method of a TypeScript class to add a new node to a data structure
|
|
12511
12534
|
* and update the count.
|
|
12512
|
-
* @param {
|
|
12535
|
+
* @param {K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The
|
|
12513
12536
|
* `keyNodeOrEntry` parameter can accept a value of type `R`, which can be any type. It
|
|
12514
|
-
* can also accept a value of type `
|
|
12537
|
+
* can also accept a value of type `K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined`, which represents a key, node,
|
|
12515
12538
|
* entry, or raw element
|
|
12516
12539
|
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
12517
12540
|
* data structure. It is an optional parameter, so it can be omitted if not needed.
|
|
@@ -12536,7 +12559,7 @@ var dataStructureTyped = (() => {
|
|
|
12536
12559
|
*
|
|
12537
12560
|
* The function overrides the delete method in a binary tree data structure, handling deletion of
|
|
12538
12561
|
* nodes and maintaining balance in the tree.
|
|
12539
|
-
* @param {
|
|
12562
|
+
* @param {K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The `predicate`
|
|
12540
12563
|
* parameter in the `delete` method is used to specify the condition for deleting a node from the
|
|
12541
12564
|
* binary tree. It can be a key, node, or entry that determines which
|
|
12542
12565
|
* node(s) should be deleted.
|
|
@@ -12611,6 +12634,7 @@ var dataStructureTyped = (() => {
|
|
|
12611
12634
|
/**
|
|
12612
12635
|
* Time Complexity: O(n log n)
|
|
12613
12636
|
* Space Complexity: O(log n)
|
|
12637
|
+
*
|
|
12614
12638
|
* The `perfectlyBalance` function takes a sorted array of nodes and builds a balanced binary search
|
|
12615
12639
|
* tree using either a recursive or iterative approach.
|
|
12616
12640
|
* @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
|
|
@@ -12698,8 +12722,8 @@ var dataStructureTyped = (() => {
|
|
|
12698
12722
|
/**
|
|
12699
12723
|
* The function `keyValueNodeEntryRawToNodeAndValue` converts a key, value, entry, or raw element into
|
|
12700
12724
|
* a node object.
|
|
12701
|
-
* @param {
|
|
12702
|
-
* `keyNodeOrEntry` parameter can be of type `R` or `
|
|
12725
|
+
* @param {K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The
|
|
12726
|
+
* `keyNodeOrEntry` parameter can be of type `R` or `K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined`.
|
|
12703
12727
|
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
|
|
12704
12728
|
* `override` function. It represents the value associated with the key in the data structure. If no
|
|
12705
12729
|
* value is provided, it will default to `undefined`.
|
|
@@ -14148,13 +14172,6 @@ var dataStructureTyped = (() => {
|
|
|
14148
14172
|
};
|
|
14149
14173
|
return __toCommonJS(src_exports);
|
|
14150
14174
|
})();
|
|
14151
|
-
/**
|
|
14152
|
-
* data-structure-typed
|
|
14153
|
-
*
|
|
14154
|
-
* @author Tyler Zeng
|
|
14155
|
-
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
14156
|
-
* @license MIT License
|
|
14157
|
-
*/
|
|
14158
14175
|
/**
|
|
14159
14176
|
* data-structure-typed
|
|
14160
14177
|
*
|