data-structure-typed 1.48.2 → 1.48.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/README.md +16 -16
- package/benchmark/report.html +16 -16
- package/benchmark/report.json +184 -184
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +16 -16
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +7 -7
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +89 -87
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +67 -58
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +28 -47
- package/dist/cjs/data-structures/binary-tree/bst.js +54 -57
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +15 -15
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +7 -7
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +22 -22
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js +11 -11
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +6 -6
- package/dist/cjs/types/common.d.ts +11 -8
- package/dist/cjs/types/common.js +6 -1
- package/dist/cjs/types/common.js.map +1 -1
- package/dist/cjs/types/data-structures/binary-tree/avl-tree.d.ts +3 -3
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +4 -4
- package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +6 -6
- package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +3 -3
- package/dist/cjs/types/data-structures/binary-tree/tree-multimap.d.ts +3 -3
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +16 -16
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +7 -7
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +89 -87
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +67 -58
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +28 -47
- package/dist/mjs/data-structures/binary-tree/bst.js +55 -57
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +15 -15
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +7 -7
- package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +22 -22
- package/dist/mjs/data-structures/binary-tree/tree-multimap.js +11 -11
- package/dist/mjs/interfaces/binary-tree.d.ts +6 -6
- package/dist/mjs/types/common.d.ts +11 -8
- package/dist/mjs/types/common.js +5 -0
- package/dist/mjs/types/data-structures/binary-tree/avl-tree.d.ts +3 -3
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +4 -4
- package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +6 -6
- package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +3 -3
- package/dist/mjs/types/data-structures/binary-tree/tree-multimap.d.ts +3 -3
- package/dist/umd/data-structure-typed.js +152 -140
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree.ts +20 -21
- package/src/data-structures/binary-tree/binary-tree.ts +147 -136
- package/src/data-structures/binary-tree/bst.ts +86 -82
- package/src/data-structures/binary-tree/rb-tree.ts +25 -26
- package/src/data-structures/binary-tree/tree-multimap.ts +30 -35
- package/src/interfaces/binary-tree.ts +5 -6
- package/src/types/common.ts +11 -8
- package/src/types/data-structures/binary-tree/avl-tree.ts +3 -3
- package/src/types/data-structures/binary-tree/binary-tree.ts +6 -5
- package/src/types/data-structures/binary-tree/bst.ts +6 -6
- package/src/types/data-structures/binary-tree/rb-tree.ts +3 -3
- package/src/types/data-structures/binary-tree/tree-multimap.ts +3 -3
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +3 -3
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +6 -6
- package/test/unit/data-structures/binary-tree/bst.test.ts +10 -9
- package/test/unit/data-structures/binary-tree/overall.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +5 -5
- package/test/unit/unrestricted-interconversion.test.ts +1 -1
|
@@ -108,6 +108,7 @@ var dataStructureTyped = (() => {
|
|
|
108
108
|
AbstractVertex: () => AbstractVertex,
|
|
109
109
|
BST: () => BST,
|
|
110
110
|
BSTNode: () => BSTNode,
|
|
111
|
+
BSTVariant: () => BSTVariant,
|
|
111
112
|
BinaryIndexedTree: () => BinaryIndexedTree,
|
|
112
113
|
BinaryTree: () => BinaryTree,
|
|
113
114
|
BinaryTreeNode: () => BinaryTreeNode,
|
|
@@ -7369,6 +7370,11 @@ var dataStructureTyped = (() => {
|
|
|
7369
7370
|
})(RBTNColor || {});
|
|
7370
7371
|
|
|
7371
7372
|
// src/types/common.ts
|
|
7373
|
+
var BSTVariant = /* @__PURE__ */ ((BSTVariant2) => {
|
|
7374
|
+
BSTVariant2["MIN"] = "MIN";
|
|
7375
|
+
BSTVariant2["MAX"] = "MAX";
|
|
7376
|
+
return BSTVariant2;
|
|
7377
|
+
})(BSTVariant || {});
|
|
7372
7378
|
var CP = /* @__PURE__ */ ((CP2) => {
|
|
7373
7379
|
CP2["lt"] = "lt";
|
|
7374
7380
|
CP2["eq"] = "eq";
|
|
@@ -7435,19 +7441,26 @@ var dataStructureTyped = (() => {
|
|
|
7435
7441
|
constructor(elements, options) {
|
|
7436
7442
|
super();
|
|
7437
7443
|
__publicField(this, "iterationType", "ITERATIVE" /* ITERATIVE */);
|
|
7444
|
+
__publicField(this, "_extractor", (key) => Number(key));
|
|
7438
7445
|
__publicField(this, "_root");
|
|
7439
7446
|
__publicField(this, "_size");
|
|
7440
7447
|
__publicField(this, "_defaultOneParamCallback", (node) => node.key);
|
|
7441
7448
|
if (options) {
|
|
7442
|
-
const { iterationType } = options;
|
|
7449
|
+
const { iterationType, extractor } = options;
|
|
7443
7450
|
if (iterationType) {
|
|
7444
7451
|
this.iterationType = iterationType;
|
|
7445
7452
|
}
|
|
7453
|
+
if (extractor) {
|
|
7454
|
+
this._extractor = extractor;
|
|
7455
|
+
}
|
|
7446
7456
|
}
|
|
7447
7457
|
this._size = 0;
|
|
7448
7458
|
if (elements)
|
|
7449
7459
|
this.addMany(elements);
|
|
7450
7460
|
}
|
|
7461
|
+
get extractor() {
|
|
7462
|
+
return this._extractor;
|
|
7463
|
+
}
|
|
7451
7464
|
get root() {
|
|
7452
7465
|
return this._root;
|
|
7453
7466
|
}
|
|
@@ -7456,7 +7469,7 @@ var dataStructureTyped = (() => {
|
|
|
7456
7469
|
}
|
|
7457
7470
|
/**
|
|
7458
7471
|
* Creates a new instance of BinaryTreeNode with the given key and value.
|
|
7459
|
-
* @param {
|
|
7472
|
+
* @param {K} key - The key for the new node.
|
|
7460
7473
|
* @param {V} value - The value for the new node.
|
|
7461
7474
|
* @returns {N} - The newly created BinaryTreeNode.
|
|
7462
7475
|
*/
|
|
@@ -7475,7 +7488,7 @@ var dataStructureTyped = (() => {
|
|
|
7475
7488
|
}
|
|
7476
7489
|
/**
|
|
7477
7490
|
* The function "isNode" checks if an exemplar is an instance of the BinaryTreeNode class.
|
|
7478
|
-
* @param exemplar - The `exemplar` parameter is a variable of type `BTNodeExemplar<V,
|
|
7491
|
+
* @param exemplar - The `exemplar` parameter is a variable of type `BTNodeExemplar<K, V,N>`.
|
|
7479
7492
|
* @returns a boolean value indicating whether the exemplar is an instance of the class N.
|
|
7480
7493
|
*/
|
|
7481
7494
|
isNode(exemplar) {
|
|
@@ -7484,7 +7497,7 @@ var dataStructureTyped = (() => {
|
|
|
7484
7497
|
/**
|
|
7485
7498
|
* The function `exemplarToNode` converts an exemplar of a binary tree node into an actual node
|
|
7486
7499
|
* object.
|
|
7487
|
-
* @param exemplar - BTNodeExemplar<V,
|
|
7500
|
+
* @param exemplar - BTNodeExemplar<K, V,N> - A generic type representing the exemplar parameter of the
|
|
7488
7501
|
* function. It can be any type.
|
|
7489
7502
|
* @returns a value of type `N` (which represents a node), or `null`, or `undefined`.
|
|
7490
7503
|
*/
|
|
@@ -7505,7 +7518,7 @@ var dataStructureTyped = (() => {
|
|
|
7505
7518
|
}
|
|
7506
7519
|
} else if (this.isNode(exemplar)) {
|
|
7507
7520
|
node = exemplar;
|
|
7508
|
-
} else if (this.
|
|
7521
|
+
} else if (this.isNotNodeInstance(exemplar)) {
|
|
7509
7522
|
node = this.createNode(exemplar);
|
|
7510
7523
|
} else {
|
|
7511
7524
|
return;
|
|
@@ -7514,7 +7527,7 @@ var dataStructureTyped = (() => {
|
|
|
7514
7527
|
}
|
|
7515
7528
|
/**
|
|
7516
7529
|
* The function checks if a given value is an entry in a binary tree node.
|
|
7517
|
-
* @param kne - BTNodeExemplar<V,
|
|
7530
|
+
* @param kne - BTNodeExemplar<K, V,N> - A generic type representing a node in a binary tree. It has
|
|
7518
7531
|
* two type parameters V and N, representing the value and node type respectively.
|
|
7519
7532
|
* @returns a boolean value.
|
|
7520
7533
|
*/
|
|
@@ -7580,7 +7593,7 @@ var dataStructureTyped = (() => {
|
|
|
7580
7593
|
* The function `addMany` takes in an iterable of `BTNodeExemplar` objects, adds each object to the
|
|
7581
7594
|
* current instance, and returns an array of the inserted nodes.
|
|
7582
7595
|
* @param nodes - The `nodes` parameter is an iterable (such as an array or a set) of
|
|
7583
|
-
* `BTNodeExemplar<V,
|
|
7596
|
+
* `BTNodeExemplar<K, V,N>` objects.
|
|
7584
7597
|
* @returns The function `addMany` returns an array of values, where each value is either of type
|
|
7585
7598
|
* `N`, `null`, or `undefined`.
|
|
7586
7599
|
*/
|
|
@@ -7675,11 +7688,11 @@ var dataStructureTyped = (() => {
|
|
|
7675
7688
|
* Space Complexity: O(1)
|
|
7676
7689
|
*
|
|
7677
7690
|
* The function calculates the depth of a given node in a binary tree.
|
|
7678
|
-
* @param {
|
|
7679
|
-
* the binary tree whose depth we want to find. It can be of type `
|
|
7691
|
+
* @param {K | N | null | undefined} distNode - The `distNode` parameter represents the node in
|
|
7692
|
+
* the binary tree whose depth we want to find. It can be of type `K`, `N`, `null`, or
|
|
7680
7693
|
* `undefined`.
|
|
7681
|
-
* @param {
|
|
7682
|
-
* from which we want to calculate the depth. It can be either a `
|
|
7694
|
+
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting node
|
|
7695
|
+
* from which we want to calculate the depth. It can be either a `K` (binary tree node key) or
|
|
7683
7696
|
* `N` (binary tree node) or `null` or `undefined`. If no value is provided for `beginRoot
|
|
7684
7697
|
* @returns the depth of the `distNode` relative to the `beginRoot`.
|
|
7685
7698
|
*/
|
|
@@ -7706,9 +7719,9 @@ var dataStructureTyped = (() => {
|
|
|
7706
7719
|
*
|
|
7707
7720
|
* The function `getHeight` calculates the maximum height of a binary tree using either recursive or
|
|
7708
7721
|
* iterative traversal.
|
|
7709
|
-
* @param {
|
|
7722
|
+
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
|
|
7710
7723
|
* starting node of the binary tree from which we want to calculate the height. It can be of type
|
|
7711
|
-
* `
|
|
7724
|
+
* `K`, `N`, `null`, or `undefined`. If not provided, it defaults to `this.root`.
|
|
7712
7725
|
* @param iterationType - The `iterationType` parameter is used to determine whether to calculate the
|
|
7713
7726
|
* height of the tree using a recursive approach or an iterative approach. It can have two possible
|
|
7714
7727
|
* values:
|
|
@@ -7752,9 +7765,9 @@ var dataStructureTyped = (() => {
|
|
|
7752
7765
|
*
|
|
7753
7766
|
* The `getMinHeight` function calculates the minimum height of a binary tree using either a
|
|
7754
7767
|
* recursive or iterative approach.
|
|
7755
|
-
* @param {
|
|
7768
|
+
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
|
|
7756
7769
|
* starting node of the binary tree from which we want to calculate the minimum height. It can be of
|
|
7757
|
-
* type `
|
|
7770
|
+
* type `K`, `N`, `null`, or `undefined`. If no value is provided, it defaults to `this.root`.
|
|
7758
7771
|
* @param iterationType - The `iterationType` parameter is used to determine the method of iteration
|
|
7759
7772
|
* to calculate the minimum height of a binary tree. It can have two possible values:
|
|
7760
7773
|
* @returns The function `getMinHeight` returns the minimum height of a binary tree.
|
|
@@ -7812,8 +7825,8 @@ var dataStructureTyped = (() => {
|
|
|
7812
7825
|
*
|
|
7813
7826
|
* The function checks if a binary tree is perfectly balanced by comparing the minimum height and the
|
|
7814
7827
|
* height of the tree.
|
|
7815
|
-
* @param {
|
|
7816
|
-
* for calculating the height and minimum height of a binary tree. It can be either a `
|
|
7828
|
+
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
|
|
7829
|
+
* for calculating the height and minimum height of a binary tree. It can be either a `K` (a key
|
|
7817
7830
|
* value of a binary tree node), `N` (a node of a binary tree), `null`, or `undefined`. If
|
|
7818
7831
|
* @returns a boolean value.
|
|
7819
7832
|
*/
|
|
@@ -7838,7 +7851,7 @@ var dataStructureTyped = (() => {
|
|
|
7838
7851
|
* matches the identifier. If set to true, the function will stop iterating once it finds a matching
|
|
7839
7852
|
* node and return that node. If set to false (default), the function will continue iterating and
|
|
7840
7853
|
* return all nodes that match the identifier.
|
|
7841
|
-
* @param {
|
|
7854
|
+
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
|
|
7842
7855
|
* starting node for the traversal. It can be either a key, a node object, or `null`/`undefined`. If
|
|
7843
7856
|
* it is `null` or `undefined`, an empty array will be returned.
|
|
7844
7857
|
* @param iterationType - The `iterationType` parameter determines the type of iteration used to
|
|
@@ -7894,8 +7907,8 @@ var dataStructureTyped = (() => {
|
|
|
7894
7907
|
* the binary tree. It is used to filter the nodes based on certain conditions. The `callback`
|
|
7895
7908
|
* function should return a boolean value indicating whether the node should be included in the
|
|
7896
7909
|
* result or not.
|
|
7897
|
-
* @param {
|
|
7898
|
-
* for the search in the binary tree. It can be specified as a `
|
|
7910
|
+
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
|
|
7911
|
+
* for the search in the binary tree. It can be specified as a `K` (a unique identifier for a
|
|
7899
7912
|
* node in the binary tree), a node object (`N`), or `null`/`undefined` to start the search from
|
|
7900
7913
|
* @param iterationType - The `iterationType` parameter is a variable that determines the type of
|
|
7901
7914
|
* iteration to be performed on the binary tree. It is used to specify whether the iteration should
|
|
@@ -7920,7 +7933,7 @@ var dataStructureTyped = (() => {
|
|
|
7920
7933
|
* @param {C} callback - The `callback` parameter is a function that will be called for each node in
|
|
7921
7934
|
* the binary tree. It is used to determine if a node matches the given identifier. The `callback`
|
|
7922
7935
|
* function should take a single parameter of type `N` (the type of the nodes in the binary tree) and
|
|
7923
|
-
* @param {
|
|
7936
|
+
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
|
|
7924
7937
|
* for searching the binary tree. It can be either a key value, a node object, or `null`/`undefined`.
|
|
7925
7938
|
* If `null` or `undefined` is passed, the search will start from the root of the binary tree.
|
|
7926
7939
|
* @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
|
|
@@ -7944,7 +7957,7 @@ var dataStructureTyped = (() => {
|
|
|
7944
7957
|
*
|
|
7945
7958
|
* The function `getNodeByKey` searches for a node in a binary tree by its key, using either
|
|
7946
7959
|
* recursive or iterative iteration.
|
|
7947
|
-
* @param {
|
|
7960
|
+
* @param {K} key - The `key` parameter is the key value that we are searching for in the tree.
|
|
7948
7961
|
* It is used to find the node with the matching key value.
|
|
7949
7962
|
* @param iterationType - The `iterationType` parameter is used to determine whether the search for
|
|
7950
7963
|
* the node with the given key should be performed iteratively or recursively. It has two possible
|
|
@@ -7987,7 +8000,7 @@ var dataStructureTyped = (() => {
|
|
|
7987
8000
|
/**
|
|
7988
8001
|
* The function `ensureNode` returns the node corresponding to the given key if it is a valid node
|
|
7989
8002
|
* key, otherwise it returns the key itself.
|
|
7990
|
-
* @param {
|
|
8003
|
+
* @param {K | N | null | undefined} key - The `key` parameter can be of type `K`, `N`,
|
|
7991
8004
|
* `null`, or `undefined`. It represents a key used to identify a node in a binary tree.
|
|
7992
8005
|
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
|
|
7993
8006
|
* type of iteration to be used when searching for a node by key. It has a default value of
|
|
@@ -7996,7 +8009,7 @@ var dataStructureTyped = (() => {
|
|
|
7996
8009
|
* itself if it is not a valid node key.
|
|
7997
8010
|
*/
|
|
7998
8011
|
ensureNode(key, iterationType = "ITERATIVE" /* ITERATIVE */) {
|
|
7999
|
-
return this.
|
|
8012
|
+
return this.isNotNodeInstance(key) ? this.getNodeByKey(key, iterationType) : key;
|
|
8000
8013
|
}
|
|
8001
8014
|
/**
|
|
8002
8015
|
* Time Complexity: O(n)
|
|
@@ -8011,8 +8024,8 @@ var dataStructureTyped = (() => {
|
|
|
8011
8024
|
* the binary tree. It is used to determine whether a node matches the given identifier. The callback
|
|
8012
8025
|
* function should return a value that can be compared to the identifier to determine if it is a
|
|
8013
8026
|
* match.
|
|
8014
|
-
* @param {
|
|
8015
|
-
* for the search in the binary tree. It can be specified as a `
|
|
8027
|
+
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
|
|
8028
|
+
* for the search in the binary tree. It can be specified as a `K` (a unique identifier for a
|
|
8016
8029
|
* node), a node object of type `N`, or `null`/`undefined` to start the search from the root of
|
|
8017
8030
|
* @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
|
|
8018
8031
|
* be performed when searching for a node in the binary tree. It is an optional parameter with a
|
|
@@ -8050,8 +8063,8 @@ var dataStructureTyped = (() => {
|
|
|
8050
8063
|
*
|
|
8051
8064
|
* The function `getPathToRoot` returns an array of nodes from a given node to the root of a tree
|
|
8052
8065
|
* structure, with the option to reverse the order of the nodes.
|
|
8053
|
-
* @param {
|
|
8054
|
-
* starting node from which you want to find the path to the root. It can be of type `
|
|
8066
|
+
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
|
|
8067
|
+
* starting node from which you want to find the path to the root. It can be of type `K`, `N`,
|
|
8055
8068
|
* `null`, or `undefined`.
|
|
8056
8069
|
* @param [isReverse=true] - The `isReverse` parameter is a boolean flag that determines whether the
|
|
8057
8070
|
* resulting path should be reversed or not. If `isReverse` is set to `true`, the path will be
|
|
@@ -8080,8 +8093,8 @@ var dataStructureTyped = (() => {
|
|
|
8080
8093
|
*
|
|
8081
8094
|
* The function `getLeftMost` returns the leftmost node in a binary tree, either recursively or
|
|
8082
8095
|
* iteratively.
|
|
8083
|
-
* @param {
|
|
8084
|
-
* for finding the leftmost node in a binary tree. It can be either a `
|
|
8096
|
+
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
|
|
8097
|
+
* for finding the leftmost node in a binary tree. It can be either a `K` (a key value), `N` (a
|
|
8085
8098
|
* node), `null`, or `undefined`. If not provided, it defaults to `this.root`,
|
|
8086
8099
|
* @param iterationType - The `iterationType` parameter is used to determine the type of iteration to
|
|
8087
8100
|
* be performed when finding the leftmost node in a binary tree. It can have two possible values:
|
|
@@ -8118,8 +8131,8 @@ var dataStructureTyped = (() => {
|
|
|
8118
8131
|
*
|
|
8119
8132
|
* The function `getRightMost` returns the rightmost node in a binary tree, either recursively or
|
|
8120
8133
|
* iteratively.
|
|
8121
|
-
* @param {
|
|
8122
|
-
* starting node from which we want to find the rightmost node. It can be of type `
|
|
8134
|
+
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
|
|
8135
|
+
* starting node from which we want to find the rightmost node. It can be of type `K`, `N`,
|
|
8123
8136
|
* `null`, or `undefined`. If not provided, it defaults to `this.root`, which is a property of the
|
|
8124
8137
|
* current object.
|
|
8125
8138
|
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
|
|
@@ -8156,7 +8169,7 @@ var dataStructureTyped = (() => {
|
|
|
8156
8169
|
* Space Complexity: O(1)
|
|
8157
8170
|
*
|
|
8158
8171
|
* The function `isSubtreeBST` checks if a given binary tree is a valid binary search tree.
|
|
8159
|
-
* @param {
|
|
8172
|
+
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the root
|
|
8160
8173
|
* node of the binary search tree (BST) that you want to check if it is a subtree of another BST.
|
|
8161
8174
|
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
|
|
8162
8175
|
* type of iteration to use when checking if a subtree is a binary search tree (BST). It can have two
|
|
@@ -8171,9 +8184,10 @@ var dataStructureTyped = (() => {
|
|
|
8171
8184
|
const dfs = (cur, min, max) => {
|
|
8172
8185
|
if (!cur)
|
|
8173
8186
|
return true;
|
|
8174
|
-
|
|
8187
|
+
const numKey = this.extractor(cur.key);
|
|
8188
|
+
if (numKey <= min || numKey >= max)
|
|
8175
8189
|
return false;
|
|
8176
|
-
return dfs(cur.left, min,
|
|
8190
|
+
return dfs(cur.left, min, numKey) && dfs(cur.right, numKey, max);
|
|
8177
8191
|
};
|
|
8178
8192
|
return dfs(beginRoot, Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
|
|
8179
8193
|
} else {
|
|
@@ -8185,9 +8199,10 @@ var dataStructureTyped = (() => {
|
|
|
8185
8199
|
curr = curr.left;
|
|
8186
8200
|
}
|
|
8187
8201
|
curr = stack.pop();
|
|
8188
|
-
|
|
8202
|
+
const numKey = this.extractor(curr.key);
|
|
8203
|
+
if (!curr || prev >= numKey)
|
|
8189
8204
|
return false;
|
|
8190
|
-
prev =
|
|
8205
|
+
prev = numKey;
|
|
8191
8206
|
curr = curr.right;
|
|
8192
8207
|
}
|
|
8193
8208
|
return true;
|
|
@@ -8222,8 +8237,8 @@ var dataStructureTyped = (() => {
|
|
|
8222
8237
|
* @param {C} callback - The `callback` parameter is a function that will be called for each node in
|
|
8223
8238
|
* the subtree traversal. It takes a single parameter, which is the current node being traversed, and
|
|
8224
8239
|
* returns a value of any type.
|
|
8225
|
-
* @param {
|
|
8226
|
-
* starting node or key from which the subtree traversal should begin. It can be of type `
|
|
8240
|
+
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
|
|
8241
|
+
* starting node or key from which the subtree traversal should begin. It can be of type `K`,
|
|
8227
8242
|
* `N`, `null`, or `undefined`. If not provided, the `root` property of the current object is used as
|
|
8228
8243
|
* the default value.
|
|
8229
8244
|
* @param iterationType - The `iterationType` parameter determines the type of traversal to be
|
|
@@ -8302,13 +8317,13 @@ var dataStructureTyped = (() => {
|
|
|
8302
8317
|
return this.isRealNode(node) || node === null;
|
|
8303
8318
|
}
|
|
8304
8319
|
/**
|
|
8305
|
-
* The function "
|
|
8320
|
+
* The function "isNotNodeInstance" checks if a potential key is a number.
|
|
8306
8321
|
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
|
|
8307
8322
|
* data type.
|
|
8308
8323
|
* @returns a boolean value indicating whether the potentialKey is of type number or not.
|
|
8309
8324
|
*/
|
|
8310
|
-
|
|
8311
|
-
return
|
|
8325
|
+
isNotNodeInstance(potentialKey) {
|
|
8326
|
+
return !(potentialKey instanceof BinaryTreeNode);
|
|
8312
8327
|
}
|
|
8313
8328
|
/**
|
|
8314
8329
|
* Time complexity: O(n)
|
|
@@ -8322,7 +8337,7 @@ var dataStructureTyped = (() => {
|
|
|
8322
8337
|
* `null`, or `undefined`, and returns a value of any type. The default value for this parameter is
|
|
8323
8338
|
* @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter determines the order in which the
|
|
8324
8339
|
* nodes are traversed during the depth-first search. It can have one of the following values:
|
|
8325
|
-
* @param {
|
|
8340
|
+
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting node
|
|
8326
8341
|
* for the depth-first search traversal. It can be specified as a key, a node object, or
|
|
8327
8342
|
* `null`/`undefined`. If not provided, the `beginRoot` will default to the root node of the tree.
|
|
8328
8343
|
* @param {IterationType} iterationType - The `iterationType` parameter determines the type of
|
|
@@ -8441,7 +8456,7 @@ var dataStructureTyped = (() => {
|
|
|
8441
8456
|
* @param {C} callback - The `callback` parameter is a function that will be called for each node in
|
|
8442
8457
|
* the breadth-first search traversal. It takes a single parameter, which is the current node being
|
|
8443
8458
|
* visited, and returns a value of any type.
|
|
8444
|
-
* @param {
|
|
8459
|
+
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
|
|
8445
8460
|
* starting node for the breadth-first search traversal. It can be specified as a key, a node object,
|
|
8446
8461
|
* or `null`/`undefined` to indicate the root of the tree. If not provided, the `root` property of
|
|
8447
8462
|
* the class is used as
|
|
@@ -8512,9 +8527,9 @@ var dataStructureTyped = (() => {
|
|
|
8512
8527
|
* @param {C} callback - The `callback` parameter is a function that will be called for each node in
|
|
8513
8528
|
* the tree. It takes a single parameter, which can be of type `N`, `null`, or `undefined`, and
|
|
8514
8529
|
* returns a value of any type.
|
|
8515
|
-
* @param {
|
|
8530
|
+
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
|
|
8516
8531
|
* starting node for traversing the tree. It can be either a node object (`N`), a key value
|
|
8517
|
-
* (`
|
|
8532
|
+
* (`K`), `null`, or `undefined`. If not provided, it defaults to the root node of the tree.
|
|
8518
8533
|
* @param iterationType - The `iterationType` parameter determines the type of iteration to be
|
|
8519
8534
|
* performed on the tree. It can have two possible values:
|
|
8520
8535
|
* @param [includeNull=false] - The `includeNull` parameter is a boolean value that determines
|
|
@@ -8571,7 +8586,7 @@ var dataStructureTyped = (() => {
|
|
|
8571
8586
|
}
|
|
8572
8587
|
/**
|
|
8573
8588
|
* The function `getPredecessor` returns the predecessor node of a given node in a binary tree.
|
|
8574
|
-
* @param {
|
|
8589
|
+
* @param {K | N | null | undefined} node - The `node` parameter can be of type `K`, `N`,
|
|
8575
8590
|
* `null`, or `undefined`.
|
|
8576
8591
|
* @returns The function `getPredecessor` returns a value of type `N | undefined`.
|
|
8577
8592
|
*/
|
|
@@ -8593,7 +8608,7 @@ var dataStructureTyped = (() => {
|
|
|
8593
8608
|
}
|
|
8594
8609
|
/**
|
|
8595
8610
|
* The function `getSuccessor` returns the next node in a binary tree given a current node.
|
|
8596
|
-
* @param {
|
|
8611
|
+
* @param {K | N | null} [x] - The parameter `x` can be of type `K`, `N`, or `null`.
|
|
8597
8612
|
* @returns the successor of the given node or key. The successor is the node that comes immediately
|
|
8598
8613
|
* after the given node in the inorder traversal of the binary tree.
|
|
8599
8614
|
*/
|
|
@@ -8622,7 +8637,7 @@ var dataStructureTyped = (() => {
|
|
|
8622
8637
|
* @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter in the `morris` function
|
|
8623
8638
|
* determines the order in which the nodes of a binary tree are traversed. It can have one of the
|
|
8624
8639
|
* following values:
|
|
8625
|
-
* @param {
|
|
8640
|
+
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting node
|
|
8626
8641
|
* for the traversal. It can be specified as a key, a node object, or `null`/`undefined` to indicate
|
|
8627
8642
|
* the root of the tree. If no value is provided, the default value is the root of the tree.
|
|
8628
8643
|
* @returns The function `morris` returns an array of values that are the result of invoking the
|
|
@@ -8784,7 +8799,7 @@ var dataStructureTyped = (() => {
|
|
|
8784
8799
|
return newTree;
|
|
8785
8800
|
}
|
|
8786
8801
|
// // TODO Type error, need to return a TREE<NV> that is a value type only for callback function.
|
|
8787
|
-
// // map<NV>(callback: (entry: [
|
|
8802
|
+
// // map<NV>(callback: (entry: [K, V | undefined], tree: this) => NV) {
|
|
8788
8803
|
// // const newTree = this.createTree();
|
|
8789
8804
|
// // for (const [key, value] of this) {
|
|
8790
8805
|
// // newTree.add(key, callback([key, value], this));
|
|
@@ -8794,7 +8809,7 @@ var dataStructureTyped = (() => {
|
|
|
8794
8809
|
//
|
|
8795
8810
|
/**
|
|
8796
8811
|
* The `print` function is used to display a binary tree structure in a visually appealing way.
|
|
8797
|
-
* @param {
|
|
8812
|
+
* @param {K | N | null | undefined} [beginRoot=this.root] - The `root` parameter is of type `K | N | null |
|
|
8798
8813
|
* undefined`. It represents the root node of a binary tree. The root node can have one of the
|
|
8799
8814
|
* following types:
|
|
8800
8815
|
* @param {BinaryTreePrintOptions} [options={ isShowUndefined: false, isShowNull: false, isShowRedBlackNIL: false}] - Options object that controls printing behavior. You can specify whether to display undefined, null, or sentinel nodes.
|
|
@@ -8828,22 +8843,22 @@ var dataStructureTyped = (() => {
|
|
|
8828
8843
|
const stack = [];
|
|
8829
8844
|
let current = node;
|
|
8830
8845
|
while (current || stack.length > 0) {
|
|
8831
|
-
while (current && !isNaN(current.key)) {
|
|
8846
|
+
while (current && !isNaN(this.extractor(current.key))) {
|
|
8832
8847
|
stack.push(current);
|
|
8833
8848
|
current = current.left;
|
|
8834
8849
|
}
|
|
8835
8850
|
current = stack.pop();
|
|
8836
|
-
if (current && !isNaN(current.key)) {
|
|
8851
|
+
if (current && !isNaN(this.extractor(current.key))) {
|
|
8837
8852
|
yield [current.key, current.value];
|
|
8838
8853
|
current = current.right;
|
|
8839
8854
|
}
|
|
8840
8855
|
}
|
|
8841
8856
|
} else {
|
|
8842
|
-
if (node.left && !isNaN(node.key)) {
|
|
8857
|
+
if (node.left && !isNaN(this.extractor(node.key))) {
|
|
8843
8858
|
yield* __yieldStar(this[Symbol.iterator](node.left));
|
|
8844
8859
|
}
|
|
8845
8860
|
yield [node.key, node.value];
|
|
8846
|
-
if (node.right && !isNaN(node.key)) {
|
|
8861
|
+
if (node.right && !isNaN(this.extractor(node.key))) {
|
|
8847
8862
|
yield* __yieldStar(this[Symbol.iterator](node.right));
|
|
8848
8863
|
}
|
|
8849
8864
|
}
|
|
@@ -8855,10 +8870,10 @@ var dataStructureTyped = (() => {
|
|
|
8855
8870
|
return emptyDisplayLayout;
|
|
8856
8871
|
} else if (node === void 0 && !isShowUndefined) {
|
|
8857
8872
|
return emptyDisplayLayout;
|
|
8858
|
-
} else if (node !== null && node !== void 0 && isNaN(node.key) && !isShowRedBlackNIL) {
|
|
8873
|
+
} else if (node !== null && node !== void 0 && isNaN(this.extractor(node.key)) && !isShowRedBlackNIL) {
|
|
8859
8874
|
return emptyDisplayLayout;
|
|
8860
8875
|
} else if (node !== null && node !== void 0) {
|
|
8861
|
-
const key = node.key, line = isNaN(key) ? "S" : key.toString(), width = line.length;
|
|
8876
|
+
const key = node.key, line = isNaN(this.extractor(key)) ? "S" : this.extractor(key).toString(), width = line.length;
|
|
8862
8877
|
return _buildNodeDisplay(line, width, this._displayAux(node.left, options), this._displayAux(node.right, options));
|
|
8863
8878
|
} else {
|
|
8864
8879
|
const line = node === void 0 ? "U" : "N", width = line.length;
|
|
@@ -8936,7 +8951,7 @@ var dataStructureTyped = (() => {
|
|
|
8936
8951
|
* If the parent node is null, the function also returns undefined.
|
|
8937
8952
|
*/
|
|
8938
8953
|
_addTo(newNode, parent) {
|
|
8939
|
-
if (this.
|
|
8954
|
+
if (this.isNotNodeInstance(parent))
|
|
8940
8955
|
parent = this.getNode(parent);
|
|
8941
8956
|
if (parent) {
|
|
8942
8957
|
if (parent.left === void 0) {
|
|
@@ -9028,11 +9043,11 @@ var dataStructureTyped = (() => {
|
|
|
9028
9043
|
constructor(elements, options) {
|
|
9029
9044
|
super([], options);
|
|
9030
9045
|
__publicField(this, "_root");
|
|
9031
|
-
__publicField(this, "
|
|
9046
|
+
__publicField(this, "_variant", "MIN" /* MIN */);
|
|
9032
9047
|
if (options) {
|
|
9033
|
-
const {
|
|
9034
|
-
if (
|
|
9035
|
-
this.
|
|
9048
|
+
const { variant } = options;
|
|
9049
|
+
if (variant) {
|
|
9050
|
+
this._variant = variant;
|
|
9036
9051
|
}
|
|
9037
9052
|
}
|
|
9038
9053
|
this._root = void 0;
|
|
@@ -9042,9 +9057,12 @@ var dataStructureTyped = (() => {
|
|
|
9042
9057
|
get root() {
|
|
9043
9058
|
return this._root;
|
|
9044
9059
|
}
|
|
9060
|
+
get variant() {
|
|
9061
|
+
return this._variant;
|
|
9062
|
+
}
|
|
9045
9063
|
/**
|
|
9046
9064
|
* The function creates a new binary search tree node with the given key and value.
|
|
9047
|
-
* @param {
|
|
9065
|
+
* @param {K} key - The key parameter is the key value that will be associated with
|
|
9048
9066
|
* the new node. It is used to determine the position of the node in the binary search tree.
|
|
9049
9067
|
* @param [value] - The parameter `value` is an optional value that can be assigned to the node. It
|
|
9050
9068
|
* represents the value associated with the node in a binary search tree.
|
|
@@ -9063,12 +9081,12 @@ var dataStructureTyped = (() => {
|
|
|
9063
9081
|
createTree(options) {
|
|
9064
9082
|
return new _BST([], __spreadValues({
|
|
9065
9083
|
iterationType: this.iterationType,
|
|
9066
|
-
|
|
9084
|
+
variant: this.variant
|
|
9067
9085
|
}, options));
|
|
9068
9086
|
}
|
|
9069
9087
|
/**
|
|
9070
9088
|
* The function checks if an exemplar is an instance of BSTNode.
|
|
9071
|
-
* @param exemplar - The `exemplar` parameter is a variable of type `BTNodeExemplar<V, N>`.
|
|
9089
|
+
* @param exemplar - The `exemplar` parameter is a variable of type `BTNodeExemplar<K, V, N>`.
|
|
9072
9090
|
* @returns a boolean value indicating whether the exemplar is an instance of the BSTNode class.
|
|
9073
9091
|
*/
|
|
9074
9092
|
isNode(exemplar) {
|
|
@@ -9077,7 +9095,7 @@ var dataStructureTyped = (() => {
|
|
|
9077
9095
|
/**
|
|
9078
9096
|
* The function `exemplarToNode` takes an exemplar and returns a corresponding node if the exemplar
|
|
9079
9097
|
* is valid, otherwise it returns undefined.
|
|
9080
|
-
* @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<V, N>`.
|
|
9098
|
+
* @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`.
|
|
9081
9099
|
* @returns a variable `node` which is of type `N` or `undefined`.
|
|
9082
9100
|
*/
|
|
9083
9101
|
exemplarToNode(exemplar) {
|
|
@@ -9093,7 +9111,7 @@ var dataStructureTyped = (() => {
|
|
|
9093
9111
|
} else {
|
|
9094
9112
|
node = this.createNode(key, value);
|
|
9095
9113
|
}
|
|
9096
|
-
} else if (this.
|
|
9114
|
+
} else if (this.isNotNodeInstance(exemplar)) {
|
|
9097
9115
|
node = this.createNode(exemplar);
|
|
9098
9116
|
} else {
|
|
9099
9117
|
return;
|
|
@@ -9190,17 +9208,17 @@ var dataStructureTyped = (() => {
|
|
|
9190
9208
|
sorted = realBTNExemplars.sort((a, b) => {
|
|
9191
9209
|
let aR, bR;
|
|
9192
9210
|
if (this.isEntry(a))
|
|
9193
|
-
aR = a[0];
|
|
9211
|
+
aR = this.extractor(a[0]);
|
|
9194
9212
|
else if (this.isRealNode(a))
|
|
9195
|
-
aR = a.key;
|
|
9213
|
+
aR = this.extractor(a.key);
|
|
9196
9214
|
else
|
|
9197
|
-
aR = a;
|
|
9215
|
+
aR = this.extractor(a);
|
|
9198
9216
|
if (this.isEntry(b))
|
|
9199
|
-
bR = b[0];
|
|
9217
|
+
bR = this.extractor(b[0]);
|
|
9200
9218
|
else if (this.isRealNode(b))
|
|
9201
|
-
bR = b.key;
|
|
9219
|
+
bR = this.extractor(b.key);
|
|
9202
9220
|
else
|
|
9203
|
-
bR = b;
|
|
9221
|
+
bR = this.extractor(b);
|
|
9204
9222
|
return aR - bR;
|
|
9205
9223
|
});
|
|
9206
9224
|
const _dfs = (arr) => {
|
|
@@ -9236,34 +9254,31 @@ var dataStructureTyped = (() => {
|
|
|
9236
9254
|
}
|
|
9237
9255
|
return inserted;
|
|
9238
9256
|
}
|
|
9239
|
-
/**
|
|
9240
|
-
|
|
9241
|
-
|
|
9242
|
-
|
|
9243
|
-
|
|
9244
|
-
|
|
9245
|
-
|
|
9246
|
-
|
|
9247
|
-
|
|
9248
|
-
|
|
9249
|
-
|
|
9250
|
-
|
|
9251
|
-
|
|
9252
|
-
|
|
9253
|
-
|
|
9254
|
-
|
|
9255
|
-
|
|
9256
|
-
|
|
9257
|
-
|
|
9258
|
-
|
|
9259
|
-
|
|
9260
|
-
|
|
9261
|
-
|
|
9262
|
-
|
|
9263
|
-
|
|
9264
|
-
else
|
|
9265
|
-
return (_f = (_e = this.getRightMost(beginRoot, iterationType)) == null ? void 0 : _e.key) != null ? _f : 0;
|
|
9266
|
-
}
|
|
9257
|
+
// /**
|
|
9258
|
+
// * Time Complexity: O(n log n) - Adding each element individually in a balanced tree.
|
|
9259
|
+
// * Space Complexity: O(n) - Additional space is required for the sorted array.
|
|
9260
|
+
// */
|
|
9261
|
+
//
|
|
9262
|
+
// /**
|
|
9263
|
+
// * Time Complexity: O(log n) - Average case for a balanced tree.
|
|
9264
|
+
// * Space Complexity: O(1) - Constant space is used.
|
|
9265
|
+
// *
|
|
9266
|
+
// * The `lastKey` function returns the key of the rightmost node in a binary tree, or the key of the
|
|
9267
|
+
// * leftmost node if the comparison result is greater than.
|
|
9268
|
+
// * @param {K | N | undefined} beginRoot - The `beginRoot` parameter is optional and can be of
|
|
9269
|
+
// * type `K`, `N`, or `undefined`. It represents the starting point for finding the last key in
|
|
9270
|
+
// * the binary tree. If not provided, it defaults to the root of the binary tree (`this.root`).
|
|
9271
|
+
// * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
|
|
9272
|
+
// * be performed. It can have one of the following values:
|
|
9273
|
+
// * @returns the key of the rightmost node in the binary tree if the comparison result is less than,
|
|
9274
|
+
// * the key of the leftmost node if the comparison result is greater than, and the key of the
|
|
9275
|
+
// * rightmost node otherwise. If no node is found, it returns 0.
|
|
9276
|
+
// */
|
|
9277
|
+
// lastKey(beginRoot: BSTNodeKeyOrNode<K,N> = this.root, iterationType = this.iterationType): K {
|
|
9278
|
+
// if (this._compare(0, 1) === CP.lt) return this.getRightMost(beginRoot, iterationType)?.key ?? 0;
|
|
9279
|
+
// else if (this._compare(0, 1) === CP.gt) return this.getLeftMost(beginRoot, iterationType)?.key ?? 0;
|
|
9280
|
+
// else return this.getRightMost(beginRoot, iterationType)?.key ?? 0;
|
|
9281
|
+
// }
|
|
9267
9282
|
/**
|
|
9268
9283
|
* Time Complexity: O(log n) - Average case for a balanced tree.
|
|
9269
9284
|
* Space Complexity: O(1) - Constant space is used.
|
|
@@ -9274,7 +9289,7 @@ var dataStructureTyped = (() => {
|
|
|
9274
9289
|
*
|
|
9275
9290
|
* The function `getNodeByKey` searches for a node in a binary tree based on a given key, using
|
|
9276
9291
|
* either recursive or iterative methods.
|
|
9277
|
-
* @param {
|
|
9292
|
+
* @param {K} key - The `key` parameter is the key value that we are searching for in the tree.
|
|
9278
9293
|
* It is used to identify the node that we want to retrieve.
|
|
9279
9294
|
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
|
|
9280
9295
|
* type of iteration to use when searching for a node in the binary tree. It can have two possible
|
|
@@ -9319,14 +9334,14 @@ var dataStructureTyped = (() => {
|
|
|
9319
9334
|
/**
|
|
9320
9335
|
* The function `ensureNode` returns the node corresponding to the given key if it is a node key,
|
|
9321
9336
|
* otherwise it returns the key itself.
|
|
9322
|
-
* @param {
|
|
9337
|
+
* @param {K | N | undefined} key - The `key` parameter can be of type `K`, `N`, or
|
|
9323
9338
|
* `undefined`.
|
|
9324
9339
|
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
|
|
9325
9340
|
* type of iteration to be performed. It has a default value of `IterationType.ITERATIVE`.
|
|
9326
9341
|
* @returns either a node object (N) or undefined.
|
|
9327
9342
|
*/
|
|
9328
9343
|
ensureNode(key, iterationType = "ITERATIVE" /* ITERATIVE */) {
|
|
9329
|
-
return this.
|
|
9344
|
+
return this.isNotNodeInstance(key) ? this.getNodeByKey(key, iterationType) : key;
|
|
9330
9345
|
}
|
|
9331
9346
|
/**
|
|
9332
9347
|
* Time Complexity: O(log n) - Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key.
|
|
@@ -9344,7 +9359,7 @@ var dataStructureTyped = (() => {
|
|
|
9344
9359
|
* first node that matches the identifier. If set to true, the function will return an array
|
|
9345
9360
|
* containing only the first matching node. If set to false (default), the function will continue
|
|
9346
9361
|
* searching for all nodes that match the identifier and return an array containing
|
|
9347
|
-
* @param {
|
|
9362
|
+
* @param {K | N | undefined} beginRoot - The `beginRoot` parameter represents the starting node
|
|
9348
9363
|
* for the traversal. It can be either a key value or a node object. If it is undefined, the
|
|
9349
9364
|
* traversal will start from the root of the tree.
|
|
9350
9365
|
* @param iterationType - The `iterationType` parameter determines the type of iteration to be
|
|
@@ -9419,7 +9434,7 @@ var dataStructureTyped = (() => {
|
|
|
9419
9434
|
* traverse nodes that are lesser than, greater than, or equal to the `targetNode`. It is of type
|
|
9420
9435
|
* `CP`, which is a custom type representing the comparison operator. The possible values for
|
|
9421
9436
|
* `lesserOrGreater` are
|
|
9422
|
-
* @param {
|
|
9437
|
+
* @param {K | N | undefined} targetNode - The `targetNode` parameter represents the node in the
|
|
9423
9438
|
* binary tree that you want to traverse from. It can be specified either by its key, by the node
|
|
9424
9439
|
* object itself, or it can be left undefined to start the traversal from the root of the tree.
|
|
9425
9440
|
* @param iterationType - The `iterationType` parameter determines the type of traversal to be
|
|
@@ -9591,19 +9606,16 @@ var dataStructureTyped = (() => {
|
|
|
9591
9606
|
/**
|
|
9592
9607
|
* The function compares two values using a comparator function and returns whether the first value
|
|
9593
9608
|
* is greater than, less than, or equal to the second value.
|
|
9594
|
-
* @param {
|
|
9595
|
-
* @param {
|
|
9609
|
+
* @param {K} a - The parameter "a" is of type K.
|
|
9610
|
+
* @param {K} b - The parameter "b" in the above code represents a K.
|
|
9596
9611
|
* @returns a value of type CP (ComparisonResult). The possible return values are CP.gt (greater
|
|
9597
9612
|
* than), CP.lt (less than), or CP.eq (equal).
|
|
9598
9613
|
*/
|
|
9599
9614
|
_compare(a, b) {
|
|
9600
|
-
const
|
|
9601
|
-
|
|
9602
|
-
|
|
9603
|
-
|
|
9604
|
-
return "lt" /* lt */;
|
|
9605
|
-
else
|
|
9606
|
-
return "eq" /* eq */;
|
|
9615
|
+
const extractedA = this.extractor(a);
|
|
9616
|
+
const extractedB = this.extractor(b);
|
|
9617
|
+
const compared = this.variant === "MIN" /* MIN */ ? extractedA - extractedB : extractedB - extractedA;
|
|
9618
|
+
return compared > 0 ? "gt" /* gt */ : compared < 0 ? "lt" /* lt */ : "eq" /* eq */;
|
|
9607
9619
|
}
|
|
9608
9620
|
};
|
|
9609
9621
|
|
|
@@ -10044,7 +10056,7 @@ var dataStructureTyped = (() => {
|
|
|
10044
10056
|
var AVLTree = class _AVLTree extends BST {
|
|
10045
10057
|
/**
|
|
10046
10058
|
* The constructor function initializes an AVLTree object with optional elements and options.
|
|
10047
|
-
* @param [elements] - The `elements` parameter is an optional iterable of `BTNodeExemplar<V, N>`
|
|
10059
|
+
* @param [elements] - The `elements` parameter is an optional iterable of `BTNodeExemplar<K, V, N>`
|
|
10048
10060
|
* objects. It represents a collection of elements that will be added to the AVL tree during
|
|
10049
10061
|
* initialization.
|
|
10050
10062
|
* @param [options] - The `options` parameter is an optional object that allows you to customize the
|
|
@@ -10058,7 +10070,7 @@ var dataStructureTyped = (() => {
|
|
|
10058
10070
|
}
|
|
10059
10071
|
/**
|
|
10060
10072
|
* The function creates a new AVL tree node with the specified key and value.
|
|
10061
|
-
* @param {
|
|
10073
|
+
* @param {K} key - The key parameter is the key value that will be associated with
|
|
10062
10074
|
* the new node. It is used to determine the position of the node in the binary search tree.
|
|
10063
10075
|
* @param [value] - The parameter `value` is an optional value that can be assigned to the node. It is of
|
|
10064
10076
|
* type `V`, which means it can be any value that is assignable to the `value` property of the
|
|
@@ -10078,12 +10090,12 @@ var dataStructureTyped = (() => {
|
|
|
10078
10090
|
createTree(options) {
|
|
10079
10091
|
return new _AVLTree([], __spreadValues({
|
|
10080
10092
|
iterationType: this.iterationType,
|
|
10081
|
-
|
|
10093
|
+
variant: this.variant
|
|
10082
10094
|
}, options));
|
|
10083
10095
|
}
|
|
10084
10096
|
/**
|
|
10085
10097
|
* The function checks if an exemplar is an instance of AVLTreeNode.
|
|
10086
|
-
* @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<V, N>`.
|
|
10098
|
+
* @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`.
|
|
10087
10099
|
* @returns a boolean value indicating whether the exemplar is an instance of the AVLTreeNode class.
|
|
10088
10100
|
*/
|
|
10089
10101
|
isNode(exemplar) {
|
|
@@ -10144,9 +10156,9 @@ var dataStructureTyped = (() => {
|
|
|
10144
10156
|
/**
|
|
10145
10157
|
* The `_swapProperties` function swaps the key, value, and height properties between two nodes in a binary
|
|
10146
10158
|
* tree.
|
|
10147
|
-
* @param {
|
|
10148
|
-
* needs to be swapped with the destination node. It can be of type `
|
|
10149
|
-
* @param {
|
|
10159
|
+
* @param {K | N | undefined} srcNode - The `srcNode` parameter represents the source node that
|
|
10160
|
+
* needs to be swapped with the destination node. It can be of type `K`, `N`, or `undefined`.
|
|
10161
|
+
* @param {K | N | undefined} destNode - The `destNode` parameter represents the destination
|
|
10150
10162
|
* node where the values from the source node will be swapped to.
|
|
10151
10163
|
* @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined`
|
|
10152
10164
|
* if either `srcNode` or `destNode` is undefined.
|
|
@@ -10458,7 +10470,7 @@ var dataStructureTyped = (() => {
|
|
|
10458
10470
|
/**
|
|
10459
10471
|
* This is the constructor function for a Red-Black Tree data structure in TypeScript, which
|
|
10460
10472
|
* initializes the tree with optional elements and options.
|
|
10461
|
-
* @param [elements] - The `elements` parameter is an optional iterable of `BTNodeExemplar<V, N>`
|
|
10473
|
+
* @param [elements] - The `elements` parameter is an optional iterable of `BTNodeExemplar<K, V, N>`
|
|
10462
10474
|
* objects. It represents the initial elements that will be added to the RBTree during its
|
|
10463
10475
|
* construction. If this parameter is provided, the `addMany` method is called to add all the
|
|
10464
10476
|
* elements to the
|
|
@@ -10483,7 +10495,7 @@ var dataStructureTyped = (() => {
|
|
|
10483
10495
|
}
|
|
10484
10496
|
/**
|
|
10485
10497
|
* The function creates a new Red-Black Tree node with the specified key, value, and color.
|
|
10486
|
-
* @param {
|
|
10498
|
+
* @param {K} key - The key parameter is the key value associated with the node. It is used to
|
|
10487
10499
|
* identify and compare nodes in the Red-Black Tree.
|
|
10488
10500
|
* @param {V} [value] - The `value` parameter is an optional parameter that represents the value
|
|
10489
10501
|
* associated with the node. It is of type `V`, which is a generic type that can be replaced with any
|
|
@@ -10506,12 +10518,12 @@ var dataStructureTyped = (() => {
|
|
|
10506
10518
|
createTree(options) {
|
|
10507
10519
|
return new _RedBlackTree([], __spreadValues({
|
|
10508
10520
|
iterationType: this.iterationType,
|
|
10509
|
-
|
|
10521
|
+
variant: this.variant
|
|
10510
10522
|
}, options));
|
|
10511
10523
|
}
|
|
10512
10524
|
/**
|
|
10513
10525
|
* The function checks if an exemplar is an instance of the RedBlackTreeNode class.
|
|
10514
|
-
* @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<V, N>`.
|
|
10526
|
+
* @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`.
|
|
10515
10527
|
* @returns a boolean value indicating whether the exemplar is an instance of the RedBlackTreeNode
|
|
10516
10528
|
* class.
|
|
10517
10529
|
*/
|
|
@@ -10521,7 +10533,7 @@ var dataStructureTyped = (() => {
|
|
|
10521
10533
|
/**
|
|
10522
10534
|
* The function `exemplarToNode` takes an exemplar and returns a node if the exemplar is valid,
|
|
10523
10535
|
* otherwise it returns undefined.
|
|
10524
|
-
* @param exemplar - BTNodeExemplar<V, N> - A generic type representing an exemplar of a binary tree
|
|
10536
|
+
* @param exemplar - BTNodeExemplar<K, V, N> - A generic type representing an exemplar of a binary tree
|
|
10525
10537
|
* node. It can be either a node itself, an entry (key-value pair), a node key, or any other value
|
|
10526
10538
|
* that is not a valid exemplar.
|
|
10527
10539
|
* @returns a variable `node` which is of type `N | undefined`.
|
|
@@ -10539,7 +10551,7 @@ var dataStructureTyped = (() => {
|
|
|
10539
10551
|
} else {
|
|
10540
10552
|
node = this.createNode(key, value, 1 /* RED */);
|
|
10541
10553
|
}
|
|
10542
|
-
} else if (this.
|
|
10554
|
+
} else if (this.isNotNodeInstance(exemplar)) {
|
|
10543
10555
|
node = this.createNode(exemplar, void 0, 1 /* RED */);
|
|
10544
10556
|
} else {
|
|
10545
10557
|
return;
|
|
@@ -10695,7 +10707,7 @@ var dataStructureTyped = (() => {
|
|
|
10695
10707
|
* @param {C} callback - The `callback` parameter is a function that will be called for each node in
|
|
10696
10708
|
* the binary tree. It is used to determine if a node matches the given identifier. The `callback`
|
|
10697
10709
|
* function should take a single parameter of type `N` (the type of the nodes in the binary tree) and
|
|
10698
|
-
* @param {
|
|
10710
|
+
* @param {K | N | undefined} beginRoot - The `beginRoot` parameter is the starting point for
|
|
10699
10711
|
* searching for a node in a binary tree. It can be either a key value or a node object. If it is not
|
|
10700
10712
|
* provided, the search will start from the root of the binary tree.
|
|
10701
10713
|
* @param iterationType - The `iterationType` parameter is a variable that determines the type of
|
|
@@ -11002,7 +11014,7 @@ var dataStructureTyped = (() => {
|
|
|
11002
11014
|
var TreeMultimapNode = class extends AVLTreeNode {
|
|
11003
11015
|
/**
|
|
11004
11016
|
* The constructor function initializes a BinaryTreeNode object with a key, value, and count.
|
|
11005
|
-
* @param {
|
|
11017
|
+
* @param {K} key - The `key` parameter is of type `K` and represents the unique identifier
|
|
11006
11018
|
* of the binary tree node.
|
|
11007
11019
|
* @param {V} [value] - The `value` parameter is an optional parameter of type `V`. It represents the value of the binary
|
|
11008
11020
|
* tree node. If no value is provided, it will be `undefined`.
|
|
@@ -11031,7 +11043,7 @@ var dataStructureTyped = (() => {
|
|
|
11031
11043
|
}
|
|
11032
11044
|
/**
|
|
11033
11045
|
* The function creates a new BSTNode with the given key, value, and count.
|
|
11034
|
-
* @param {
|
|
11046
|
+
* @param {K} key - The key parameter is the unique identifier for the binary tree node. It is used to
|
|
11035
11047
|
* distinguish one node from another in the tree.
|
|
11036
11048
|
* @param {N} value - The `value` parameter represents the value that will be stored in the binary search tree node.
|
|
11037
11049
|
* @param {number} [count] - The "count" parameter is an optional parameter of type number. It represents the number of
|
|
@@ -11044,12 +11056,12 @@ var dataStructureTyped = (() => {
|
|
|
11044
11056
|
createTree(options) {
|
|
11045
11057
|
return new _TreeMultimap([], __spreadValues({
|
|
11046
11058
|
iterationType: this.iterationType,
|
|
11047
|
-
|
|
11059
|
+
variant: this.variant
|
|
11048
11060
|
}, options));
|
|
11049
11061
|
}
|
|
11050
11062
|
/**
|
|
11051
11063
|
* The function checks if an exemplar is an instance of the TreeMultimapNode class.
|
|
11052
|
-
* @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<V, N>`.
|
|
11064
|
+
* @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`.
|
|
11053
11065
|
* @returns a boolean value indicating whether the exemplar is an instance of the TreeMultimapNode
|
|
11054
11066
|
* class.
|
|
11055
11067
|
*/
|
|
@@ -11058,7 +11070,7 @@ var dataStructureTyped = (() => {
|
|
|
11058
11070
|
}
|
|
11059
11071
|
/**
|
|
11060
11072
|
* The function `exemplarToNode` converts an exemplar object into a node object.
|
|
11061
|
-
* @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<V, N>`, where `V` represents
|
|
11073
|
+
* @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`, where `V` represents
|
|
11062
11074
|
* the value type and `N` represents the node type.
|
|
11063
11075
|
* @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
|
|
11064
11076
|
* times the node should be created. If not provided, it defaults to 1.
|
|
@@ -11077,7 +11089,7 @@ var dataStructureTyped = (() => {
|
|
|
11077
11089
|
} else {
|
|
11078
11090
|
node = this.createNode(key, value, count);
|
|
11079
11091
|
}
|
|
11080
|
-
} else if (this.
|
|
11092
|
+
} else if (this.isNotNodeInstance(exemplar)) {
|
|
11081
11093
|
node = this.createNode(exemplar, void 0, count);
|
|
11082
11094
|
} else {
|
|
11083
11095
|
return;
|
|
@@ -11289,9 +11301,9 @@ var dataStructureTyped = (() => {
|
|
|
11289
11301
|
* @param {N | undefined} newNode - The `newNode` parameter represents the node that needs to be
|
|
11290
11302
|
* added to the binary tree. It can be of type `N` (which represents a node in the binary tree) or
|
|
11291
11303
|
* `undefined` if there is no node to add.
|
|
11292
|
-
* @param {
|
|
11304
|
+
* @param {K | N | undefined} parent - The `parent` parameter represents the parent node to
|
|
11293
11305
|
* which the new node will be added as a child. It can be either a node object (`N`) or a key value
|
|
11294
|
-
* (`
|
|
11306
|
+
* (`K`).
|
|
11295
11307
|
* @returns The method `_addTo` returns either the `parent.left` or `parent.right` node that was
|
|
11296
11308
|
* added, or `undefined` if no node was added.
|
|
11297
11309
|
*/
|
|
@@ -11321,9 +11333,9 @@ var dataStructureTyped = (() => {
|
|
|
11321
11333
|
}
|
|
11322
11334
|
/**
|
|
11323
11335
|
* The `_swapProperties` function swaps the key, value, count, and height properties between two nodes.
|
|
11324
|
-
* @param {
|
|
11325
|
-
* which the values will be swapped. It can be of type `
|
|
11326
|
-
* @param {
|
|
11336
|
+
* @param {K | N | undefined} srcNode - The `srcNode` parameter represents the source node from
|
|
11337
|
+
* which the values will be swapped. It can be of type `K`, `N`, or `undefined`.
|
|
11338
|
+
* @param {K | N | undefined} destNode - The `destNode` parameter represents the destination
|
|
11327
11339
|
* node where the values from the source node will be swapped to.
|
|
11328
11340
|
* @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined`
|
|
11329
11341
|
* if either `srcNode` or `destNode` is undefined.
|