data-structure-typed 1.47.5 → 1.47.7
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/ISSUE_TEMPLATE/bug_report.md +10 -7
- package/.github/workflows/ci.yml +1 -1
- package/.github/workflows/release-package.yml +1 -1
- package/CHANGELOG.md +1 -1
- package/CODE_OF_CONDUCT.md +32 -10
- package/COMMANDS.md +3 -1
- package/CONTRIBUTING.md +4 -3
- package/README.md +103 -28
- package/SECURITY.md +1 -1
- package/benchmark/report.html +46 -1
- package/benchmark/report.json +563 -8
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +36 -18
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +46 -29
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +158 -129
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +182 -184
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +73 -63
- package/dist/cjs/data-structures/binary-tree/bst.js +168 -169
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +54 -17
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +77 -31
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +29 -40
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js +66 -136
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.js +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +2 -6
- package/dist/cjs/data-structures/hash/hash-map.js +5 -8
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +19 -21
- package/dist/cjs/data-structures/heap/heap.js +52 -34
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/max-heap.d.ts +2 -5
- package/dist/cjs/data-structures/heap/max-heap.js +2 -2
- package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/min-heap.d.ts +2 -5
- package/dist/cjs/data-structures/heap/min-heap.js +2 -2
- package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +9 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +2 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +8 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +2 -5
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +2 -2
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +2 -5
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +2 -2
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +2 -5
- package/dist/cjs/data-structures/priority-queue/priority-queue.js +2 -2
- package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +1 -0
- package/dist/cjs/data-structures/queue/deque.js +3 -0
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +1 -0
- package/dist/cjs/data-structures/queue/queue.js +3 -0
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/stack/stack.d.ts +2 -1
- package/dist/cjs/data-structures/stack/stack.js +10 -2
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +3 -0
- package/dist/cjs/data-structures/trie/trie.js +19 -4
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +4 -2
- package/dist/cjs/types/common.d.ts +7 -0
- package/dist/cjs/types/common.js.map +1 -1
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +2 -2
- package/dist/cjs/types/data-structures/hash/hash-map.d.ts +1 -2
- package/dist/cjs/types/data-structures/heap/heap.d.ts +4 -1
- package/dist/cjs/types/data-structures/priority-queue/priority-queue.d.ts +2 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +36 -18
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +49 -30
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +158 -129
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +182 -194
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +73 -63
- package/dist/mjs/data-structures/binary-tree/bst.js +171 -170
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +54 -17
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +81 -33
- package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +29 -40
- package/dist/mjs/data-structures/binary-tree/tree-multimap.js +70 -138
- package/dist/mjs/data-structures/graph/abstract-graph.js +1 -1
- package/dist/mjs/data-structures/hash/hash-map.d.ts +2 -6
- package/dist/mjs/data-structures/hash/hash-map.js +5 -8
- package/dist/mjs/data-structures/heap/heap.d.ts +19 -21
- package/dist/mjs/data-structures/heap/heap.js +53 -35
- package/dist/mjs/data-structures/heap/max-heap.d.ts +2 -5
- package/dist/mjs/data-structures/heap/max-heap.js +2 -2
- package/dist/mjs/data-structures/heap/min-heap.d.ts +2 -5
- package/dist/mjs/data-structures/heap/min-heap.js +2 -2
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +9 -1
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +2 -1
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +8 -1
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.d.ts +2 -5
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +2 -2
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.d.ts +2 -5
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +2 -2
- package/dist/mjs/data-structures/priority-queue/priority-queue.d.ts +2 -5
- package/dist/mjs/data-structures/priority-queue/priority-queue.js +2 -2
- package/dist/mjs/data-structures/queue/deque.d.ts +1 -0
- package/dist/mjs/data-structures/queue/deque.js +3 -0
- package/dist/mjs/data-structures/queue/queue.d.ts +1 -0
- package/dist/mjs/data-structures/queue/queue.js +3 -0
- package/dist/mjs/data-structures/stack/stack.d.ts +2 -1
- package/dist/mjs/data-structures/stack/stack.js +10 -2
- package/dist/mjs/data-structures/trie/trie.d.ts +3 -0
- package/dist/mjs/data-structures/trie/trie.js +20 -4
- package/dist/mjs/interfaces/binary-tree.d.ts +4 -2
- package/dist/mjs/types/common.d.ts +7 -0
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +2 -2
- package/dist/mjs/types/data-structures/hash/hash-map.d.ts +1 -2
- package/dist/mjs/types/data-structures/heap/heap.d.ts +4 -1
- package/dist/mjs/types/data-structures/priority-queue/priority-queue.d.ts +2 -1
- package/dist/umd/data-structure-typed.js +629 -595
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +1 -1
- package/src/data-structures/binary-tree/avl-tree.ts +61 -31
- package/src/data-structures/binary-tree/binary-tree.ts +283 -254
- package/src/data-structures/binary-tree/bst.ts +193 -170
- package/src/data-structures/binary-tree/rb-tree.ts +87 -32
- package/src/data-structures/binary-tree/tree-multimap.ts +76 -136
- package/src/data-structures/graph/abstract-graph.ts +1 -1
- package/src/data-structures/hash/hash-map.ts +8 -8
- package/src/data-structures/heap/heap.ts +57 -39
- package/src/data-structures/heap/max-heap.ts +5 -5
- package/src/data-structures/heap/min-heap.ts +5 -5
- package/src/data-structures/linked-list/doubly-linked-list.ts +10 -1
- package/src/data-structures/linked-list/singly-linked-list.ts +9 -1
- package/src/data-structures/priority-queue/max-priority-queue.ts +4 -3
- package/src/data-structures/priority-queue/min-priority-queue.ts +12 -12
- package/src/data-structures/priority-queue/priority-queue.ts +3 -3
- package/src/data-structures/queue/deque.ts +4 -0
- package/src/data-structures/queue/queue.ts +4 -0
- package/src/data-structures/stack/stack.ts +12 -3
- package/src/data-structures/trie/trie.ts +23 -4
- package/src/interfaces/binary-tree.ts +14 -2
- package/src/types/common.ts +15 -1
- package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
- package/src/types/data-structures/binary-tree/bst.ts +2 -3
- package/src/types/data-structures/hash/hash-map.ts +1 -2
- package/src/types/data-structures/heap/heap.ts +3 -1
- package/src/types/data-structures/priority-queue/priority-queue.ts +3 -1
- package/test/integration/{all-in-one.ts → all-in-one.test.ts} +1 -1
- package/test/integration/index.html +87 -0
- package/test/performance/data-structures/comparison/comparison.test.ts +7 -6
- package/test/performance/data-structures/heap/heap.test.ts +2 -2
- package/test/performance/data-structures/priority-queue/priority-queue.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +20 -20
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +56 -57
- package/test/unit/data-structures/binary-tree/bst.test.ts +49 -54
- package/test/unit/data-structures/binary-tree/overall.test.ts +17 -18
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +3 -3
- package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +118 -66
- package/test/unit/data-structures/heap/heap.test.ts +2 -2
- package/test/unit/data-structures/heap/max-heap.test.ts +1 -1
- package/test/unit/data-structures/heap/min-heap.test.ts +1 -1
- package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +4 -3
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +9 -10
- package/test/unit/data-structures/stack/stack.test.ts +2 -2
- package/test/unit/unrestricted-interconversion.test.ts +156 -0
- package/tsconfig-cjs.json +1 -1
- package/test/integration/conversion.test.ts +0 -0
|
@@ -5,7 +5,7 @@ describe('Overall BinaryTree Test', () => {
|
|
|
5
5
|
const bst = new BST();
|
|
6
6
|
bst.add(11);
|
|
7
7
|
bst.add(3);
|
|
8
|
-
bst.addMany([15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5],
|
|
8
|
+
bst.addMany([15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5], false);
|
|
9
9
|
bst.size === 16; // true
|
|
10
10
|
expect(bst.size).toBe(16); // true
|
|
11
11
|
bst.has(6); // true
|
|
@@ -30,26 +30,25 @@ describe('Overall BinaryTree Test', () => {
|
|
|
30
30
|
expect(bfsIDs[0]).toBe(11);
|
|
31
31
|
|
|
32
32
|
const objBST = new BST<{ key: number; keyA: number }>();
|
|
33
|
-
objBST.add(11, { key: 11, keyA: 11 });
|
|
34
|
-
objBST.add(3, { key: 3, keyA: 3 });
|
|
33
|
+
objBST.add([11, { key: 11, keyA: 11 }]);
|
|
34
|
+
objBST.add([3, { key: 3, keyA: 3 }]);
|
|
35
35
|
|
|
36
36
|
objBST.addMany(
|
|
37
|
-
[15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5],
|
|
38
37
|
[
|
|
39
|
-
{ key: 15, keyA: 15 },
|
|
40
|
-
{ key: 1, keyA: 1 },
|
|
41
|
-
{ key: 8, keyA: 8 },
|
|
42
|
-
{ key: 13, keyA: 13 },
|
|
43
|
-
{ key: 16, keyA: 16 },
|
|
44
|
-
{ key: 2, keyA: 2 },
|
|
45
|
-
{ key: 6, keyA: 6 },
|
|
46
|
-
{ key: 9, keyA: 9 },
|
|
47
|
-
{ key: 12, keyA: 12 },
|
|
48
|
-
{ key: 14, keyA: 14 },
|
|
49
|
-
{ key: 4, keyA: 4 },
|
|
50
|
-
{ key: 7, keyA: 7 },
|
|
51
|
-
{ key: 10, keyA: 10 },
|
|
52
|
-
{ key: 5, keyA: 5 }
|
|
38
|
+
[15, { key: 15, keyA: 15 }],
|
|
39
|
+
[1, { key: 1, keyA: 1 }],
|
|
40
|
+
[8, { key: 8, keyA: 8 }],
|
|
41
|
+
[13, { key: 13, keyA: 13 }],
|
|
42
|
+
[16, { key: 16, keyA: 16 }],
|
|
43
|
+
[2, { key: 2, keyA: 2 }],
|
|
44
|
+
[6, { key: 6, keyA: 6 }],
|
|
45
|
+
[9, { key: 9, keyA: 9 }],
|
|
46
|
+
[12, { key: 12, keyA: 12 }],
|
|
47
|
+
[14, { key: 14, keyA: 14 }],
|
|
48
|
+
[4, { key: 4, keyA: 4 }],
|
|
49
|
+
[7, { key: 7, keyA: 7 }],
|
|
50
|
+
[10, { key: 10, keyA: 10 }],
|
|
51
|
+
[5, { key: 5, keyA: 5 }]
|
|
53
52
|
]
|
|
54
53
|
);
|
|
55
54
|
|
|
@@ -510,9 +510,9 @@ describe('RedBlackTree iterative methods test', () => {
|
|
|
510
510
|
let rbTree: RedBlackTree<string>;
|
|
511
511
|
beforeEach(() => {
|
|
512
512
|
rbTree = new RedBlackTree();
|
|
513
|
-
rbTree.add(1, 'a');
|
|
514
|
-
rbTree.add(2, 'b');
|
|
515
|
-
rbTree.add(3, 'c');
|
|
513
|
+
rbTree.add([1, 'a']);
|
|
514
|
+
rbTree.add([2, 'b']);
|
|
515
|
+
rbTree.add([3, 'c']);
|
|
516
516
|
});
|
|
517
517
|
|
|
518
518
|
test('The node obtained by get Node should match the node type', () => {
|
|
@@ -3,15 +3,52 @@ import { isDebugTest } from '../../../config';
|
|
|
3
3
|
|
|
4
4
|
const isDebug = isDebugTest;
|
|
5
5
|
|
|
6
|
-
describe('TreeMultimap
|
|
7
|
-
|
|
6
|
+
describe('TreeMultimap count', () => {
|
|
7
|
+
let tm: TreeMultimap<number>;
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
tm = new TreeMultimap<number>();
|
|
10
|
+
|
|
11
|
+
})
|
|
12
|
+
it('Should added isolated node count ', () => {
|
|
13
|
+
tm.addMany([[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]);
|
|
14
|
+
const newNode = new TreeMultimapNode(3, 33, 10);
|
|
15
|
+
tm.add(newNode);
|
|
16
|
+
expect(tm.count).toBe(15)
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('Should count', () => {
|
|
20
|
+
tm.addMany([[1, 1], [2, 2], [3, 3]]);
|
|
21
|
+
tm.lesserOrGreaterTraverse(node => node.count += 2, CP.gt, 1);
|
|
22
|
+
expect(tm.count).toBe(7)
|
|
23
|
+
})
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
describe('TreeMultimap operations test1', () => {
|
|
27
|
+
it('should perform various operations on a Binary Search Tree with numeric values1', () => {
|
|
8
28
|
const treeMultimap = new TreeMultimap();
|
|
9
29
|
|
|
10
30
|
expect(treeMultimap instanceof TreeMultimap);
|
|
11
|
-
treeMultimap.add(11, 11);
|
|
12
|
-
treeMultimap.add(3, 3);
|
|
13
|
-
const idAndValues
|
|
14
|
-
|
|
31
|
+
treeMultimap.add([11, 11]);
|
|
32
|
+
treeMultimap.add([3, 3]);
|
|
33
|
+
const idAndValues: [number, number][] = [
|
|
34
|
+
[11, 11],
|
|
35
|
+
[3, 3],
|
|
36
|
+
[15, 15],
|
|
37
|
+
[1, 1],
|
|
38
|
+
[8, 8],
|
|
39
|
+
[13, 13],
|
|
40
|
+
[16, 16],
|
|
41
|
+
[2, 2],
|
|
42
|
+
[6, 6],
|
|
43
|
+
[9, 9],
|
|
44
|
+
[12, 12],
|
|
45
|
+
[14, 14],
|
|
46
|
+
[4, 4],
|
|
47
|
+
[7, 7],
|
|
48
|
+
[10, 10],
|
|
49
|
+
[5, 5]
|
|
50
|
+
];
|
|
51
|
+
treeMultimap.addMany(idAndValues);
|
|
15
52
|
expect(treeMultimap.root instanceof TreeMultimapNode);
|
|
16
53
|
|
|
17
54
|
if (treeMultimap.root) expect(treeMultimap.root.key == 11);
|
|
@@ -21,8 +58,8 @@ describe('TreeMultimap operations test', () => {
|
|
|
21
58
|
|
|
22
59
|
expect(treeMultimap.has(6));
|
|
23
60
|
|
|
24
|
-
expect(treeMultimap.getHeight(6)).toBe(
|
|
25
|
-
expect(treeMultimap.getDepth(6)).toBe(
|
|
61
|
+
expect(treeMultimap.getHeight(6)).toBe(4);
|
|
62
|
+
expect(treeMultimap.getDepth(6)).toBe(0);
|
|
26
63
|
const nodeId10 = treeMultimap.getNode(10);
|
|
27
64
|
expect(nodeId10?.key).toBe(10);
|
|
28
65
|
|
|
@@ -39,14 +76,14 @@ describe('TreeMultimap operations test', () => {
|
|
|
39
76
|
|
|
40
77
|
const node15 = treeMultimap.getNode(15);
|
|
41
78
|
const minNodeBySpecificNode = node15 && treeMultimap.getLeftMost(node15);
|
|
42
|
-
expect(minNodeBySpecificNode?.key).toBe(
|
|
79
|
+
expect(minNodeBySpecificNode?.key).toBe(15);
|
|
43
80
|
|
|
44
81
|
let subTreeSum = 0;
|
|
45
82
|
node15 && treeMultimap.subTreeTraverse((node: TreeMultimapNode<number>) => (subTreeSum += node.key), 15);
|
|
46
|
-
expect(subTreeSum).toBe(
|
|
83
|
+
expect(subTreeSum).toBe(31);
|
|
47
84
|
let lesserSum = 0;
|
|
48
85
|
treeMultimap.lesserOrGreaterTraverse((node: TreeMultimapNode<number>) => (lesserSum += node.key), CP.lt, 10);
|
|
49
|
-
expect(lesserSum).toBe(
|
|
86
|
+
expect(lesserSum).toBe(21);
|
|
50
87
|
|
|
51
88
|
expect(node15 instanceof TreeMultimapNode);
|
|
52
89
|
if (node15 instanceof TreeMultimapNode) {
|
|
@@ -203,39 +240,38 @@ describe('TreeMultimap operations test', () => {
|
|
|
203
240
|
expect(bfsNodes[1].key).toBe(2);
|
|
204
241
|
expect(bfsNodes[2].key).toBe(16);
|
|
205
242
|
|
|
206
|
-
expect(treeMultimap.count).toBe(
|
|
243
|
+
expect(treeMultimap.count).toBe(4);
|
|
207
244
|
});
|
|
208
245
|
|
|
209
246
|
it('should perform various operations on a Binary Search Tree with object values', () => {
|
|
210
247
|
const objTreeMultimap = new TreeMultimap<{ key: number; keyA: number }>();
|
|
211
248
|
expect(objTreeMultimap).toBeInstanceOf(TreeMultimap);
|
|
212
|
-
objTreeMultimap.add(11, { key: 11, keyA: 11 });
|
|
213
|
-
objTreeMultimap.add(3, { key: 3, keyA: 3 });
|
|
214
|
-
const values = [
|
|
215
|
-
{ key: 15, keyA: 15 },
|
|
216
|
-
{ key: 1, keyA: 1 },
|
|
217
|
-
{ key: 8, keyA: 8 },
|
|
218
|
-
{ key: 13, keyA: 13 },
|
|
219
|
-
{ key: 16, keyA: 16 },
|
|
220
|
-
{ key: 2, keyA: 2 },
|
|
221
|
-
{ key: 6, keyA: 6 },
|
|
222
|
-
{ key: 9, keyA: 9 },
|
|
223
|
-
{ key: 12, keyA: 12 },
|
|
224
|
-
{ key: 14, keyA: 14 },
|
|
225
|
-
{ key: 4, keyA: 4 },
|
|
226
|
-
{ key: 7, keyA: 7 },
|
|
227
|
-
{ key: 10, keyA: 10 },
|
|
228
|
-
{ key: 5, keyA: 5 }
|
|
249
|
+
objTreeMultimap.add([11, { key: 11, keyA: 11 }]);
|
|
250
|
+
objTreeMultimap.add([3, { key: 3, keyA: 3 }]);
|
|
251
|
+
const values: [number, { key: number, keyA: number }][] = [
|
|
252
|
+
[15, { key: 15, keyA: 15 }],
|
|
253
|
+
[1, { key: 1, keyA: 1 }],
|
|
254
|
+
[8, { key: 8, keyA: 8 }],
|
|
255
|
+
[13, { key: 13, keyA: 13 }],
|
|
256
|
+
[16, { key: 16, keyA: 16 }],
|
|
257
|
+
[2, { key: 2, keyA: 2 }],
|
|
258
|
+
[6, { key: 6, keyA: 6 }],
|
|
259
|
+
[9, { key: 9, keyA: 9 }],
|
|
260
|
+
[12, { key: 12, keyA: 12 }],
|
|
261
|
+
[14, { key: 14, keyA: 14 }],
|
|
262
|
+
[4, { key: 4, keyA: 4 }],
|
|
263
|
+
[7, { key: 7, keyA: 7 }],
|
|
264
|
+
[10, { key: 10, keyA: 10 }],
|
|
265
|
+
[5, { key: 5, keyA: 5 }]
|
|
229
266
|
];
|
|
230
267
|
|
|
231
268
|
objTreeMultimap.addMany(
|
|
232
|
-
values.map(item => item.key),
|
|
233
269
|
values
|
|
234
270
|
);
|
|
235
271
|
|
|
236
272
|
expect(objTreeMultimap.root).toBeInstanceOf(TreeMultimapNode);
|
|
237
273
|
|
|
238
|
-
if (objTreeMultimap.root) expect(objTreeMultimap.root.key).toBe(
|
|
274
|
+
if (objTreeMultimap.root) expect(objTreeMultimap.root.key).toBe(6);
|
|
239
275
|
|
|
240
276
|
expect(objTreeMultimap.count).toBe(16);
|
|
241
277
|
|
|
@@ -243,26 +279,43 @@ describe('TreeMultimap operations test', () => {
|
|
|
243
279
|
});
|
|
244
280
|
});
|
|
245
281
|
|
|
246
|
-
describe('TreeMultimap operations test
|
|
247
|
-
it('should perform various operations on a Binary Search Tree with numeric
|
|
248
|
-
const treeMultimap = new TreeMultimap({ iterationType: IterationType.RECURSIVE });
|
|
282
|
+
describe('TreeMultimap operations test recursively1', () => {
|
|
283
|
+
it('should perform various operations on a Binary Search Tree with numeric values1', () => {
|
|
284
|
+
const treeMultimap = new TreeMultimap<number>([], { iterationType: IterationType.RECURSIVE });
|
|
249
285
|
|
|
250
286
|
expect(treeMultimap instanceof TreeMultimap);
|
|
251
|
-
treeMultimap.add(11, 11);
|
|
252
|
-
treeMultimap.add(3, 3);
|
|
253
|
-
const idAndValues
|
|
254
|
-
|
|
255
|
-
|
|
287
|
+
treeMultimap.add([11, 11]);
|
|
288
|
+
treeMultimap.add([3, 3]);
|
|
289
|
+
const idAndValues: [number, number][] = [
|
|
290
|
+
[11, 11],
|
|
291
|
+
[3, 3],
|
|
292
|
+
[15, 15],
|
|
293
|
+
[1, 1],
|
|
294
|
+
[8, 8],
|
|
295
|
+
[13, 13],
|
|
296
|
+
[16, 16],
|
|
297
|
+
[2, 2],
|
|
298
|
+
[6, 6],
|
|
299
|
+
[9, 9],
|
|
300
|
+
[12, 12],
|
|
301
|
+
[14, 14],
|
|
302
|
+
[4, 4],
|
|
303
|
+
[7, 7],
|
|
304
|
+
[10, 10],
|
|
305
|
+
[5, 5]
|
|
306
|
+
];
|
|
307
|
+
treeMultimap.addMany(idAndValues);
|
|
308
|
+
expect(treeMultimap.root).toBeInstanceOf(TreeMultimapNode);
|
|
256
309
|
|
|
257
|
-
if (treeMultimap.root) expect(treeMultimap.root.key
|
|
310
|
+
if (treeMultimap.root) expect(treeMultimap.root.key).toBe(6);
|
|
258
311
|
|
|
259
312
|
expect(treeMultimap.size).toBe(16);
|
|
260
313
|
expect(treeMultimap.count).toBe(18);
|
|
261
314
|
|
|
262
315
|
expect(treeMultimap.has(6));
|
|
263
316
|
|
|
264
|
-
expect(treeMultimap.getHeight(6)).toBe(
|
|
265
|
-
expect(treeMultimap.getDepth(6)).toBe(
|
|
317
|
+
expect(treeMultimap.getHeight(6)).toBe(4);
|
|
318
|
+
expect(treeMultimap.getDepth(6)).toBe(0);
|
|
266
319
|
const nodeId10 = treeMultimap.getNode(10);
|
|
267
320
|
expect(nodeId10?.key).toBe(10);
|
|
268
321
|
|
|
@@ -279,14 +332,14 @@ describe('TreeMultimap operations test recursively', () => {
|
|
|
279
332
|
|
|
280
333
|
const node15 = treeMultimap.getNode(15);
|
|
281
334
|
const minNodeBySpecificNode = node15 && treeMultimap.getLeftMost(node15);
|
|
282
|
-
expect(minNodeBySpecificNode?.key).toBe(
|
|
335
|
+
expect(minNodeBySpecificNode?.key).toBe(15);
|
|
283
336
|
|
|
284
337
|
let subTreeSum = 0;
|
|
285
338
|
node15 && treeMultimap.subTreeTraverse((node: TreeMultimapNode<number>) => (subTreeSum += node.key), 15);
|
|
286
|
-
expect(subTreeSum).toBe(
|
|
339
|
+
expect(subTreeSum).toBe(31);
|
|
287
340
|
let lesserSum = 0;
|
|
288
341
|
treeMultimap.lesserOrGreaterTraverse((node: TreeMultimapNode<number>) => (lesserSum += node.key), CP.lt, 10);
|
|
289
|
-
expect(lesserSum).toBe(
|
|
342
|
+
expect(lesserSum).toBe(21);
|
|
290
343
|
|
|
291
344
|
expect(node15 instanceof TreeMultimapNode);
|
|
292
345
|
if (node15 instanceof TreeMultimapNode) {
|
|
@@ -303,7 +356,7 @@ describe('TreeMultimap operations test recursively', () => {
|
|
|
303
356
|
const dfsInorderNodes = treeMultimap.dfs(node => node, 'in');
|
|
304
357
|
expect(dfsInorderNodes[0].key).toBe(1);
|
|
305
358
|
expect(dfsInorderNodes[dfsInorderNodes.length - 1].key).toBe(16);
|
|
306
|
-
expect(treeMultimap.isPerfectlyBalanced()).toBe(
|
|
359
|
+
expect(treeMultimap.isPerfectlyBalanced()).toBe(true);
|
|
307
360
|
|
|
308
361
|
treeMultimap.perfectlyBalance();
|
|
309
362
|
|
|
@@ -443,39 +496,38 @@ describe('TreeMultimap operations test recursively', () => {
|
|
|
443
496
|
expect(bfsNodes[1].key).toBe(2);
|
|
444
497
|
expect(bfsNodes[2].key).toBe(16);
|
|
445
498
|
|
|
446
|
-
expect(treeMultimap.count).toBe(
|
|
499
|
+
expect(treeMultimap.count).toBe(4);
|
|
447
500
|
});
|
|
448
501
|
|
|
449
502
|
it('should perform various operations on a Binary Search Tree with object values', () => {
|
|
450
503
|
const objTreeMultimap = new TreeMultimap<{ key: number; keyA: number }>();
|
|
451
504
|
expect(objTreeMultimap).toBeInstanceOf(TreeMultimap);
|
|
452
|
-
objTreeMultimap.add(11, { key: 11, keyA: 11 });
|
|
453
|
-
objTreeMultimap.add(3, { key: 3, keyA: 3 });
|
|
454
|
-
const values = [
|
|
455
|
-
{ key: 15, keyA: 15 },
|
|
456
|
-
{ key: 1, keyA: 1 },
|
|
457
|
-
{ key: 8, keyA: 8 },
|
|
458
|
-
{ key: 13, keyA: 13 },
|
|
459
|
-
{ key: 16, keyA: 16 },
|
|
460
|
-
{ key: 2, keyA: 2 },
|
|
461
|
-
{ key: 6, keyA: 6 },
|
|
462
|
-
{ key: 9, keyA: 9 },
|
|
463
|
-
{ key: 12, keyA: 12 },
|
|
464
|
-
{ key: 14, keyA: 14 },
|
|
465
|
-
{ key: 4, keyA: 4 },
|
|
466
|
-
{ key: 7, keyA: 7 },
|
|
467
|
-
{ key: 10, keyA: 10 },
|
|
468
|
-
{ key: 5, keyA: 5 }
|
|
505
|
+
objTreeMultimap.add([11, { key: 11, keyA: 11 }]);
|
|
506
|
+
objTreeMultimap.add([3, { key: 3, keyA: 3 }]);
|
|
507
|
+
const values: [number, { key: number; keyA: number }][] = [
|
|
508
|
+
[15, { key: 15, keyA: 15 }],
|
|
509
|
+
[1, { key: 1, keyA: 1 }],
|
|
510
|
+
[8, { key: 8, keyA: 8 }],
|
|
511
|
+
[13, { key: 13, keyA: 13 }],
|
|
512
|
+
[16, { key: 16, keyA: 16 }],
|
|
513
|
+
[2, { key: 2, keyA: 2 }],
|
|
514
|
+
[6, { key: 6, keyA: 6 }],
|
|
515
|
+
[9, { key: 9, keyA: 9 }],
|
|
516
|
+
[12, { key: 12, keyA: 12 }],
|
|
517
|
+
[14, { key: 14, keyA: 14 }],
|
|
518
|
+
[4, { key: 4, keyA: 4 }],
|
|
519
|
+
[7, { key: 7, keyA: 7 }],
|
|
520
|
+
[10, { key: 10, keyA: 10 }],
|
|
521
|
+
[5, { key: 5, keyA: 5 }]
|
|
469
522
|
];
|
|
470
523
|
|
|
471
524
|
objTreeMultimap.addMany(
|
|
472
|
-
values.map(item => item.key),
|
|
473
525
|
values
|
|
474
526
|
);
|
|
475
527
|
|
|
476
528
|
expect(objTreeMultimap.root).toBeInstanceOf(TreeMultimapNode);
|
|
477
529
|
|
|
478
|
-
if (objTreeMultimap.root) expect(objTreeMultimap.root.key).toBe(
|
|
530
|
+
if (objTreeMultimap.root) expect(objTreeMultimap.root.key).toBe(6);
|
|
479
531
|
|
|
480
532
|
expect(objTreeMultimap.count).toBe(16);
|
|
481
533
|
|
|
@@ -23,7 +23,7 @@ describe('Heap Operation Test', () => {
|
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
it('should object heap work well', function () {
|
|
26
|
-
const minHeap = new MinHeap<{ a: string; key: number }>({ comparator: (a, b) => a.key - b.key });
|
|
26
|
+
const minHeap = new MinHeap<{ a: string; key: number }>([], { comparator: (a, b) => a.key - b.key });
|
|
27
27
|
minHeap.add({ key: 1, a: 'a1' });
|
|
28
28
|
minHeap.add({ key: 6, a: 'a6' });
|
|
29
29
|
minHeap.add({ key: 2, a: 'a2' });
|
|
@@ -43,7 +43,7 @@ describe('Heap Operation Test', () => {
|
|
|
43
43
|
i++;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
const maxHeap = new MaxHeap<{ key: number; a: string }>({ comparator: (a, b) => b.key - a.key });
|
|
46
|
+
const maxHeap = new MaxHeap<{ key: number; a: string }>([], { comparator: (a, b) => b.key - a.key });
|
|
47
47
|
maxHeap.add({ key: 1, a: 'a1' });
|
|
48
48
|
maxHeap.add({ key: 6, a: 'a6' });
|
|
49
49
|
maxHeap.add({ key: 5, a: 'a5' });
|
|
@@ -5,7 +5,7 @@ describe('MaxHeap', () => {
|
|
|
5
5
|
let maxHeap: MaxHeap<number>;
|
|
6
6
|
|
|
7
7
|
beforeEach(() => {
|
|
8
|
-
maxHeap = new MaxHeap({ comparator: numberComparator });
|
|
8
|
+
maxHeap = new MaxHeap([], { comparator: numberComparator });
|
|
9
9
|
});
|
|
10
10
|
|
|
11
11
|
it('add and poll elements in descending order', () => {
|
|
@@ -5,7 +5,7 @@ describe('MinHeap', () => {
|
|
|
5
5
|
let minHeap: MinHeap<number>;
|
|
6
6
|
|
|
7
7
|
beforeEach(() => {
|
|
8
|
-
minHeap = new MinHeap({ comparator: numberComparator });
|
|
8
|
+
minHeap = new MinHeap([], { comparator: numberComparator });
|
|
9
9
|
});
|
|
10
10
|
|
|
11
11
|
it('add and poll elements in ascending order', () => {
|
|
@@ -16,7 +16,7 @@ describe('MaxPriorityQueue Operation Test', () => {
|
|
|
16
16
|
});
|
|
17
17
|
|
|
18
18
|
it('should add elements and maintain heap property in a object MaxPriorityQueue', () => {
|
|
19
|
-
const priorityQueue = new MaxPriorityQueue<{ keyA: number }>({ comparator: (a, b) => b.keyA - a.keyA });
|
|
19
|
+
const priorityQueue = new MaxPriorityQueue<{ keyA: number }>([], { comparator: (a, b) => b.keyA - a.keyA });
|
|
20
20
|
priorityQueue.refill([{ keyA: 5 }, { keyA: 3 }, { keyA: 1 }]);
|
|
21
21
|
priorityQueue.add({ keyA: 7 });
|
|
22
22
|
|
|
@@ -52,7 +52,7 @@ describe('MaxPriorityQueue Operation Test', () => {
|
|
|
52
52
|
|
|
53
53
|
it('should correctly heapify an array', () => {
|
|
54
54
|
const array = [5, 3, 7, 1];
|
|
55
|
-
const heap = MaxPriorityQueue.heapify<number>(
|
|
55
|
+
const heap = MaxPriorityQueue.heapify<number>(array, { comparator: (a, b) => b - a });
|
|
56
56
|
heap.refill(array);
|
|
57
57
|
|
|
58
58
|
expect(heap.poll()).toBe(7);
|
|
@@ -63,7 +63,8 @@ describe('MaxPriorityQueue Operation Test', () => {
|
|
|
63
63
|
|
|
64
64
|
it('should correctly heapify an object array', () => {
|
|
65
65
|
const elements = [{ keyA: 5 }, { keyA: 3 }, { keyA: 7 }, { keyA: 1 }];
|
|
66
|
-
|
|
66
|
+
debugger
|
|
67
|
+
const maxPQ = MaxPriorityQueue.heapify<{ keyA: number }>(elements, { comparator: (a, b) => b.keyA - a.keyA });
|
|
67
68
|
|
|
68
69
|
expect(maxPQ.poll()?.keyA).toBe(7);
|
|
69
70
|
expect(maxPQ.poll()?.keyA).toBe(5);
|
|
@@ -5,7 +5,7 @@ import { isDebugTest } from '../../../config';
|
|
|
5
5
|
const isDebug = isDebugTest;
|
|
6
6
|
describe('PriorityQueue Operation Test', () => {
|
|
7
7
|
it('should PriorityQueue poll, pee, heapify, toArray work well', function () {
|
|
8
|
-
const minPQ = new PriorityQueue<number>({ comparator: (a, b) => a - b });
|
|
8
|
+
const minPQ = new PriorityQueue<number>([], { comparator: (a, b) => a - b });
|
|
9
9
|
minPQ.refill([5, 2, 3, 4, 6, 1]);
|
|
10
10
|
expect(minPQ.toArray()).toEqual([1, 2, 3, 4, 6, 5]);
|
|
11
11
|
minPQ.poll();
|
|
@@ -14,15 +14,14 @@ describe('PriorityQueue Operation Test', () => {
|
|
|
14
14
|
expect(minPQ.toArray()).toEqual([4, 5, 6]);
|
|
15
15
|
expect(minPQ.peek()).toBe(4);
|
|
16
16
|
expect(
|
|
17
|
-
PriorityQueue.heapify({
|
|
18
|
-
elements: [3, 2, 1, 5, 6, 7, 8, 9, 10],
|
|
17
|
+
PriorityQueue.heapify([3, 2, 1, 5, 6, 7, 8, 9, 10], {
|
|
19
18
|
comparator: (a, b) => a - b
|
|
20
19
|
}).toArray()
|
|
21
|
-
).toEqual([1,
|
|
20
|
+
).toEqual([1, 3, 2, 5, 6, 7, 8, 9, 10]);
|
|
22
21
|
});
|
|
23
22
|
|
|
24
23
|
it('should Max PriorityQueue poll, peek, heapify, toArray work well', function () {
|
|
25
|
-
const maxPriorityQueue = new PriorityQueue<number>({ comparator: (a, b) => b - a });
|
|
24
|
+
const maxPriorityQueue = new PriorityQueue<number>([], { comparator: (a, b) => b - a });
|
|
26
25
|
maxPriorityQueue.refill([5, 2, 3, 4, 6, 1]);
|
|
27
26
|
expect(maxPriorityQueue.toArray()).toEqual([6, 5, 3, 4, 2, 1]);
|
|
28
27
|
maxPriorityQueue.poll();
|
|
@@ -31,15 +30,15 @@ describe('PriorityQueue Operation Test', () => {
|
|
|
31
30
|
expect(maxPriorityQueue.toArray()).toEqual([3, 2, 1]);
|
|
32
31
|
expect(maxPriorityQueue.peek()).toBe(3);
|
|
33
32
|
expect(
|
|
34
|
-
PriorityQueue.heapify({
|
|
35
|
-
|
|
33
|
+
PriorityQueue.heapify([3, 2, 1, 5, 6, 7, 8, 9, 10], {
|
|
34
|
+
|
|
36
35
|
comparator: (a, b) => a - b
|
|
37
36
|
}).toArray()
|
|
38
|
-
).toEqual([1,
|
|
37
|
+
).toEqual([1, 3, 2, 5, 6, 7, 8, 9, 10]);
|
|
39
38
|
});
|
|
40
39
|
|
|
41
40
|
it('should PriorityQueue clone, sort, getNodes, dfs work well', function () {
|
|
42
|
-
const minPQ1 = new PriorityQueue<number>({ comparator: (a, b) => a - b });
|
|
41
|
+
const minPQ1 = new PriorityQueue<number>([], { comparator: (a, b) => a - b });
|
|
43
42
|
minPQ1.refill([2, 5, 8, 3, 1, 6, 7, 4]);
|
|
44
43
|
const clonedPriorityQueue = minPQ1.clone();
|
|
45
44
|
expect(clonedPriorityQueue.elements).toEqual(minPQ1.elements);
|
|
@@ -52,7 +51,7 @@ describe('PriorityQueue Operation Test', () => {
|
|
|
52
51
|
|
|
53
52
|
describe('Priority Queue Performance Test', () => {
|
|
54
53
|
it('should numeric heap work well', function () {
|
|
55
|
-
const pq = new PriorityQueue({ comparator: (a, b) => b - a });
|
|
54
|
+
const pq = new PriorityQueue<number>([], { comparator: (a, b) => b - a });
|
|
56
55
|
|
|
57
56
|
const tS = performance.now();
|
|
58
57
|
|
|
@@ -83,7 +83,7 @@ describe('Stack iterative methods', () => {
|
|
|
83
83
|
result.push(element);
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
expect(result).toEqual([
|
|
86
|
+
expect(result).toEqual([1, 2, 3]); // iteration should start from the top of the stack
|
|
87
87
|
});
|
|
88
88
|
|
|
89
89
|
test('should apply forEach to the stack', () => {
|
|
@@ -92,7 +92,7 @@ describe('Stack iterative methods', () => {
|
|
|
92
92
|
result.push(element);
|
|
93
93
|
});
|
|
94
94
|
|
|
95
|
-
expect(result).toEqual([
|
|
95
|
+
expect(result).toEqual([1, 2, 3]);
|
|
96
96
|
});
|
|
97
97
|
|
|
98
98
|
test('should filter elements in the stack', () => {
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AVLTree,
|
|
3
|
+
BinaryTree,
|
|
4
|
+
BST,
|
|
5
|
+
Deque,
|
|
6
|
+
DoublyLinkedList,
|
|
7
|
+
HashMap,
|
|
8
|
+
Heap,
|
|
9
|
+
MaxHeap,
|
|
10
|
+
MaxPriorityQueue,
|
|
11
|
+
MinHeap,
|
|
12
|
+
MinPriorityQueue,
|
|
13
|
+
Queue,
|
|
14
|
+
RedBlackTree,
|
|
15
|
+
SinglyLinkedList,
|
|
16
|
+
Stack,
|
|
17
|
+
TreeMultimap,
|
|
18
|
+
Trie
|
|
19
|
+
} from '../../src';
|
|
20
|
+
import { isDebugTest } from "../config";
|
|
21
|
+
|
|
22
|
+
const isDebug = isDebugTest;
|
|
23
|
+
const orgArr: number[] = [6, 1, 2, 7, 5, 3, 4, 9, 8];
|
|
24
|
+
const orgStrArr: string[] = [
|
|
25
|
+
"trie",
|
|
26
|
+
"trial",
|
|
27
|
+
"trick",
|
|
28
|
+
"trip",
|
|
29
|
+
"tree",
|
|
30
|
+
"trend",
|
|
31
|
+
"triangle",
|
|
32
|
+
"track",
|
|
33
|
+
"trace",
|
|
34
|
+
"transmit"
|
|
35
|
+
];
|
|
36
|
+
const entries: [number, number][] = [[6, 6], [1, 1], [2, 2], [7, 7], [5, 5], [3, 3], [4, 4], [9, 9], [8, 8]];
|
|
37
|
+
|
|
38
|
+
describe('conversions', () => {
|
|
39
|
+
it('Array to Queue', () => {
|
|
40
|
+
const q = new Queue<number>(orgArr);
|
|
41
|
+
isDebug && q.print();
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it('Array to Deque', () => {
|
|
45
|
+
const dq = new Deque<number>(orgArr);
|
|
46
|
+
isDebug && dq.print();
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('Array to SinglyLinkedList', () => {
|
|
50
|
+
const sl = new SinglyLinkedList<number>(orgArr);
|
|
51
|
+
isDebug && sl.print();
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('Array to DoublyLinkedList', () => {
|
|
55
|
+
const dl = new DoublyLinkedList<number>(orgArr);
|
|
56
|
+
isDebug && dl.print();
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('Array to Stack', () => {
|
|
60
|
+
const stack = new Stack<number>(orgArr);
|
|
61
|
+
isDebug && stack.print();
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('Array to MinHeap', () => {
|
|
65
|
+
const minHeap = new MinHeap<number>(orgArr);
|
|
66
|
+
isDebug && minHeap.print();
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it('Array to MaxHeap', () => {
|
|
70
|
+
const maxHeap = new MaxHeap<number>(orgArr);
|
|
71
|
+
isDebug && maxHeap.print();
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it('Array to MinPriorityQueue', () => {
|
|
75
|
+
const minPQ = new MinPriorityQueue<number>(orgArr);
|
|
76
|
+
isDebug && minPQ.print();
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it('Array to MaxPriorityQueue', () => {
|
|
80
|
+
const maxPQ = new MaxPriorityQueue<number>(orgArr);
|
|
81
|
+
isDebug && maxPQ.print();
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('Entry Array to BinaryTree', () => {
|
|
85
|
+
const biTree = new BinaryTree<number>(entries);
|
|
86
|
+
isDebug && biTree.print();
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
it('Entry Array to BST', () => {
|
|
90
|
+
const bst = new BST<number>(entries);
|
|
91
|
+
expect(bst.size).toBe(9)
|
|
92
|
+
isDebug && bst.print();
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
it('Entry Array to RedBlackTree', () => {
|
|
96
|
+
const rbTree = new RedBlackTree<number>(entries);
|
|
97
|
+
expect(rbTree.size).toBe(9)
|
|
98
|
+
isDebug && rbTree.print();
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
it('Entry Array to AVLTree', () => {
|
|
102
|
+
const avl = new AVLTree<number>(entries);
|
|
103
|
+
expect(avl.size).toBe(9)
|
|
104
|
+
isDebug && avl.print();
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
it('Entry Array to TreeMultimap', () => {
|
|
108
|
+
const treeMulti = new TreeMultimap<number>(entries);
|
|
109
|
+
expect(treeMulti.size).toBe(9)
|
|
110
|
+
isDebug && treeMulti.print();
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
it('HashMap to RedBlackTree', () => {
|
|
114
|
+
const hm = new HashMap(entries);
|
|
115
|
+
isDebug && hm.print()
|
|
116
|
+
const rbTree = new RedBlackTree<number>(hm);
|
|
117
|
+
expect(rbTree.size).toBe(9)
|
|
118
|
+
isDebug && rbTree.print();
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
it('PriorityQueue to BST', () => {
|
|
122
|
+
const pq = new MinPriorityQueue(orgArr);
|
|
123
|
+
isDebug && pq.print();
|
|
124
|
+
const bst = new BST<number>(pq);
|
|
125
|
+
expect(bst.size).toBe(9)
|
|
126
|
+
isDebug && bst.print();
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
it('Deque to RedBlackTree', () => {
|
|
130
|
+
const dq = new Deque(orgArr);
|
|
131
|
+
isDebug && dq.print();
|
|
132
|
+
const rbTree = new RedBlackTree<number>(dq);
|
|
133
|
+
expect(rbTree.size).toBe(9)
|
|
134
|
+
isDebug && rbTree.print();
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
it('Trie to Heap to Deque', () => {
|
|
138
|
+
const trie = new Trie(orgStrArr);
|
|
139
|
+
expect(trie.size).toBe(10);
|
|
140
|
+
isDebug && trie.print();
|
|
141
|
+
const heap = new Heap<string>(trie, { comparator: (a, b) => Number(a) - Number(b) });
|
|
142
|
+
expect(heap.size).toBe(10);
|
|
143
|
+
isDebug && heap.print();
|
|
144
|
+
const dq = new Deque<string>(heap);
|
|
145
|
+
expect(dq.size).toBe(10);
|
|
146
|
+
isDebug && dq.print();
|
|
147
|
+
const entries = dq.map((el, i) => <[number, string]>[i, el]);
|
|
148
|
+
const avl = new AVLTree<string>(entries);
|
|
149
|
+
expect(avl.size).toBe(10)
|
|
150
|
+
isDebug && avl.print();
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
package/tsconfig-cjs.json
CHANGED
|
File without changes
|