data-structure-typed 1.51.3 → 1.51.4
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/POSTS_zh-CN.md +54 -0
- package/README.md +3 -0
- package/benchmark/report.html +1 -37
- package/benchmark/report.json +3 -405
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +2 -2
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.js +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/index.d.ts +1 -1
- package/dist/cjs/data-structures/index.js +1 -1
- package/dist/cjs/data-structures/index.js.map +1 -1
- package/dist/cjs/utils/index.d.ts +1 -0
- package/dist/cjs/utils/index.js +1 -0
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/number.d.ts +1 -0
- package/dist/cjs/utils/number.js +12 -0
- package/dist/cjs/utils/number.js.map +1 -0
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +2 -2
- package/dist/mjs/data-structures/binary-tree/bst.js +1 -1
- package/dist/mjs/data-structures/index.d.ts +1 -1
- package/dist/mjs/data-structures/index.js +1 -1
- package/dist/mjs/utils/index.d.ts +1 -0
- package/dist/mjs/utils/index.js +1 -0
- package/dist/mjs/utils/number.d.ts +1 -0
- package/dist/mjs/utils/number.js +7 -0
- package/dist/umd/data-structure-typed.js +116 -108
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +6 -6
- package/src/data-structures/binary-tree/binary-tree.ts +2 -2
- package/src/data-structures/binary-tree/bst.ts +1 -1
- package/src/data-structures/index.ts +1 -1
- package/src/utils/index.ts +1 -0
- package/src/utils/number.ts +9 -0
- package/test/performance/data-structures/tree/tree.test.ts +0 -0
- package/test/unit/data-structures/tree/tree.test.ts +0 -39
|
@@ -165,6 +165,7 @@ var dataStructureTyped = (() => {
|
|
|
165
165
|
rangeCheck: () => rangeCheck,
|
|
166
166
|
roundFixed: () => roundFixed,
|
|
167
167
|
throwRangeError: () => throwRangeError,
|
|
168
|
+
toBinaryString: () => toBinaryString,
|
|
168
169
|
toThunk: () => toThunk,
|
|
169
170
|
trampoline: () => trampoline,
|
|
170
171
|
trampolineAsync: () => trampolineAsync,
|
|
@@ -711,6 +712,13 @@ var dataStructureTyped = (() => {
|
|
|
711
712
|
return Math.round(num * multiplier) / multiplier;
|
|
712
713
|
};
|
|
713
714
|
|
|
715
|
+
// src/utils/number.ts
|
|
716
|
+
function toBinaryString(num, digit = 32) {
|
|
717
|
+
let binaryString = (num >>> 0).toString(2);
|
|
718
|
+
binaryString = binaryString.padStart(digit, "0");
|
|
719
|
+
return binaryString;
|
|
720
|
+
}
|
|
721
|
+
|
|
714
722
|
// src/data-structures/hash/hash-map.ts
|
|
715
723
|
var HashMap = class _HashMap extends IterableEntryBase {
|
|
716
724
|
/**
|
|
@@ -7891,9 +7899,9 @@ var dataStructureTyped = (() => {
|
|
|
7891
7899
|
* @returns a boolean value.
|
|
7892
7900
|
*/
|
|
7893
7901
|
isRealNode(node) {
|
|
7894
|
-
if (
|
|
7902
|
+
if (node === this.NIL || node === null || node === void 0)
|
|
7895
7903
|
return false;
|
|
7896
|
-
return
|
|
7904
|
+
return this.isNode(node);
|
|
7897
7905
|
}
|
|
7898
7906
|
/**
|
|
7899
7907
|
* The function checks if a given node is a BinaryTreeNode instance and has a key value of NaN.
|
|
@@ -12489,112 +12497,6 @@ var dataStructureTyped = (() => {
|
|
|
12489
12497
|
}
|
|
12490
12498
|
};
|
|
12491
12499
|
|
|
12492
|
-
// src/data-structures/tree/tree.ts
|
|
12493
|
-
var TreeNode = class _TreeNode {
|
|
12494
|
-
/**
|
|
12495
|
-
* The constructor function initializes a TreeNode object with a key, optional value, and optional
|
|
12496
|
-
* children.
|
|
12497
|
-
* @param {string} key - A string representing the key of the tree node.
|
|
12498
|
-
* @param {V} [value] - The `value` parameter is an optional parameter of type `V`. It represents the
|
|
12499
|
-
* value associated with the node. If no value is provided, it defaults to `undefined`.
|
|
12500
|
-
* @param {TreeNode<V>[]} [children] - The `children` parameter is an optional array of `TreeNode<V>`
|
|
12501
|
-
* objects. It represents the child nodes of the current node. If no children are provided, the
|
|
12502
|
-
* default value is an empty array.
|
|
12503
|
-
*/
|
|
12504
|
-
constructor(key, value, children) {
|
|
12505
|
-
__publicField(this, "_key");
|
|
12506
|
-
__publicField(this, "_value");
|
|
12507
|
-
__publicField(this, "_children");
|
|
12508
|
-
this._key = key;
|
|
12509
|
-
this._value = value || void 0;
|
|
12510
|
-
this._children = children || [];
|
|
12511
|
-
}
|
|
12512
|
-
/**
|
|
12513
|
-
* The function returns the value of the protected variable _key.
|
|
12514
|
-
* @returns The value of the `_key` property, which is a string.
|
|
12515
|
-
*/
|
|
12516
|
-
get key() {
|
|
12517
|
-
return this._key;
|
|
12518
|
-
}
|
|
12519
|
-
/**
|
|
12520
|
-
* The above function sets the value of a protected variable called "key".
|
|
12521
|
-
* @param {string} value - The value parameter is a string that represents the value to be assigned
|
|
12522
|
-
* to the key.
|
|
12523
|
-
*/
|
|
12524
|
-
set key(value) {
|
|
12525
|
-
this._key = value;
|
|
12526
|
-
}
|
|
12527
|
-
/**
|
|
12528
|
-
* The function returns the value stored in a variable, or undefined if the variable is empty.
|
|
12529
|
-
* @returns The value of the variable `_value` is being returned.
|
|
12530
|
-
*/
|
|
12531
|
-
get value() {
|
|
12532
|
-
return this._value;
|
|
12533
|
-
}
|
|
12534
|
-
/**
|
|
12535
|
-
* The function sets the value of a variable.
|
|
12536
|
-
* @param {V | undefined} value - The parameter "value" is of type "V | undefined", which means it
|
|
12537
|
-
* can accept a value of type "V" or it can be undefined.
|
|
12538
|
-
*/
|
|
12539
|
-
set value(value) {
|
|
12540
|
-
this._value = value;
|
|
12541
|
-
}
|
|
12542
|
-
/**
|
|
12543
|
-
* The function returns an array of TreeNode objects or undefined.
|
|
12544
|
-
* @returns The `children` property is being returned. It is of type `TreeNode<V>[] | undefined`,
|
|
12545
|
-
* which means it can either be an array of `TreeNode<V>` objects or `undefined`.
|
|
12546
|
-
*/
|
|
12547
|
-
get children() {
|
|
12548
|
-
return this._children;
|
|
12549
|
-
}
|
|
12550
|
-
/**
|
|
12551
|
-
* The function sets the value of the children property of a TreeNode object.
|
|
12552
|
-
* @param {TreeNode<V>[] | undefined} value - The value parameter is of type TreeNode<V>[] |
|
|
12553
|
-
* undefined. This means that it can accept an array of TreeNode objects or undefined.
|
|
12554
|
-
*/
|
|
12555
|
-
set children(value) {
|
|
12556
|
-
this._children = value;
|
|
12557
|
-
}
|
|
12558
|
-
/**
|
|
12559
|
-
* The function `addChildren` adds one or more child nodes to the current node.
|
|
12560
|
-
* @param {TreeNode<V> | TreeNode<V>[]} children - The `children` parameter can be either a single
|
|
12561
|
-
* `TreeNode<V>` object or an array of `TreeNode<V>` objects.
|
|
12562
|
-
*/
|
|
12563
|
-
addChildren(children) {
|
|
12564
|
-
if (!this._children) {
|
|
12565
|
-
this._children = [];
|
|
12566
|
-
}
|
|
12567
|
-
if (children instanceof _TreeNode) {
|
|
12568
|
-
this._children.push(children);
|
|
12569
|
-
} else {
|
|
12570
|
-
this._children = this._children.concat(children);
|
|
12571
|
-
}
|
|
12572
|
-
}
|
|
12573
|
-
/**
|
|
12574
|
-
* The function `getHeight()` calculates the maximum depth of a tree structure by performing a
|
|
12575
|
-
* breadth-first search.
|
|
12576
|
-
* @returns the maximum depth or height of the tree.
|
|
12577
|
-
*/
|
|
12578
|
-
getHeight() {
|
|
12579
|
-
let maxDepth = 0;
|
|
12580
|
-
if (this) {
|
|
12581
|
-
const bfs = (node, level) => {
|
|
12582
|
-
if (level > maxDepth) {
|
|
12583
|
-
maxDepth = level;
|
|
12584
|
-
}
|
|
12585
|
-
const { _children } = node;
|
|
12586
|
-
if (_children) {
|
|
12587
|
-
for (let i = 0, len = _children.length; i < len; i++) {
|
|
12588
|
-
bfs(_children[i], level + 1);
|
|
12589
|
-
}
|
|
12590
|
-
}
|
|
12591
|
-
};
|
|
12592
|
-
bfs(this, 0);
|
|
12593
|
-
}
|
|
12594
|
-
return maxDepth;
|
|
12595
|
-
}
|
|
12596
|
-
};
|
|
12597
|
-
|
|
12598
12500
|
// src/data-structures/priority-queue/priority-queue.ts
|
|
12599
12501
|
var PriorityQueue = class extends Heap {
|
|
12600
12502
|
/**
|
|
@@ -13717,6 +13619,112 @@ var dataStructureTyped = (() => {
|
|
|
13717
13619
|
return str;
|
|
13718
13620
|
}
|
|
13719
13621
|
};
|
|
13622
|
+
|
|
13623
|
+
// src/data-structures/tree/tree.ts
|
|
13624
|
+
var TreeNode = class _TreeNode {
|
|
13625
|
+
/**
|
|
13626
|
+
* The constructor function initializes a TreeNode object with a key, optional value, and optional
|
|
13627
|
+
* children.
|
|
13628
|
+
* @param {string} key - A string representing the key of the tree node.
|
|
13629
|
+
* @param {V} [value] - The `value` parameter is an optional parameter of type `V`. It represents the
|
|
13630
|
+
* value associated with the node. If no value is provided, it defaults to `undefined`.
|
|
13631
|
+
* @param {TreeNode<V>[]} [children] - The `children` parameter is an optional array of `TreeNode<V>`
|
|
13632
|
+
* objects. It represents the child nodes of the current node. If no children are provided, the
|
|
13633
|
+
* default value is an empty array.
|
|
13634
|
+
*/
|
|
13635
|
+
constructor(key, value, children) {
|
|
13636
|
+
__publicField(this, "_key");
|
|
13637
|
+
__publicField(this, "_value");
|
|
13638
|
+
__publicField(this, "_children");
|
|
13639
|
+
this._key = key;
|
|
13640
|
+
this._value = value || void 0;
|
|
13641
|
+
this._children = children || [];
|
|
13642
|
+
}
|
|
13643
|
+
/**
|
|
13644
|
+
* The function returns the value of the protected variable _key.
|
|
13645
|
+
* @returns The value of the `_key` property, which is a string.
|
|
13646
|
+
*/
|
|
13647
|
+
get key() {
|
|
13648
|
+
return this._key;
|
|
13649
|
+
}
|
|
13650
|
+
/**
|
|
13651
|
+
* The above function sets the value of a protected variable called "key".
|
|
13652
|
+
* @param {string} value - The value parameter is a string that represents the value to be assigned
|
|
13653
|
+
* to the key.
|
|
13654
|
+
*/
|
|
13655
|
+
set key(value) {
|
|
13656
|
+
this._key = value;
|
|
13657
|
+
}
|
|
13658
|
+
/**
|
|
13659
|
+
* The function returns the value stored in a variable, or undefined if the variable is empty.
|
|
13660
|
+
* @returns The value of the variable `_value` is being returned.
|
|
13661
|
+
*/
|
|
13662
|
+
get value() {
|
|
13663
|
+
return this._value;
|
|
13664
|
+
}
|
|
13665
|
+
/**
|
|
13666
|
+
* The function sets the value of a variable.
|
|
13667
|
+
* @param {V | undefined} value - The parameter "value" is of type "V | undefined", which means it
|
|
13668
|
+
* can accept a value of type "V" or it can be undefined.
|
|
13669
|
+
*/
|
|
13670
|
+
set value(value) {
|
|
13671
|
+
this._value = value;
|
|
13672
|
+
}
|
|
13673
|
+
/**
|
|
13674
|
+
* The function returns an array of TreeNode objects or undefined.
|
|
13675
|
+
* @returns The `children` property is being returned. It is of type `TreeNode<V>[] | undefined`,
|
|
13676
|
+
* which means it can either be an array of `TreeNode<V>` objects or `undefined`.
|
|
13677
|
+
*/
|
|
13678
|
+
get children() {
|
|
13679
|
+
return this._children;
|
|
13680
|
+
}
|
|
13681
|
+
/**
|
|
13682
|
+
* The function sets the value of the children property of a TreeNode object.
|
|
13683
|
+
* @param {TreeNode<V>[] | undefined} value - The value parameter is of type TreeNode<V>[] |
|
|
13684
|
+
* undefined. This means that it can accept an array of TreeNode objects or undefined.
|
|
13685
|
+
*/
|
|
13686
|
+
set children(value) {
|
|
13687
|
+
this._children = value;
|
|
13688
|
+
}
|
|
13689
|
+
/**
|
|
13690
|
+
* The function `addChildren` adds one or more child nodes to the current node.
|
|
13691
|
+
* @param {TreeNode<V> | TreeNode<V>[]} children - The `children` parameter can be either a single
|
|
13692
|
+
* `TreeNode<V>` object or an array of `TreeNode<V>` objects.
|
|
13693
|
+
*/
|
|
13694
|
+
addChildren(children) {
|
|
13695
|
+
if (!this._children) {
|
|
13696
|
+
this._children = [];
|
|
13697
|
+
}
|
|
13698
|
+
if (children instanceof _TreeNode) {
|
|
13699
|
+
this._children.push(children);
|
|
13700
|
+
} else {
|
|
13701
|
+
this._children = this._children.concat(children);
|
|
13702
|
+
}
|
|
13703
|
+
}
|
|
13704
|
+
/**
|
|
13705
|
+
* The function `getHeight()` calculates the maximum depth of a tree structure by performing a
|
|
13706
|
+
* breadth-first search.
|
|
13707
|
+
* @returns the maximum depth or height of the tree.
|
|
13708
|
+
*/
|
|
13709
|
+
getHeight() {
|
|
13710
|
+
let maxDepth = 0;
|
|
13711
|
+
if (this) {
|
|
13712
|
+
const bfs = (node, level) => {
|
|
13713
|
+
if (level > maxDepth) {
|
|
13714
|
+
maxDepth = level;
|
|
13715
|
+
}
|
|
13716
|
+
const { _children } = node;
|
|
13717
|
+
if (_children) {
|
|
13718
|
+
for (let i = 0, len = _children.length; i < len; i++) {
|
|
13719
|
+
bfs(_children[i], level + 1);
|
|
13720
|
+
}
|
|
13721
|
+
}
|
|
13722
|
+
};
|
|
13723
|
+
bfs(this, 0);
|
|
13724
|
+
}
|
|
13725
|
+
return maxDepth;
|
|
13726
|
+
}
|
|
13727
|
+
};
|
|
13720
13728
|
return __toCommonJS(src_exports);
|
|
13721
13729
|
})();
|
|
13722
13730
|
/**
|