data-structure-typed 1.35.0 → 1.40.0-rc
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/dist/data-structures/binary-tree/aa-tree.d.ts +2 -0
- package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +527 -0
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +323 -0
- package/dist/data-structures/binary-tree/abstract-binary-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/avl-tree.d.ts +94 -0
- package/dist/data-structures/binary-tree/avl-tree.js +90 -3
- package/dist/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/b-tree.d.ts +2 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +46 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +36 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/binary-tree.d.ts +31 -0
- package/dist/data-structures/binary-tree/binary-tree.js +21 -0
- package/dist/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/bst.d.ts +133 -0
- package/dist/data-structures/binary-tree/bst.js +114 -0
- package/dist/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/data-structures/binary-tree/index.d.ts +12 -0
- package/dist/data-structures/binary-tree/rb-tree.d.ts +13 -0
- package/dist/data-structures/binary-tree/segment-tree.d.ts +83 -0
- package/dist/data-structures/binary-tree/segment-tree.js +45 -0
- package/dist/data-structures/binary-tree/segment-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/splay-tree.d.ts +2 -0
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +209 -0
- package/dist/data-structures/binary-tree/tree-multiset.js +178 -0
- package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -1
- package/dist/data-structures/binary-tree/two-three-tree.d.ts +2 -0
- package/dist/data-structures/graph/abstract-graph.d.ts +332 -0
- package/dist/data-structures/graph/abstract-graph.js +269 -4
- package/dist/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/data-structures/graph/directed-graph.d.ts +200 -0
- package/dist/data-structures/graph/directed-graph.js +167 -0
- package/dist/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/data-structures/graph/index.d.ts +4 -0
- package/dist/data-structures/graph/map-graph.d.ts +79 -0
- package/dist/data-structures/graph/map-graph.js +54 -0
- package/dist/data-structures/graph/map-graph.js.map +1 -1
- package/dist/data-structures/graph/undirected-graph.d.ts +127 -0
- package/dist/data-structures/graph/undirected-graph.js +105 -0
- package/dist/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/data-structures/hash/coordinate-map.d.ts +45 -0
- package/dist/data-structures/hash/coordinate-map.js +35 -0
- package/dist/data-structures/hash/coordinate-map.js.map +1 -1
- package/dist/data-structures/hash/coordinate-set.d.ts +37 -0
- package/dist/data-structures/hash/coordinate-set.js +28 -0
- package/dist/data-structures/hash/coordinate-set.js.map +1 -1
- package/dist/data-structures/hash/hash-map.d.ts +56 -0
- package/dist/data-structures/hash/hash-map.js +29 -1
- package/dist/data-structures/hash/hash-map.js.map +1 -1
- package/dist/data-structures/hash/hash-table.d.ts +106 -0
- package/dist/data-structures/hash/hash-table.js +88 -6
- package/dist/data-structures/hash/hash-table.js.map +1 -1
- package/dist/data-structures/hash/index.d.ts +7 -0
- package/dist/data-structures/hash/pair.d.ts +2 -0
- package/dist/data-structures/hash/tree-map.d.ts +2 -0
- package/dist/data-structures/hash/tree-set.d.ts +2 -0
- package/dist/data-structures/heap/heap.d.ts +83 -0
- package/dist/data-structures/heap/heap.js +62 -0
- package/dist/data-structures/heap/heap.js.map +1 -1
- package/dist/data-structures/heap/index.d.ts +3 -0
- package/dist/data-structures/heap/max-heap.d.ts +23 -0
- package/dist/data-structures/heap/max-heap.js +16 -0
- package/dist/data-structures/heap/max-heap.js.map +1 -1
- package/dist/data-structures/heap/min-heap.d.ts +24 -0
- package/dist/data-structures/heap/min-heap.js +17 -0
- package/dist/data-structures/heap/min-heap.js.map +1 -1
- package/dist/data-structures/index.d.ts +11 -0
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +234 -0
- package/dist/data-structures/linked-list/doubly-linked-list.js +202 -0
- package/dist/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/data-structures/linked-list/index.d.ts +3 -0
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +157 -0
- package/dist/data-structures/linked-list/singly-linked-list.js +135 -0
- package/dist/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +61 -0
- package/dist/data-structures/linked-list/skip-linked-list.js +36 -0
- package/dist/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/data-structures/matrix/index.d.ts +4 -0
- package/dist/data-structures/matrix/matrix.d.ts +21 -0
- package/dist/data-structures/matrix/matrix.js +15 -0
- package/dist/data-structures/matrix/matrix.js.map +1 -1
- package/dist/data-structures/matrix/matrix2d.d.ts +108 -0
- package/dist/data-structures/matrix/matrix2d.js +91 -2
- package/dist/data-structures/matrix/matrix2d.js.map +1 -1
- package/dist/data-structures/matrix/navigator.d.ts +52 -0
- package/dist/data-structures/matrix/navigator.js +28 -0
- package/dist/data-structures/matrix/navigator.js.map +1 -1
- package/dist/data-structures/matrix/vector2d.d.ts +201 -0
- package/dist/data-structures/matrix/vector2d.js +188 -1
- package/dist/data-structures/matrix/vector2d.js.map +1 -1
- package/dist/data-structures/priority-queue/index.d.ts +3 -0
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +15 -0
- package/dist/data-structures/priority-queue/max-priority-queue.js +18 -0
- package/dist/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +15 -0
- package/dist/data-structures/priority-queue/min-priority-queue.js +19 -0
- package/dist/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/data-structures/priority-queue/priority-queue.d.ts +180 -0
- package/dist/data-structures/priority-queue/priority-queue.js +141 -0
- package/dist/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/data-structures/queue/deque.d.ts +165 -0
- package/dist/data-structures/queue/deque.js +124 -0
- package/dist/data-structures/queue/deque.js.map +1 -1
- package/dist/data-structures/queue/index.d.ts +2 -0
- package/dist/data-structures/queue/queue.d.ts +107 -0
- package/dist/data-structures/queue/queue.js +80 -0
- package/dist/data-structures/queue/queue.js.map +1 -1
- package/dist/data-structures/stack/index.d.ts +1 -0
- package/dist/data-structures/stack/stack.d.ts +63 -0
- package/dist/data-structures/stack/stack.js +50 -0
- package/dist/data-structures/stack/stack.js.map +1 -1
- package/dist/data-structures/tree/index.d.ts +1 -0
- package/dist/data-structures/tree/tree.d.ts +14 -0
- package/dist/data-structures/tree/tree.js +1 -0
- package/dist/data-structures/tree/tree.js.map +1 -1
- package/dist/data-structures/trie/index.d.ts +1 -0
- package/dist/data-structures/trie/trie.d.ts +61 -0
- package/dist/data-structures/trie/trie.js +36 -0
- package/dist/data-structures/trie/trie.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/interfaces/abstract-binary-tree.d.ts +7 -0
- package/dist/interfaces/abstract-graph.d.ts +5 -0
- package/dist/interfaces/avl-tree.d.ts +7 -0
- package/dist/interfaces/binary-tree.d.ts +6 -0
- package/dist/interfaces/bst.d.ts +6 -0
- package/dist/interfaces/directed-graph.d.ts +3 -0
- package/dist/interfaces/doubly-linked-list.d.ts +1 -0
- package/dist/interfaces/heap.d.ts +1 -0
- package/dist/interfaces/index.d.ts +15 -0
- package/dist/interfaces/navigator.d.ts +1 -0
- package/dist/interfaces/priority-queue.d.ts +1 -0
- package/dist/interfaces/rb-tree.d.ts +6 -0
- package/dist/interfaces/segment-tree.d.ts +1 -0
- package/dist/interfaces/singly-linked-list.d.ts +1 -0
- package/dist/interfaces/tree-multiset.d.ts +6 -0
- package/dist/interfaces/undirected-graph.d.ts +3 -0
- package/dist/types/data-structures/abstract-binary-tree.d.ts +34 -0
- package/dist/types/data-structures/abstract-binary-tree.js +6 -0
- package/dist/types/data-structures/abstract-binary-tree.js.map +1 -1
- package/dist/types/data-structures/abstract-graph.d.ts +11 -0
- package/dist/types/data-structures/avl-tree.d.ts +4 -0
- package/dist/types/data-structures/binary-tree.d.ts +4 -0
- package/dist/types/data-structures/bst.d.ts +13 -0
- package/dist/types/data-structures/directed-graph.d.ts +6 -0
- package/dist/types/data-structures/doubly-linked-list.d.ts +1 -0
- package/dist/types/data-structures/hash.d.ts +1 -0
- package/dist/types/data-structures/heap.d.ts +3 -0
- package/dist/types/data-structures/index.d.ts +16 -0
- package/dist/types/data-structures/map-graph.d.ts +1 -0
- package/dist/types/data-structures/navigator.d.ts +14 -0
- package/dist/types/data-structures/priority-queue.d.ts +7 -0
- package/dist/types/data-structures/rb-tree.d.ts +8 -0
- package/dist/types/data-structures/segment-tree.d.ts +1 -0
- package/dist/types/data-structures/singly-linked-list.d.ts +1 -0
- package/dist/types/data-structures/tree-multiset.d.ts +4 -0
- package/dist/types/helpers.d.ts +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/utils/index.d.ts +2 -0
- package/dist/types/utils/utils.d.ts +7 -0
- package/dist/types/utils/validate-type.d.ts +19 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/utils.d.ts +19 -0
- package/package.json +11 -7
- 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
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type KeyValueObject = {
|
|
2
|
+
[key: string]: any;
|
|
3
|
+
};
|
|
4
|
+
export type KeyValueObjectWithKey = {
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
key: string | number | symbol;
|
|
7
|
+
};
|
|
8
|
+
export type NonNumberNonObjectButDefined = string | boolean | symbol | null;
|
|
9
|
+
export type ObjectWithoutKey = Omit<KeyValueObject, 'key'>;
|
|
10
|
+
export type ObjectWithNonNumberKey = {
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
key: string | boolean | symbol | null | object | undefined;
|
|
13
|
+
};
|
|
14
|
+
export type ObjectWithNumberKey = {
|
|
15
|
+
[key: string]: any;
|
|
16
|
+
key: number;
|
|
17
|
+
};
|
|
18
|
+
export type RestrictValByKey = NonNumberNonObjectButDefined | ObjectWithoutKey | ObjectWithNonNumberKey | ObjectWithNumberKey;
|
|
19
|
+
export type DummyAny = string | number | boolean | null | undefined | object | symbol | void | ((...args: []) => any) | never;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './utils';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* data-structure-typed
|
|
3
|
+
*
|
|
4
|
+
* @author Tyler Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
|
+
* @license MIT License
|
|
7
|
+
*/
|
|
8
|
+
import type { Thunk, ToThunkFn, TrlAsyncFn, TrlFn } from '../types';
|
|
9
|
+
export declare const uuidV4: () => string;
|
|
10
|
+
export declare const arrayRemove: <T>(array: T[], predicate: (item: T, index: number, array: T[]) => boolean) => T[];
|
|
11
|
+
export declare const THUNK_SYMBOL: unique symbol;
|
|
12
|
+
export declare const isThunk: (fnOrValue: any) => boolean;
|
|
13
|
+
export declare const toThunk: (fn: ToThunkFn) => Thunk;
|
|
14
|
+
export declare const trampoline: (fn: TrlFn) => ((...args: [...Parameters<TrlFn>]) => any) & {
|
|
15
|
+
cont: (...args: [...Parameters<TrlFn>]) => Thunk;
|
|
16
|
+
};
|
|
17
|
+
export declare const trampolineAsync: (fn: TrlAsyncFn) => ((...args: [...Parameters<TrlAsyncFn>]) => Promise<any>) & {
|
|
18
|
+
cont: (...args: [...Parameters<TrlAsyncFn>]) => Thunk;
|
|
19
|
+
};
|
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "data-structure-typed",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.40.0-rc",
|
|
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",
|
|
7
7
|
"types": "lib/index.d.ts",
|
|
8
8
|
"source": "src/index.ts",
|
|
9
9
|
"umd:main": "umd/bundle.min.js",
|
|
10
|
+
"exports": {
|
|
11
|
+
"import": "./lib/index.js",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
},
|
|
10
14
|
"scripts": {
|
|
11
15
|
"build": "npm run build:es6 && npm run build:commonjs && npm run build:umd && npm run build:docs",
|
|
12
16
|
"build:es6": "rm -rf lib && tsc",
|
|
@@ -28,13 +32,13 @@
|
|
|
28
32
|
"check:deps": "dependency-cruiser src",
|
|
29
33
|
"changelog": "auto-changelog",
|
|
30
34
|
"coverage:badge": "istanbul-badges-readme",
|
|
31
|
-
"ci": "env && npm run lint && npm run build && npm run test && git fetch --tags && npm run changelog"
|
|
35
|
+
"ci": "env && npm run lint && npm run build && npm run update:individuals && npm run test && git fetch --tags && npm run changelog"
|
|
32
36
|
},
|
|
33
37
|
"repository": {
|
|
34
38
|
"type": "git",
|
|
35
39
|
"url": "git+https://github.com/zrwusa/data-structure-typed.git"
|
|
36
40
|
},
|
|
37
|
-
"author": "Tyler Zeng zrwusa@gmail.com",
|
|
41
|
+
"author": "Tyler Zeng <zrwusa@gmail.com>",
|
|
38
42
|
"license": "MIT",
|
|
39
43
|
"publishConfig": {
|
|
40
44
|
"@zrwusa:registry": "https://npm.pkg.github.com"
|
|
@@ -50,17 +54,17 @@
|
|
|
50
54
|
"@typescript-eslint/eslint-plugin": "^6.7.4",
|
|
51
55
|
"@typescript-eslint/parser": "^6.7.4",
|
|
52
56
|
"auto-changelog": "^2.4.0",
|
|
53
|
-
"avl-tree-typed": "^1.
|
|
57
|
+
"avl-tree-typed": "^1.35.1",
|
|
54
58
|
"benchmark": "^2.1.4",
|
|
55
|
-
"binary-tree-typed": "^1.
|
|
56
|
-
"bst-typed": "^1.
|
|
59
|
+
"binary-tree-typed": "^1.35.1",
|
|
60
|
+
"bst-typed": "^1.35.1",
|
|
57
61
|
"dependency-cruiser": "^14.1.0",
|
|
58
62
|
"eslint": "^8.50.0",
|
|
59
63
|
"eslint-config-prettier": "^9.0.0",
|
|
60
64
|
"eslint-import-resolver-alias": "^1.1.2",
|
|
61
65
|
"eslint-import-resolver-typescript": "^3.6.1",
|
|
62
66
|
"eslint-plugin-import": "^2.28.1",
|
|
63
|
-
"heap-typed": "^1.
|
|
67
|
+
"heap-typed": "^1.35.1",
|
|
64
68
|
"istanbul-badges-readme": "^1.8.5",
|
|
65
69
|
"jest": "^29.7.0",
|
|
66
70
|
"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
|
|