data-structure-typed 1.35.0 → 1.35.1
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/.github/workflows/ci.yml +3 -0
- package/CHANGELOG.md +3 -1
- package/CONTRIBUTING.md +18 -0
- package/package.json +6 -6
- package/test/integration/avl-tree.test.ts +4 -4
- package/test/integration/bst.test.ts +8 -8
- package/test/unit/data-structures/graph/directed-graph.test.ts +5 -5
- package/test/unit/data-structures/graph/overall.test.ts +2 -2
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +1 -1
- package/test/unit/data-structures/graph/index.ts +0 -2
- package/test/unit/data-structures/linked-list/index.ts +0 -4
package/.github/workflows/ci.yml
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -8,7 +8,9 @@ All notable changes to this project will be documented in this file.
|
|
|
8
8
|
- [Semantic Versioning](https://semver.org/spec/v2.0.0.html)
|
|
9
9
|
- [`auto-changelog`](https://github.com/CookPete/auto-changelog)
|
|
10
10
|
|
|
11
|
-
## [v1.
|
|
11
|
+
## [v1.35.1](https://github.com/zrwusa/data-structure-typed/compare/v1.35.0...main) (upcoming)
|
|
12
|
+
|
|
13
|
+
## [v1.35.0](https://github.com/zrwusa/data-structure-typed/compare/v1.34.1...v1.35.0) (11 October 2023)
|
|
12
14
|
|
|
13
15
|
## [v1.34.1](https://github.com/zrwusa/data-structure-typed/compare/v1.33.4...v1.34.1) (6 October 2023)
|
|
14
16
|
|
package/CONTRIBUTING.md
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
## Contributing
|
|
2
|
+
|
|
3
|
+
**General Rules**
|
|
4
|
+
|
|
5
|
+
- As much as possible, try to follow the existing format of markdown and code.
|
|
6
|
+
- Don't forget to run `npm run lint` and `npm test` before submitting pull requests.
|
|
7
|
+
- Make sure that **100%** of your code is covered by tests.
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
**Contributing New Data Structures**
|
|
11
|
+
|
|
12
|
+
- Make your pull requests to be **specific** and **focused**. Instead of
|
|
13
|
+
contributing "several data structures" all at once contribute them all
|
|
14
|
+
one by one separately (i.e. one pull request for "RBTree", another one
|
|
15
|
+
for "AATree" and so on).
|
|
16
|
+
- Provide **README.md** for each of the data structure **with explanations** of
|
|
17
|
+
the algorithm and **with links** to further readings.
|
|
18
|
+
- Describe what you do in code using **comments**.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "data-structure-typed",
|
|
3
|
-
"version": "1.35.
|
|
3
|
+
"version": "1.35.1",
|
|
4
4
|
"description": "Data Structures of Javascript & TypeScript. Binary Tree, BST, Graph, Heap, Priority Queue, Linked List, Queue, Deque, Stack, AVL Tree, Tree Multiset, Trie, Directed Graph, Undirected Graph, Singly Linked List, Doubly Linked List, Max Heap, Max Priority Queue, Min Heap, Min Priority Queue.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"check:deps": "dependency-cruiser src",
|
|
29
29
|
"changelog": "auto-changelog",
|
|
30
30
|
"coverage:badge": "istanbul-badges-readme",
|
|
31
|
-
"ci": "env && npm run lint && npm run build && npm run test && git fetch --tags && npm run changelog"
|
|
31
|
+
"ci": "env && npm run lint && npm run build && npm run update:individuals && npm run test && git fetch --tags && npm run changelog"
|
|
32
32
|
},
|
|
33
33
|
"repository": {
|
|
34
34
|
"type": "git",
|
|
@@ -50,17 +50,17 @@
|
|
|
50
50
|
"@typescript-eslint/eslint-plugin": "^6.7.4",
|
|
51
51
|
"@typescript-eslint/parser": "^6.7.4",
|
|
52
52
|
"auto-changelog": "^2.4.0",
|
|
53
|
-
"avl-tree-typed": "^1.
|
|
53
|
+
"avl-tree-typed": "^1.35.0",
|
|
54
54
|
"benchmark": "^2.1.4",
|
|
55
|
-
"binary-tree-typed": "^1.
|
|
56
|
-
"bst-typed": "^1.
|
|
55
|
+
"binary-tree-typed": "^1.35.0",
|
|
56
|
+
"bst-typed": "^1.35.0",
|
|
57
57
|
"dependency-cruiser": "^14.1.0",
|
|
58
58
|
"eslint": "^8.50.0",
|
|
59
59
|
"eslint-config-prettier": "^9.0.0",
|
|
60
60
|
"eslint-import-resolver-alias": "^1.1.2",
|
|
61
61
|
"eslint-import-resolver-typescript": "^3.6.1",
|
|
62
62
|
"eslint-plugin-import": "^2.28.1",
|
|
63
|
-
"heap-typed": "^1.
|
|
63
|
+
"heap-typed": "^1.35.0",
|
|
64
64
|
"istanbul-badges-readme": "^1.8.5",
|
|
65
65
|
"jest": "^29.7.0",
|
|
66
66
|
"prettier": "^3.0.3",
|
|
@@ -31,12 +31,12 @@ describe('AVL Tree Test', () => {
|
|
|
31
31
|
// node15 has type problem. After the uniform design, the generics of containers (DirectedGraph, BST) are based on the type of value. However, this design has a drawback: when I attempt to inherit from the Vertex or BSTNode classes, the types of the results obtained by all methods are those of the parent class.
|
|
32
32
|
expect(node15?.val).toBe(15);
|
|
33
33
|
|
|
34
|
-
const dfs = tree.
|
|
34
|
+
const dfs = tree.dfs('in', 'node');
|
|
35
35
|
expect(dfs[0].key).toBe(1);
|
|
36
36
|
expect(dfs[dfs.length - 1].key).toBe(16);
|
|
37
37
|
|
|
38
38
|
tree.perfectlyBalance();
|
|
39
|
-
const bfs = tree.
|
|
39
|
+
const bfs = tree.bfs('node');
|
|
40
40
|
expect(tree.isPerfectlyBalanced()).toBe(true);
|
|
41
41
|
expect(bfs[0].key).toBe(8);
|
|
42
42
|
expect(bfs[bfs.length - 1].key).toBe(16);
|
|
@@ -95,12 +95,12 @@ describe('AVL Tree Test', () => {
|
|
|
95
95
|
expect(tree.getHeight()).toBe(1);
|
|
96
96
|
|
|
97
97
|
expect(tree.isAVLBalanced()).toBe(true);
|
|
98
|
-
const lastBFSIds = tree.
|
|
98
|
+
const lastBFSIds = tree.bfs();
|
|
99
99
|
expect(lastBFSIds[0]).toBe(12);
|
|
100
100
|
expect(lastBFSIds[1]).toBe(2);
|
|
101
101
|
expect(lastBFSIds[2]).toBe(16);
|
|
102
102
|
|
|
103
|
-
const lastBFSNodes = tree.
|
|
103
|
+
const lastBFSNodes = tree.bfs('node');
|
|
104
104
|
expect(lastBFSNodes[0].key).toBe(12);
|
|
105
105
|
expect(lastBFSNodes[1].key).toBe(2);
|
|
106
106
|
expect(lastBFSNodes[2].key).toBe(16);
|
|
@@ -44,14 +44,14 @@ describe('Individual package BST operations test', () => {
|
|
|
44
44
|
const node11 = bst.get(11);
|
|
45
45
|
expect(node11).toBeInstanceOf(BSTNode);
|
|
46
46
|
|
|
47
|
-
const dfsInorderNodes = bst.
|
|
47
|
+
const dfsInorderNodes = bst.dfs('in', 'node');
|
|
48
48
|
expect(dfsInorderNodes[0].key).toBe(1);
|
|
49
49
|
expect(dfsInorderNodes[dfsInorderNodes.length - 1].key).toBe(16);
|
|
50
50
|
|
|
51
51
|
bst.perfectlyBalance();
|
|
52
52
|
expect(bst.isPerfectlyBalanced()).toBe(true);
|
|
53
53
|
|
|
54
|
-
const bfsNodesAfterBalanced = bst.
|
|
54
|
+
const bfsNodesAfterBalanced = bst.bfs('node');
|
|
55
55
|
expect(bfsNodesAfterBalanced[0].key).toBe(8);
|
|
56
56
|
expect(bfsNodesAfterBalanced[bfsNodesAfterBalanced.length - 1].key).toBe(16);
|
|
57
57
|
|
|
@@ -169,12 +169,12 @@ describe('Individual package BST operations test', () => {
|
|
|
169
169
|
|
|
170
170
|
expect(bst.isAVLBalanced()).toBe(false);
|
|
171
171
|
|
|
172
|
-
const bfsIDs = bst.
|
|
172
|
+
const bfsIDs = bst.bfs();
|
|
173
173
|
expect(bfsIDs[0]).toBe(2);
|
|
174
174
|
expect(bfsIDs[1]).toBe(12);
|
|
175
175
|
expect(bfsIDs[2]).toBe(16);
|
|
176
176
|
|
|
177
|
-
const bfsNodes = bst.
|
|
177
|
+
const bfsNodes = bst.bfs('node');
|
|
178
178
|
expect(bfsNodes[0].key).toBe(2);
|
|
179
179
|
expect(bfsNodes[1].key).toBe(12);
|
|
180
180
|
expect(bfsNodes[2].key).toBe(16);
|
|
@@ -242,14 +242,14 @@ describe('Individual package BST operations test', () => {
|
|
|
242
242
|
const node11 = objBST.get(11);
|
|
243
243
|
expect(node11).toBeInstanceOf(BSTNode);
|
|
244
244
|
|
|
245
|
-
const dfsInorderNodes = objBST.
|
|
245
|
+
const dfsInorderNodes = objBST.dfs('in', 'node');
|
|
246
246
|
expect(dfsInorderNodes[0].key).toBe(1);
|
|
247
247
|
expect(dfsInorderNodes[dfsInorderNodes.length - 1].key).toBe(16);
|
|
248
248
|
|
|
249
249
|
objBST.perfectlyBalance();
|
|
250
250
|
expect(objBST.isPerfectlyBalanced()).toBe(true);
|
|
251
251
|
|
|
252
|
-
const bfsNodesAfterBalanced = objBST.
|
|
252
|
+
const bfsNodesAfterBalanced = objBST.bfs('node');
|
|
253
253
|
expect(bfsNodesAfterBalanced[0].key).toBe(8);
|
|
254
254
|
expect(bfsNodesAfterBalanced[bfsNodesAfterBalanced.length - 1].key).toBe(16);
|
|
255
255
|
|
|
@@ -367,12 +367,12 @@ describe('Individual package BST operations test', () => {
|
|
|
367
367
|
|
|
368
368
|
expect(objBST.isAVLBalanced()).toBe(false);
|
|
369
369
|
|
|
370
|
-
const bfsIDs = objBST.
|
|
370
|
+
const bfsIDs = objBST.bfs();
|
|
371
371
|
expect(bfsIDs[0]).toBe(2);
|
|
372
372
|
expect(bfsIDs[1]).toBe(12);
|
|
373
373
|
expect(bfsIDs[2]).toBe(16);
|
|
374
374
|
|
|
375
|
-
const bfsNodes = objBST.
|
|
375
|
+
const bfsNodes = objBST.bfs('node');
|
|
376
376
|
expect(bfsNodes[0].key).toBe(2);
|
|
377
377
|
expect(bfsNodes[1].key).toBe(12);
|
|
378
378
|
expect(bfsNodes[2].key).toBe(16);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {DirectedEdge, DirectedGraph, DirectedVertex,
|
|
1
|
+
import {DirectedEdge, DirectedGraph, DirectedVertex, VertexKey} from '../../../../src';
|
|
2
2
|
|
|
3
3
|
describe('DirectedGraph Operation Test', () => {
|
|
4
4
|
let graph: DirectedGraph;
|
|
@@ -63,7 +63,7 @@ describe('DirectedGraph Operation Test', () => {
|
|
|
63
63
|
});
|
|
64
64
|
|
|
65
65
|
class MyVertex<V extends string> extends DirectedVertex<V> {
|
|
66
|
-
constructor(key:
|
|
66
|
+
constructor(key: VertexKey, val?: V) {
|
|
67
67
|
super(key, val);
|
|
68
68
|
this._data = val;
|
|
69
69
|
}
|
|
@@ -80,7 +80,7 @@ class MyVertex<V extends string> extends DirectedVertex<V> {
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
class MyEdge<E extends string> extends DirectedEdge<E> {
|
|
83
|
-
constructor(v1:
|
|
83
|
+
constructor(v1: VertexKey, v2: VertexKey, weight?: number, val?: E) {
|
|
84
84
|
super(v1, v2, weight, val);
|
|
85
85
|
this._data = val;
|
|
86
86
|
}
|
|
@@ -97,11 +97,11 @@ class MyEdge<E extends string> extends DirectedEdge<E> {
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
class MyDirectedGraph<V extends MyVertex<string>, E extends MyEdge<string>> extends DirectedGraph<V, E> {
|
|
100
|
-
createVertex(key:
|
|
100
|
+
createVertex(key: VertexKey, val: V['val']): V {
|
|
101
101
|
return new MyVertex(key, val) as V;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
createEdge(src:
|
|
104
|
+
createEdge(src: VertexKey, dest: VertexKey, weight?: number, val?: E['val']): E {
|
|
105
105
|
return new MyEdge(src, dest, weight ?? 1, val) as E;
|
|
106
106
|
}
|
|
107
107
|
}
|
|
@@ -29,8 +29,8 @@ describe('Overall Graph Operation Test', () => {
|
|
|
29
29
|
graph.addEdge('A', 'B');
|
|
30
30
|
graph.addEdge('B', 'C');
|
|
31
31
|
|
|
32
|
-
const
|
|
33
|
-
expect(
|
|
32
|
+
const topologicalOrderKeys = graph.topologicalSort();
|
|
33
|
+
expect(topologicalOrderKeys).toEqual(['A', 'B', 'C']);
|
|
34
34
|
});
|
|
35
35
|
it('Overall UndirectedGraph Operation Test', () => {
|
|
36
36
|
const graph = new UndirectedGraph();
|
|
@@ -384,7 +384,7 @@ describe('SinglyLinkedList Performance Test', () => {
|
|
|
384
384
|
for (let i = 0; i < magnitude.LINEAR; i++) {
|
|
385
385
|
list.push(i);
|
|
386
386
|
}
|
|
387
|
-
expect(performance.now() - startPushTime).toBeLessThan(bigO.LINEAR *
|
|
387
|
+
expect(performance.now() - startPushTime).toBeLessThan(bigO.LINEAR * 20);
|
|
388
388
|
|
|
389
389
|
const startPopTime = performance.now();
|
|
390
390
|
|