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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "data-structure-typed",
|
|
3
|
-
"version": "1.51.
|
|
3
|
+
"version": "1.51.4",
|
|
4
4
|
"description": "Javascript Data Structure. Heap, Binary Tree, Red Black Tree, Linked List, Deque, Trie, HashMap, Directed Graph, Undirected Graph, Binary Search Tree(BST), AVL Tree, Priority Queue, Graph, Queue, Tree Multiset, Singly Linked List, Doubly Linked List, Max Heap, Max Priority Queue, Min Heap, Min Priority Queue, Stack. Benchmark compared with C++ STL. API aligned with ES6 and Java.util. Usability is comparable to Python",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/mjs/index.js",
|
|
@@ -66,11 +66,11 @@
|
|
|
66
66
|
"@typescript-eslint/eslint-plugin": "^6.7.4",
|
|
67
67
|
"@typescript-eslint/parser": "^6.7.4",
|
|
68
68
|
"auto-changelog": "^2.4.0",
|
|
69
|
-
"avl-tree-typed": "^1.51.
|
|
69
|
+
"avl-tree-typed": "^1.51.3",
|
|
70
70
|
"benchmark": "^2.1.4",
|
|
71
|
-
"binary-tree-typed": "^1.51.
|
|
72
|
-
"bst-typed": "^1.51.
|
|
73
|
-
"data-structure-typed": "^1.51.
|
|
71
|
+
"binary-tree-typed": "^1.51.3",
|
|
72
|
+
"bst-typed": "^1.51.3",
|
|
73
|
+
"data-structure-typed": "^1.51.3",
|
|
74
74
|
"dependency-cruiser": "^14.1.0",
|
|
75
75
|
"doctoc": "^2.2.1",
|
|
76
76
|
"eslint": "^8.50.0",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"eslint-import-resolver-typescript": "^3.6.1",
|
|
80
80
|
"eslint-plugin-import": "^2.28.1",
|
|
81
81
|
"fast-glob": "^3.3.1",
|
|
82
|
-
"heap-typed": "^1.51.
|
|
82
|
+
"heap-typed": "^1.51.3",
|
|
83
83
|
"istanbul-badges-readme": "^1.8.5",
|
|
84
84
|
"jest": "^29.7.0",
|
|
85
85
|
"js-sdsl": "^4.4.2",
|
|
@@ -316,8 +316,8 @@ export class BinaryTree<
|
|
|
316
316
|
* @returns a boolean value.
|
|
317
317
|
*/
|
|
318
318
|
isRealNode(node: KeyOrNodeOrEntry<K, V, NODE>): node is NODE {
|
|
319
|
-
if (
|
|
320
|
-
return
|
|
319
|
+
if (node === this.NIL || node === null || node === undefined) return false;
|
|
320
|
+
return this.isNode(node);
|
|
321
321
|
}
|
|
322
322
|
|
|
323
323
|
/**
|
|
@@ -695,7 +695,7 @@ export class BST<
|
|
|
695
695
|
if (!current) return undefined;
|
|
696
696
|
|
|
697
697
|
if (this._variant === 'STANDARD') {
|
|
698
|
-
// For
|
|
698
|
+
// For 'STANDARD', find the rightmost node
|
|
699
699
|
while (current.right !== undefined) {
|
|
700
700
|
current = current.right;
|
|
701
701
|
}
|
|
@@ -4,9 +4,9 @@ export * from './stack';
|
|
|
4
4
|
export * from './queue';
|
|
5
5
|
export * from './graph';
|
|
6
6
|
export * from './binary-tree';
|
|
7
|
-
export * from './tree';
|
|
8
7
|
export * from './heap';
|
|
9
8
|
export * from './priority-queue';
|
|
10
9
|
export * from './matrix';
|
|
11
10
|
export * from './trie';
|
|
12
11
|
export * from './base';
|
|
12
|
+
export * from './tree';
|
package/src/utils/index.ts
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function toBinaryString(num: number, digit = 32) {
|
|
2
|
+
// Convert number to binary string
|
|
3
|
+
let binaryString = (num >>> 0).toString(2); // Use the unsigned right shift operator to ensure you get a binary representation of a 32-bit unsigned integer
|
|
4
|
+
|
|
5
|
+
// Use pad Start to ensure the string length is 32 bits
|
|
6
|
+
binaryString = binaryString.padStart(digit, '0');
|
|
7
|
+
|
|
8
|
+
return binaryString;
|
|
9
|
+
}
|
|
File without changes
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { TreeNode } from '../../../../src';
|
|
2
|
-
|
|
3
|
-
describe('TreeNode', () => {
|
|
4
|
-
it('should create a TreeNode with the given key and value', () => {
|
|
5
|
-
const node = new TreeNode<string>('1', 'Node 1');
|
|
6
|
-
expect(node.key).toBe('1');
|
|
7
|
-
expect(node.value).toBe('Node 1');
|
|
8
|
-
expect(node.children).toEqual([]);
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
it('should add children to the TreeNode', () => {
|
|
12
|
-
const parentNode = new TreeNode<string>('1', 'Parent Node');
|
|
13
|
-
const child1 = new TreeNode<string>('2', 'Child 1');
|
|
14
|
-
const child2 = new TreeNode<string>('3', 'Child 2');
|
|
15
|
-
|
|
16
|
-
parentNode.addChildren([child1, child2]);
|
|
17
|
-
|
|
18
|
-
expect(parentNode.children).toEqual([child1, child2]);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('should calculate the height of the tree correctly', () => {
|
|
22
|
-
const rootNode = new TreeNode<string>('1', 'Root Node');
|
|
23
|
-
const child1 = new TreeNode<string>('2', 'Child 1');
|
|
24
|
-
const child2 = new TreeNode<string>('3', 'Child 2');
|
|
25
|
-
const grandchild1 = new TreeNode<string>('4', 'Grandchild 1');
|
|
26
|
-
const grandchild2 = new TreeNode<string>('5', 'Grandchild 2');
|
|
27
|
-
|
|
28
|
-
rootNode.addChildren([child1, child2]);
|
|
29
|
-
child1.addChildren([grandchild1]);
|
|
30
|
-
child2.addChildren([grandchild2]);
|
|
31
|
-
|
|
32
|
-
expect(rootNode.getHeight()).toBe(2); // Height of the tree should be 2
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('should handle nodes without children when calculating height', () => {
|
|
36
|
-
const rootNode = new TreeNode<string>('1', 'Root Node');
|
|
37
|
-
expect(rootNode.getHeight()).toBe(0); // Height of a single node should be 0
|
|
38
|
-
});
|
|
39
|
-
});
|