data-structure-typed 1.38.6 → 1.38.8
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 +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +6 -6
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +45 -33
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +80 -30
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +6 -6
- 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/binary-tree/rb-tree.d.ts +3 -3
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multiset.d.ts +6 -6
- package/dist/cjs/data-structures/binary-tree/tree-multiset.js +2 -2
- package/dist/cjs/data-structures/binary-tree/tree-multiset.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/hash/tree-map.js.map +1 -1
- package/dist/cjs/data-structures/hash/tree-set.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
- package/dist/cjs/data-structures/matrix/vector2d.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +2 -2
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +6 -6
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +1 -1
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +45 -33
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +80 -30
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +6 -6
- package/dist/mjs/data-structures/binary-tree/bst.js +1 -1
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +3 -3
- package/dist/mjs/data-structures/binary-tree/tree-multiset.d.ts +6 -6
- package/dist/mjs/data-structures/binary-tree/tree-multiset.js +2 -2
- package/dist/mjs/interfaces/binary-tree.d.ts +2 -2
- package/dist/umd/data-structure-typed.min.js +27 -0
- package/dist/umd/data-structure-typed.min.js.map +1 -0
- package/package.json +6 -6
- package/src/data-structures/binary-tree/avl-tree.ts +10 -11
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +1 -1
- package/src/data-structures/binary-tree/binary-tree.ts +107 -52
- package/src/data-structures/binary-tree/bst.ts +9 -9
- package/src/data-structures/binary-tree/rb-tree.ts +4 -7
- package/src/data-structures/binary-tree/tree-multiset.ts +10 -14
- package/src/data-structures/graph/abstract-graph.ts +10 -11
- package/src/data-structures/graph/directed-graph.ts +1 -2
- package/src/data-structures/graph/undirected-graph.ts +4 -5
- package/src/data-structures/hash/hash-map.ts +1 -1
- package/src/data-structures/hash/tree-map.ts +2 -1
- package/src/data-structures/hash/tree-set.ts +2 -1
- package/src/data-structures/linked-list/singly-linked-list.ts +1 -1
- package/src/data-structures/matrix/matrix.ts +1 -1
- package/src/data-structures/matrix/vector2d.ts +2 -1
- package/src/data-structures/queue/deque.ts +5 -4
- package/src/data-structures/queue/queue.ts +1 -1
- package/src/interfaces/binary-tree.ts +2 -2
- package/src/types/data-structures/matrix/navigator.ts +1 -1
- package/src/types/utils/utils.ts +1 -1
- package/src/types/utils/validate-type.ts +2 -2
- package/test/integration/bst.test.ts +1 -1
- package/test/integration/index.html +1 -1
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +3 -3
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +23 -2
- package/test/unit/data-structures/binary-tree/bst.test.ts +4 -10
- package/test/unit/data-structures/binary-tree/overall.test.ts +20 -20
- package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +2 -2
- package/test/unit/data-structures/heap/heap.test.ts +2 -2
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +1 -1
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +2 -2
- package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +2 -2
- package/test/utils/big-o.ts +1 -1
- package/tsup.config.js +11 -4
- package/dist/umd/index.global.js +0 -27
- package/dist/umd/index.global.js.map +0 -1
|
@@ -51,12 +51,11 @@ export class UndirectedEdge<V = number> extends AbstractEdge<V> {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
export class UndirectedGraph<
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
V extends UndirectedVertex<any> = UndirectedVertex,
|
|
55
|
+
E extends UndirectedEdge<any> = UndirectedEdge
|
|
56
|
+
>
|
|
57
57
|
extends AbstractGraph<V, E>
|
|
58
|
-
implements IGraph<V, E>
|
|
59
|
-
{
|
|
58
|
+
implements IGraph<V, E> {
|
|
60
59
|
/**
|
|
61
60
|
* The constructor initializes a new Map object to store edges.
|
|
62
61
|
*/
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export class TreeMap {
|
|
1
|
+
export class TreeMap {
|
|
2
|
+
}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export class TreeSet {
|
|
1
|
+
export class TreeSet {
|
|
2
|
+
}
|
|
@@ -14,7 +14,7 @@ export class MatrixNTI2D<V = any> {
|
|
|
14
14
|
* given initial value or 0 if not provided.
|
|
15
15
|
* @param options - An object containing the following properties:
|
|
16
16
|
*/
|
|
17
|
-
constructor(options: {row: number; col: number; initialVal?: V}) {
|
|
17
|
+
constructor(options: { row: number; col: number; initialVal?: V }) {
|
|
18
18
|
const {row, col, initialVal} = options;
|
|
19
19
|
this._matrix = new Array(row).fill(undefined).map(() => new Array(col).fill(initialVal || 0));
|
|
20
20
|
}
|
|
@@ -9,7 +9,8 @@ import {DoublyLinkedList} from '../linked-list';
|
|
|
9
9
|
|
|
10
10
|
// O(n) time complexity of obtaining the value
|
|
11
11
|
// O(1) time complexity of adding at the beginning and the end
|
|
12
|
-
export class Deque<E = any> extends DoublyLinkedList<E> {
|
|
12
|
+
export class Deque<E = any> extends DoublyLinkedList<E> {
|
|
13
|
+
}
|
|
13
14
|
|
|
14
15
|
// O(1) time complexity of obtaining the value
|
|
15
16
|
// O(n) time complexity of adding at the beginning and the end
|
|
@@ -19,9 +20,9 @@ export class ObjectDeque<E = number> {
|
|
|
19
20
|
if (capacity !== undefined) this._capacity = capacity;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
private _nodes: {[key: number]: E} = {};
|
|
23
|
+
private _nodes: { [key: number]: E } = {};
|
|
23
24
|
|
|
24
|
-
get nodes(): {[p: number]: E} {
|
|
25
|
+
get nodes(): { [p: number]: E } {
|
|
25
26
|
return this._nodes;
|
|
26
27
|
}
|
|
27
28
|
|
|
@@ -156,7 +157,7 @@ export class ObjectDeque<E = number> {
|
|
|
156
157
|
return this._size <= 0;
|
|
157
158
|
}
|
|
158
159
|
|
|
159
|
-
protected _seNodes(value: {[p: number]: E}) {
|
|
160
|
+
protected _seNodes(value: { [p: number]: E }) {
|
|
160
161
|
this._nodes = value;
|
|
161
162
|
}
|
|
162
163
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {BinaryTreeNode} from '../data-structures';
|
|
2
|
-
import {BinaryTreeDeletedResult, BinaryTreeNodeKey, MapCallback} from '../types';
|
|
2
|
+
import {BinaryTreeDeletedResult, BinaryTreeNodeKey, BinaryTreeNodeNested, MapCallback} from '../types';
|
|
3
3
|
|
|
4
|
-
export interface IBinaryTree<N extends BinaryTreeNode<
|
|
4
|
+
export interface IBinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNodeNested<V>> {
|
|
5
5
|
createNode(key: BinaryTreeNodeKey, val?: N['val']): N;
|
|
6
6
|
|
|
7
7
|
add(keyOrNode: BinaryTreeNodeKey | N | null, val?: N['val']): N | null | undefined;
|
package/src/types/utils/utils.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type ToThunkFn = () => ReturnType<TrlFn>;
|
|
2
|
-
export type Thunk = () => ReturnType<ToThunkFn> & {__THUNK__: symbol};
|
|
2
|
+
export type Thunk = () => ReturnType<ToThunkFn> & { __THUNK__: symbol };
|
|
3
3
|
export type TrlFn = (...args: any[]) => any;
|
|
4
4
|
export type TrlAsyncFn = (...args: any[]) => any;
|
|
5
5
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export type KeyValueObject = {[key: string]: any};
|
|
1
|
+
export type KeyValueObject = { [key: string]: any };
|
|
2
2
|
|
|
3
|
-
export type KeyValueObjectWithKey = {[key: string]: any; key: string | number | symbol};
|
|
3
|
+
export type KeyValueObjectWithKey = { [key: string]: any; key: string | number | symbol };
|
|
4
4
|
|
|
5
5
|
export type NonNumberNonObjectButDefined = string | boolean | symbol | null;
|
|
6
6
|
|
|
@@ -183,7 +183,7 @@ describe('Individual package BST operations test', () => {
|
|
|
183
183
|
});
|
|
184
184
|
|
|
185
185
|
it('should perform various operations on a Binary Search Tree with object values', () => {
|
|
186
|
-
const objBST = new BST<
|
|
186
|
+
const objBST = new BST<{ key: number; keyA: number }>();
|
|
187
187
|
expect(objBST).toBeInstanceOf(BST);
|
|
188
188
|
objBST.add(11, {key: 11, keyA: 11});
|
|
189
189
|
objBST.add(3, {key: 3, keyA: 3});
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset='UTF-8'>
|
|
5
5
|
<title>CDN Test</title>
|
|
6
|
-
<script src='https://cdn.jsdelivr.net/npm/data-structure-typed/dist/umd/
|
|
6
|
+
<script src='https://cdn.jsdelivr.net/npm/data-structure-typed/dist/umd/data-structure-typed.min.js'></script>
|
|
7
7
|
</head>
|
|
8
8
|
<body>
|
|
9
9
|
<div id='app'>
|
|
@@ -3,7 +3,7 @@ import {AVLTree, AVLTreeNode, CP} from '../../../../src';
|
|
|
3
3
|
describe('AVL Tree Test', () => {
|
|
4
4
|
it('should perform various operations on a AVL Tree', () => {
|
|
5
5
|
const arr = [11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5];
|
|
6
|
-
const tree = new AVLTree<
|
|
6
|
+
const tree = new AVLTree<number>();
|
|
7
7
|
|
|
8
8
|
for (const i of arr) tree.add(i, i);
|
|
9
9
|
|
|
@@ -110,7 +110,7 @@ describe('AVL Tree Test', () => {
|
|
|
110
110
|
});
|
|
111
111
|
|
|
112
112
|
describe('AVLTree APIs test', () => {
|
|
113
|
-
const avl = new AVLTree<
|
|
113
|
+
const avl = new AVLTree<{ id: number; text: string }>();
|
|
114
114
|
beforeEach(() => {
|
|
115
115
|
avl.clear();
|
|
116
116
|
});
|
|
@@ -123,7 +123,7 @@ describe('AVLTree APIs test', () => {
|
|
|
123
123
|
avl.add(node3);
|
|
124
124
|
avl.add(node3, {id: 3, text: 'text33'});
|
|
125
125
|
|
|
126
|
-
const bfsRes = avl.bfs(node => node.key
|
|
126
|
+
const bfsRes = avl.bfs(node => node.key);
|
|
127
127
|
expect(bfsRes[0]).toBe(2);
|
|
128
128
|
});
|
|
129
129
|
});
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {AVLTree, AVLTreeNode, BinaryTree, BinaryTreeNode} from '../../../../src';
|
|
1
|
+
import {AVLTree, AVLTreeNode, BinaryTree, BinaryTreeNode, IterationType} from '../../../../src';
|
|
2
|
+
import {isDebugTest} from "../../../config";
|
|
3
|
+
|
|
4
|
+
const isDebug = isDebugTest;
|
|
5
|
+
// const isDebug = true;
|
|
2
6
|
|
|
3
7
|
describe('BinaryTreeNode', () => {
|
|
4
8
|
it('should create an instance of BinaryTreeNode', () => {
|
|
@@ -196,7 +200,7 @@ describe('BinaryTree Morris Traversal', () => {
|
|
|
196
200
|
});
|
|
197
201
|
|
|
198
202
|
describe('BinaryTree APIs test', () => {
|
|
199
|
-
const avl = new AVLTree<
|
|
203
|
+
const avl = new AVLTree<{ id: number; text: string }>();
|
|
200
204
|
beforeEach(() => {
|
|
201
205
|
avl.clear();
|
|
202
206
|
});
|
|
@@ -213,3 +217,20 @@ describe('BinaryTree APIs test', () => {
|
|
|
213
217
|
expect(bfsRes[0]?.key).toBe(2);
|
|
214
218
|
});
|
|
215
219
|
});
|
|
220
|
+
|
|
221
|
+
describe('BinaryTree traversals', () => {
|
|
222
|
+
const tree = new BinaryTree<number>();
|
|
223
|
+
|
|
224
|
+
const arr = [35, 20, 40, 15, 29, null, 50, null, 16, 28, 30, 45, 55];
|
|
225
|
+
tree.refill(arr);
|
|
226
|
+
expect(tree.dfs(node => node.key, 'pre')).toEqual([35, 20, 15, 16, 29, 28, 30, 40, 50, 45, 55]);
|
|
227
|
+
expect(tree.dfs(node => node.key, 'in')).toEqual([15, 16, 20, 28, 29, 30, 35, 40, 45, 50, 55]);
|
|
228
|
+
expect(tree.dfs(node => node.key, 'post')).toEqual([16, 15, 28, 30, 29, 20, 45, 55, 50, 40, 35]);
|
|
229
|
+
expect(tree.bfs(node => node.key, tree.root, IterationType.RECURSIVE)).toEqual([35, 20, 40, 15, 29, 50, 16, 28, 30, 45, 55]);
|
|
230
|
+
expect(tree.bfs(node => node.key, tree.root, IterationType.ITERATIVE)).toEqual([35, 20, 40, 15, 29, 50, 16, 28, 30, 45, 55]);
|
|
231
|
+
|
|
232
|
+
const levels = tree.listLevels(node => node.key);
|
|
233
|
+
expect(levels).toEqual([[35], [20, 40], [15, 29, 50], [16, 28, 30, 45, 55]]);
|
|
234
|
+
isDebug && console.log(levels);
|
|
235
|
+
|
|
236
|
+
})
|
|
@@ -189,7 +189,7 @@ describe('BST operations test', () => {
|
|
|
189
189
|
});
|
|
190
190
|
|
|
191
191
|
it('should perform various operations on a Binary Search Tree with object values', () => {
|
|
192
|
-
const objBST = new BST<
|
|
192
|
+
const objBST = new BST<{ key: number; keyA: number }>();
|
|
193
193
|
expect(objBST).toBeInstanceOf(BST);
|
|
194
194
|
objBST.add(11, {key: 11, keyA: 11});
|
|
195
195
|
objBST.add(3, {key: 3, keyA: 3});
|
|
@@ -260,7 +260,7 @@ describe('BST operations test', () => {
|
|
|
260
260
|
objBST.perfectlyBalance();
|
|
261
261
|
expect(objBST.isPerfectlyBalanced()).toBe(true);
|
|
262
262
|
|
|
263
|
-
const bfsNodesAfterBalanced: BSTNode<{key: number; keyA: number}>[] = [];
|
|
263
|
+
const bfsNodesAfterBalanced: BSTNode<{ key: number; keyA: number }>[] = [];
|
|
264
264
|
objBST.bfs(node => bfsNodesAfterBalanced.push(node));
|
|
265
265
|
expect(bfsNodesAfterBalanced[0].key).toBe(8);
|
|
266
266
|
expect(bfsNodesAfterBalanced[bfsNodesAfterBalanced.length - 1].key).toBe(16);
|
|
@@ -385,7 +385,7 @@ describe('BST operations test', () => {
|
|
|
385
385
|
expect(bfsIDs[1]).toBe(12);
|
|
386
386
|
expect(bfsIDs[2]).toBe(16);
|
|
387
387
|
|
|
388
|
-
const bfsNodes: BSTNode<{key: number; keyA: number}>[] = [];
|
|
388
|
+
const bfsNodes: BSTNode<{ key: number; keyA: number }>[] = [];
|
|
389
389
|
objBST.bfs(node => bfsNodes.push(node));
|
|
390
390
|
expect(bfsNodes[0].key).toBe(2);
|
|
391
391
|
expect(bfsNodes[1].key).toBe(12);
|
|
@@ -435,13 +435,7 @@ describe('BST Performance test', function () {
|
|
|
435
435
|
bst.addMany(nodes);
|
|
436
436
|
isDebug && console.log('---add', performance.now() - start);
|
|
437
437
|
const startL = performance.now();
|
|
438
|
-
const arr: number[][] =
|
|
439
|
-
bst.bfs((node, level) => {
|
|
440
|
-
if (level !== undefined) {
|
|
441
|
-
if (!arr[level]) arr[level] = [];
|
|
442
|
-
arr[level].push(node.key);
|
|
443
|
-
}
|
|
444
|
-
}, true);
|
|
438
|
+
const arr: number[][] = bst.listLevels((node) => node.key);
|
|
445
439
|
isDebug && console.log('---listLevels', arr);
|
|
446
440
|
isDebug && console.log('---listLevels', performance.now() - startL);
|
|
447
441
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {AVLTree, BST
|
|
1
|
+
import {AVLTree, BST} from '../../../../src';
|
|
2
2
|
|
|
3
3
|
describe('Overall BinaryTree Test', () => {
|
|
4
4
|
it('should perform various operations on BinaryTree', () => {
|
|
@@ -6,30 +6,30 @@ describe('Overall BinaryTree Test', () => {
|
|
|
6
6
|
bst.add(11);
|
|
7
7
|
bst.add(3);
|
|
8
8
|
bst.addMany([15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5], undefined, false);
|
|
9
|
-
bst.size === 16;
|
|
10
|
-
expect(bst.size).toBe(16);
|
|
11
|
-
bst.has(6);
|
|
12
|
-
expect(bst.has(6)).toBe(true);
|
|
13
|
-
bst.getHeight(6) === 2;
|
|
14
|
-
bst.getHeight() === 5;
|
|
15
|
-
bst.getDepth(6) === 3;
|
|
16
|
-
expect(bst.getHeight(6)).toBe(2);
|
|
17
|
-
expect(bst.getHeight()).toBe(5);
|
|
18
|
-
expect(bst.getDepth(6)).toBe(3);
|
|
9
|
+
bst.size === 16; // true
|
|
10
|
+
expect(bst.size).toBe(16); // true
|
|
11
|
+
bst.has(6); // true
|
|
12
|
+
expect(bst.has(6)).toBe(true); // true
|
|
13
|
+
bst.getHeight(6) === 2; // true
|
|
14
|
+
bst.getHeight() === 5; // true
|
|
15
|
+
bst.getDepth(6) === 3; // true
|
|
16
|
+
expect(bst.getHeight(6)).toBe(2); // true
|
|
17
|
+
expect(bst.getHeight()).toBe(5); // true
|
|
18
|
+
expect(bst.getDepth(6)).toBe(3); // true
|
|
19
19
|
const leftMost = bst.getLeftMost();
|
|
20
|
-
leftMost?.key === 1;
|
|
20
|
+
leftMost?.key === 1; // true
|
|
21
21
|
expect(leftMost?.key).toBe(1);
|
|
22
22
|
bst.delete(6);
|
|
23
|
-
bst.get(6);
|
|
23
|
+
bst.get(6); // null
|
|
24
24
|
expect(bst.get(6)).toBeNull();
|
|
25
|
-
bst.isAVLBalanced();
|
|
25
|
+
bst.isAVLBalanced(); // true or false
|
|
26
26
|
expect(bst.isAVLBalanced()).toBe(true);
|
|
27
27
|
const bfsIDs: number[] = [];
|
|
28
28
|
bst.bfs(node => bfsIDs.push(node.key));
|
|
29
|
-
bfsIDs[0] === 11;
|
|
29
|
+
bfsIDs[0] === 11; // true
|
|
30
30
|
expect(bfsIDs[0]).toBe(11);
|
|
31
31
|
|
|
32
|
-
const objBST = new BST<
|
|
32
|
+
const objBST = new BST<{ key: number; keyA: number }>();
|
|
33
33
|
objBST.add(11, {key: 11, keyA: 11});
|
|
34
34
|
objBST.add(3, {key: 3, keyA: 3});
|
|
35
35
|
|
|
@@ -57,10 +57,10 @@ describe('Overall BinaryTree Test', () => {
|
|
|
57
57
|
|
|
58
58
|
const avlTree = new AVLTree();
|
|
59
59
|
avlTree.addMany([11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5]);
|
|
60
|
-
avlTree.isAVLBalanced();
|
|
61
|
-
expect(avlTree.isAVLBalanced()).toBe(true);
|
|
60
|
+
avlTree.isAVLBalanced(); // true
|
|
61
|
+
expect(avlTree.isAVLBalanced()).toBe(true); // true
|
|
62
62
|
avlTree.delete(10);
|
|
63
|
-
avlTree.isAVLBalanced();
|
|
64
|
-
expect(avlTree.isAVLBalanced()).toBe(true);
|
|
63
|
+
avlTree.isAVLBalanced(); // true
|
|
64
|
+
expect(avlTree.isAVLBalanced()).toBe(true); // true
|
|
65
65
|
});
|
|
66
66
|
});
|
|
@@ -206,7 +206,7 @@ describe('TreeMultiset operations test', () => {
|
|
|
206
206
|
});
|
|
207
207
|
|
|
208
208
|
it('should perform various operations on a Binary Search Tree with object values', () => {
|
|
209
|
-
const objTreeMultiset = new TreeMultiset<
|
|
209
|
+
const objTreeMultiset = new TreeMultiset<{ key: number; keyA: number }>();
|
|
210
210
|
expect(objTreeMultiset).toBeInstanceOf(TreeMultiset);
|
|
211
211
|
objTreeMultiset.add(11, {key: 11, keyA: 11});
|
|
212
212
|
objTreeMultiset.add(3, {key: 3, keyA: 3});
|
|
@@ -481,7 +481,7 @@ describe('TreeMultiset Performance test', function () {
|
|
|
481
481
|
}
|
|
482
482
|
isDebug && console.log('---add', performance.now() - start);
|
|
483
483
|
const startL = performance.now();
|
|
484
|
-
treeMS.lesserOrGreaterTraverse((node
|
|
484
|
+
treeMS.lesserOrGreaterTraverse((node) => (node.count += 1), CP.lt, inputSize / 2);
|
|
485
485
|
isDebug && console.log('---lesserOrGreaterTraverse', performance.now() - startL);
|
|
486
486
|
});
|
|
487
487
|
});
|
|
@@ -22,7 +22,7 @@ describe('Heap Operation Test', () => {
|
|
|
22
22
|
});
|
|
23
23
|
|
|
24
24
|
it('should object heap work well', function () {
|
|
25
|
-
const minHeap = new MinHeap<{a: string; key: number}>((a, b) => a.key - b.key);
|
|
25
|
+
const minHeap = new MinHeap<{ a: string; key: number }>((a, b) => a.key - b.key);
|
|
26
26
|
minHeap.add({key: 1, a: 'a1'});
|
|
27
27
|
minHeap.add({key: 6, a: 'a6'});
|
|
28
28
|
minHeap.add({key: 2, a: 'a2'});
|
|
@@ -37,7 +37,7 @@ describe('Heap Operation Test', () => {
|
|
|
37
37
|
i++;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
const maxHeap = new MaxHeap<{key: number; a: string}>((a, b) => b.key - a.key);
|
|
40
|
+
const maxHeap = new MaxHeap<{ key: number; a: string }>((a, b) => b.key - a.key);
|
|
41
41
|
maxHeap.add({key: 1, a: 'a1'});
|
|
42
42
|
maxHeap.add({key: 6, a: 'a6'});
|
|
43
43
|
maxHeap.add({key: 5, a: 'a5'});
|
|
@@ -3,7 +3,7 @@ import {bigO, magnitude} from '../../../utils';
|
|
|
3
3
|
|
|
4
4
|
describe('DoublyLinkedList Operation Test', () => {
|
|
5
5
|
let list: DoublyLinkedList<number>;
|
|
6
|
-
let objectList: DoublyLinkedList<{keyA: number}>;
|
|
6
|
+
let objectList: DoublyLinkedList<{ keyA: number }>;
|
|
7
7
|
|
|
8
8
|
beforeEach(() => {
|
|
9
9
|
list = new DoublyLinkedList();
|
|
@@ -3,10 +3,10 @@ import {bigO, magnitude} from '../../../utils';
|
|
|
3
3
|
|
|
4
4
|
describe('SinglyLinkedList Operation Test', () => {
|
|
5
5
|
let list: SinglyLinkedList<number>;
|
|
6
|
-
let objectList: SinglyLinkedList<{keyA: number}>;
|
|
6
|
+
let objectList: SinglyLinkedList<{ keyA: number }>;
|
|
7
7
|
beforeEach(() => {
|
|
8
8
|
list = new SinglyLinkedList<number>();
|
|
9
|
-
objectList = new SinglyLinkedList<{keyA: number}>();
|
|
9
|
+
objectList = new SinglyLinkedList<{ keyA: number }>();
|
|
10
10
|
});
|
|
11
11
|
|
|
12
12
|
describe('push', () => {
|
|
@@ -17,7 +17,7 @@ describe('MaxPriorityQueue Operation Test', () => {
|
|
|
17
17
|
});
|
|
18
18
|
|
|
19
19
|
it('should add elements and maintain heap property in a object MaxPriorityQueue', () => {
|
|
20
|
-
const priorityQueue = new MaxPriorityQueue<{keyA: number}>((a, b) => b.keyA - a.keyA);
|
|
20
|
+
const priorityQueue = new MaxPriorityQueue<{ keyA: number }>((a, b) => b.keyA - a.keyA);
|
|
21
21
|
priorityQueue.refill([{keyA: 5}, {keyA: 3}, {keyA: 1}]);
|
|
22
22
|
priorityQueue.add({keyA: 7});
|
|
23
23
|
|
|
@@ -64,7 +64,7 @@ describe('MaxPriorityQueue Operation Test', () => {
|
|
|
64
64
|
|
|
65
65
|
it('should correctly heapify an object array', () => {
|
|
66
66
|
const nodes = [{keyA: 5}, {keyA: 3}, {keyA: 7}, {keyA: 1}];
|
|
67
|
-
const maxPQ = MaxPriorityQueue.heapify<{keyA: number}>(nodes, (a, b) => b.keyA - a.keyA);
|
|
67
|
+
const maxPQ = MaxPriorityQueue.heapify<{ keyA: number }>(nodes, (a, b) => b.keyA - a.keyA);
|
|
68
68
|
|
|
69
69
|
expect(maxPQ.poll()?.keyA).toBe(7);
|
|
70
70
|
expect(maxPQ.poll()?.keyA).toBe(5);
|
package/test/utils/big-o.ts
CHANGED
|
@@ -26,7 +26,7 @@ export const bigO = {
|
|
|
26
26
|
|
|
27
27
|
function findPotentialN(input: any): number {
|
|
28
28
|
let longestArray: any[] = [];
|
|
29
|
-
let mostProperties: {[key: string]: any} = {};
|
|
29
|
+
let mostProperties: { [key: string]: any } = {};
|
|
30
30
|
|
|
31
31
|
function recurse(obj: any) {
|
|
32
32
|
if (Array.isArray(obj)) {
|
package/tsup.config.js
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
export default [{
|
|
2
|
-
|
|
2
|
+
entryPoints: {
|
|
3
|
+
"data-structure-typed": "src/index.ts"
|
|
4
|
+
},
|
|
3
5
|
format: ["iife"],
|
|
4
6
|
clean: true,
|
|
5
7
|
sourcemap: true,
|
|
6
8
|
minify: true,
|
|
7
|
-
outDir:
|
|
8
|
-
globalName:
|
|
9
|
+
outDir: "dist/umd",
|
|
10
|
+
globalName: "dataStructureTyped",
|
|
9
11
|
platform: "browser",
|
|
10
|
-
bundle: true
|
|
12
|
+
bundle: true,
|
|
13
|
+
outExtension() {
|
|
14
|
+
return {
|
|
15
|
+
js: `.min.js`,
|
|
16
|
+
}
|
|
17
|
+
},
|
|
11
18
|
}];
|