data-structure-typed 1.49.9 → 1.50.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/CHANGELOG.md +1 -1
- package/README.md +192 -200
- package/benchmark/report.html +13 -13
- package/benchmark/report.json +158 -152
- package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +0 -7
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +0 -9
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +5 -22
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +9 -80
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +89 -27
- package/dist/cjs/data-structures/binary-tree/bst.js +131 -46
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +0 -7
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +1 -10
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +0 -7
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js +2 -11
- package/dist/cjs/data-structures/binary-tree/tree-multimap.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.d.ts +3 -3
- package/dist/cjs/data-structures/hash/hash-map.js +6 -6
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.js.map +1 -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.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/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +0 -7
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +0 -9
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +5 -22
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +9 -80
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +89 -27
- package/dist/mjs/data-structures/binary-tree/bst.js +131 -46
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +0 -7
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +1 -10
- package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +0 -7
- package/dist/mjs/data-structures/binary-tree/tree-multimap.js +2 -11
- package/dist/mjs/data-structures/hash/hash-map.d.ts +3 -3
- package/dist/mjs/data-structures/hash/hash-map.js +15 -15
- package/dist/umd/data-structure-typed.js +143 -153
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +12 -41
- package/src/data-structures/base/iterable-base.ts +6 -6
- package/src/data-structures/binary-tree/avl-tree.ts +7 -18
- package/src/data-structures/binary-tree/binary-tree.ts +111 -149
- package/src/data-structures/binary-tree/bst.ts +159 -56
- package/src/data-structures/binary-tree/rb-tree.ts +7 -18
- package/src/data-structures/binary-tree/tree-multimap.ts +8 -19
- package/src/data-structures/graph/abstract-graph.ts +14 -15
- package/src/data-structures/graph/directed-graph.ts +6 -7
- package/src/data-structures/graph/undirected-graph.ts +6 -7
- package/src/data-structures/hash/hash-map.ts +23 -22
- package/src/data-structures/heap/heap.ts +1 -1
- package/src/data-structures/linked-list/doubly-linked-list.ts +1 -1
- package/src/data-structures/linked-list/singly-linked-list.ts +1 -1
- package/src/data-structures/queue/deque.ts +3 -3
- package/src/data-structures/queue/queue.ts +1 -1
- package/src/data-structures/stack/stack.ts +1 -1
- package/src/data-structures/trie/trie.ts +1 -1
- package/src/types/data-structures/graph/abstract-graph.ts +8 -8
- package/test/integration/all-in-one.test.ts +1 -1
- package/test/integration/index.html +2 -2
- package/test/performance/data-structures/queue/deque.test.ts +8 -2
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +2 -2
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +38 -9
- package/test/unit/data-structures/binary-tree/bst.test.ts +8 -12
- package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +4 -4
- package/test/unit/data-structures/graph/abstract-graph.test.ts +2 -1
- package/test/unit/data-structures/hash/hash-map.test.ts +4 -2
- package/test/unit/data-structures/queue/deque.test.ts +8 -6
- package/test/unit/data-structures/queue/queue.test.ts +1 -1
- package/test/unit/unrestricted-interconversion.test.ts +143 -10
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
<meta charset='UTF-8'>
|
|
5
5
|
<title>CDN Test</title>
|
|
6
6
|
<!-- <script src="../../dist/umd/data-structure-typed.min.js"></script>-->
|
|
7
|
-
|
|
8
|
-
<!-- <script src='https://cdn.jsdelivr.net/npm/data-structure-typed/dist/umd/data-structure-typed.min.js'></script>-->
|
|
7
|
+
<script src="../../dist/umd/data-structure-typed.js"></script>
|
|
8
|
+
<!-- <script src='https://cdn.jsdelivr.net/npm/data-structure-typed/dist/umd/data-structure-typed.min.js'></script>-->
|
|
9
9
|
<!-- <script src='https://cdn.jsdelivr.net/npm/data-structure-typed@1.42.2/dist/umd/data-structure-typed.min.js'></script>-->
|
|
10
10
|
<!-- <script src='https://cdn.jsdelivr.net/npm/data-structure-typed@1.43.3/dist/umd/data-structure-typed.min.js'></script>-->
|
|
11
11
|
<!-- <script src='https://cdn.jsdelivr.net/npm/data-structure-typed@1.44.0/dist/umd/data-structure-typed.min.js'></script>-->
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Deque } from '../../../../src';
|
|
2
2
|
import { Deque as CDeque } from 'js-sdsl';
|
|
3
3
|
import * as Benchmark from 'benchmark';
|
|
4
|
-
import { magnitude } from '../../../utils';
|
|
4
|
+
import { getRandomInt, magnitude } from '../../../utils';
|
|
5
5
|
import { isCompetitor } from '../../../config';
|
|
6
6
|
|
|
7
7
|
export const suite = new Benchmark.Suite();
|
|
8
|
-
const { MILLION, HUNDRED_THOUSAND } = magnitude;
|
|
8
|
+
const { MILLION, HUNDRED_THOUSAND, TEN_THOUSAND } = magnitude;
|
|
9
9
|
|
|
10
10
|
suite.add(`${MILLION.toLocaleString()} push`, () => {
|
|
11
11
|
const deque = new Deque<number>();
|
|
@@ -20,6 +20,12 @@ if (isCompetitor) {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
suite
|
|
23
|
+
.add(`${TEN_THOUSAND.toLocaleString()} push & delete`, () => {
|
|
24
|
+
const _deque = new Deque<number>();
|
|
25
|
+
|
|
26
|
+
for (let i = 0; i < TEN_THOUSAND; i++) _deque.push(i);
|
|
27
|
+
for (let i = 0; i < TEN_THOUSAND; i++) _deque.delete(getRandomInt(0, TEN_THOUSAND - 1));
|
|
28
|
+
})
|
|
23
29
|
.add(`${MILLION.toLocaleString()} push & pop`, () => {
|
|
24
30
|
const _deque = new Deque<number>();
|
|
25
31
|
|
|
@@ -24,7 +24,7 @@ describe('AVL Tree Test', () => {
|
|
|
24
24
|
expect(getMinNodeBySpecificNode?.key).toBe(12);
|
|
25
25
|
|
|
26
26
|
let subTreeSum = 0;
|
|
27
|
-
node15 && tree.
|
|
27
|
+
node15 && tree.dfs(node => (subTreeSum += node.key), 'pre', node15);
|
|
28
28
|
expect(subTreeSum).toBe(70);
|
|
29
29
|
|
|
30
30
|
let lesserSum = 0;
|
|
@@ -132,7 +132,7 @@ describe('AVL Tree Test recursively', () => {
|
|
|
132
132
|
expect(getMinNodeBySpecificNode?.key).toBe(12);
|
|
133
133
|
|
|
134
134
|
let subTreeSum = 0;
|
|
135
|
-
node15 && tree.
|
|
135
|
+
node15 && tree.dfs(node => (subTreeSum += node.key), 'pre', node15);
|
|
136
136
|
expect(subTreeSum).toBe(70);
|
|
137
137
|
|
|
138
138
|
let lesserSum = 0;
|
|
@@ -238,16 +238,45 @@ describe('BinaryTree', () => {
|
|
|
238
238
|
expect(tree.getNodes(tree.getNodeByKey(2), undefined, false, tree.root)).toEqual([tree.getNodeByKey(2)]);
|
|
239
239
|
});
|
|
240
240
|
|
|
241
|
-
it('should subTreeTraverse', () => {
|
|
241
|
+
// it('should subTreeTraverse', () => {
|
|
242
|
+
// tree.addMany([4, 2, 6, null, 1, 3, null, 5, null, 7]);
|
|
243
|
+
// expect(tree.subTreeTraverse(node => node.key, tree.getNode(6), IterationType.ITERATIVE)).toEqual([6, 3, 7]);
|
|
244
|
+
// expect(tree.subTreeTraverse(node => node.key, tree.getNode(6), IterationType.ITERATIVE, false)).toEqual([6, 3, 7]);
|
|
245
|
+
// expect(tree.subTreeTraverse(node => node.key, tree.getNode(6), IterationType.RECURSIVE)).toEqual([6, 3, 7]);
|
|
246
|
+
// expect(
|
|
247
|
+
// tree.subTreeTraverse(node => (node ? node.key : null), tree.getNode(6), IterationType.ITERATIVE, true)
|
|
248
|
+
// ).toEqual([6, 3, 7, null]);
|
|
249
|
+
// expect(
|
|
250
|
+
// tree.subTreeTraverse(node => (node ? node.key : node), tree.getNode(6), IterationType.ITERATIVE, true)
|
|
251
|
+
// ).toEqual([6, 3, 7, null]);
|
|
252
|
+
// expect(
|
|
253
|
+
// tree.subTreeTraverse(node => (node ? node.key : null), tree.getNode(6), IterationType.RECURSIVE, true)
|
|
254
|
+
// ).toEqual([6, 3, 7, null]);
|
|
255
|
+
// });
|
|
256
|
+
|
|
257
|
+
it('should sub tree traverse', () => {
|
|
242
258
|
tree.addMany([4, 2, 6, null, 1, 3, null, 5, null, 7]);
|
|
243
|
-
expect(tree.
|
|
244
|
-
expect(tree.
|
|
245
|
-
expect(
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
259
|
+
expect(tree.dfs(node => node.key, 'pre', tree.getNode(6), IterationType.ITERATIVE)).toEqual([6, 3, 7]);
|
|
260
|
+
expect(tree.dfs(node => node.key, 'pre', tree.getNode(6), IterationType.ITERATIVE, false)).toEqual([6, 3, 7]);
|
|
261
|
+
expect(tree.dfs(node => node.key, 'pre', tree.getNode(6), IterationType.RECURSIVE)).toEqual([6, 3, 7]);
|
|
262
|
+
expect(tree.dfs(node => (node ? node.key : null), 'pre', tree.getNode(6), IterationType.ITERATIVE, true)).toEqual([
|
|
263
|
+
6,
|
|
264
|
+
3,
|
|
265
|
+
7,
|
|
266
|
+
null
|
|
267
|
+
]);
|
|
268
|
+
expect(tree.dfs(node => (node ? node.key : node), 'pre', tree.getNode(6), IterationType.ITERATIVE, true)).toEqual([
|
|
269
|
+
6,
|
|
270
|
+
3,
|
|
271
|
+
7,
|
|
272
|
+
null
|
|
273
|
+
]);
|
|
274
|
+
expect(tree.dfs(node => (node ? node.key : null), 'pre', tree.getNode(6), IterationType.RECURSIVE, true)).toEqual([
|
|
275
|
+
6,
|
|
276
|
+
3,
|
|
277
|
+
7,
|
|
278
|
+
null
|
|
279
|
+
]);
|
|
251
280
|
});
|
|
252
281
|
|
|
253
282
|
it('should clear the tree', () => {
|
|
@@ -54,7 +54,7 @@ describe('BST operations test', () => {
|
|
|
54
54
|
expect(minNodeBySpecificNode?.key).toBe(12);
|
|
55
55
|
|
|
56
56
|
let subTreeSum = 0;
|
|
57
|
-
node15 && bst.
|
|
57
|
+
node15 && bst.dfs(node => (subTreeSum += node.key), 'pre', 15);
|
|
58
58
|
expect(subTreeSum).toBe(70);
|
|
59
59
|
|
|
60
60
|
let lesserSum = 0;
|
|
@@ -257,7 +257,7 @@ describe('BST operations test', () => {
|
|
|
257
257
|
expect(minNodeBySpecificNode?.key).toBe(12);
|
|
258
258
|
|
|
259
259
|
let subTreeSum = 0;
|
|
260
|
-
node15 && objBST.
|
|
260
|
+
node15 && objBST.dfs(node => (subTreeSum += node.key), 'pre', node15);
|
|
261
261
|
expect(subTreeSum).toBe(70);
|
|
262
262
|
|
|
263
263
|
let lesserSum = 0;
|
|
@@ -444,7 +444,7 @@ describe('BST operations test recursively', () => {
|
|
|
444
444
|
expect(minNodeBySpecificNode?.key).toBe(12);
|
|
445
445
|
|
|
446
446
|
let subTreeSum = 0;
|
|
447
|
-
node15 && bst.
|
|
447
|
+
node15 && bst.dfs(node => (subTreeSum += node.key), 'pre', 15);
|
|
448
448
|
expect(subTreeSum).toBe(70);
|
|
449
449
|
|
|
450
450
|
let lesserSum = 0;
|
|
@@ -645,7 +645,7 @@ describe('BST operations test recursively', () => {
|
|
|
645
645
|
expect(minNodeBySpecificNode?.key).toBe(12);
|
|
646
646
|
|
|
647
647
|
let subTreeSum = 0;
|
|
648
|
-
node15 && objBST.
|
|
648
|
+
node15 && objBST.dfs(node => (subTreeSum += node.key), 'pre', node15);
|
|
649
649
|
expect(subTreeSum).toBe(70);
|
|
650
650
|
|
|
651
651
|
let lesserSum = 0;
|
|
@@ -868,14 +868,10 @@ describe('BST Performance test', function () {
|
|
|
868
868
|
it('should subTreeTraverse, null should be ignored', () => {
|
|
869
869
|
const bst = new BST();
|
|
870
870
|
bst.addMany([4, 2, 6, 1, 3, 5, 7]);
|
|
871
|
-
expect(bst.
|
|
872
|
-
expect(bst.
|
|
873
|
-
expect(bst.
|
|
874
|
-
|
|
875
|
-
]);
|
|
876
|
-
expect(bst.subTreeTraverse(node => node?.key ?? undefined, bst.getNode(6), IterationType.RECURSIVE, true)).toEqual([
|
|
877
|
-
6, 5, 7
|
|
878
|
-
]);
|
|
871
|
+
expect(bst.dfs(node => node.key, 'pre', bst.getNode(6), IterationType.ITERATIVE)).toEqual([6, 5, 7]);
|
|
872
|
+
expect(bst.dfs(node => node.key, 'pre', bst.getNode(6), IterationType.RECURSIVE)).toEqual([6, 5, 7]);
|
|
873
|
+
expect(bst.dfs(node => node?.key ?? undefined, 'pre', bst.getNode(6), IterationType.ITERATIVE)).toEqual([6, 5, 7]);
|
|
874
|
+
expect(bst.dfs(node => node?.key ?? undefined, 'pre', bst.getNode(6), IterationType.RECURSIVE)).toEqual([6, 5, 7]);
|
|
879
875
|
});
|
|
880
876
|
});
|
|
881
877
|
|
|
@@ -96,7 +96,7 @@ describe('TreeMultimap operations test1', () => {
|
|
|
96
96
|
expect(minNodeBySpecificNode?.key).toBe(15);
|
|
97
97
|
|
|
98
98
|
let subTreeSum = 0;
|
|
99
|
-
node15 && treeMultimap.
|
|
99
|
+
node15 && treeMultimap.dfs(node => (subTreeSum += node.key), 'pre', 15);
|
|
100
100
|
expect(subTreeSum).toBe(31);
|
|
101
101
|
let lesserSum = 0;
|
|
102
102
|
treeMultimap.lesserOrGreaterTraverse((node: TreeMultimapNode<number>) => (lesserSum += node.key), CP.lt, 10);
|
|
@@ -104,7 +104,7 @@ describe('TreeMultimap operations test1', () => {
|
|
|
104
104
|
|
|
105
105
|
expect(node15 instanceof TreeMultimapNode);
|
|
106
106
|
if (node15 instanceof TreeMultimapNode) {
|
|
107
|
-
const subTreeAdd = treeMultimap.
|
|
107
|
+
const subTreeAdd = treeMultimap.dfs(node => (node.count += 1), 'pre', 15);
|
|
108
108
|
expect(subTreeAdd);
|
|
109
109
|
}
|
|
110
110
|
const node11 = treeMultimap.getNode(11);
|
|
@@ -350,7 +350,7 @@ describe('TreeMultimap operations test recursively1', () => {
|
|
|
350
350
|
expect(minNodeBySpecificNode?.key).toBe(15);
|
|
351
351
|
|
|
352
352
|
let subTreeSum = 0;
|
|
353
|
-
node15 && treeMultimap.
|
|
353
|
+
node15 && treeMultimap.dfs(node => (subTreeSum += node.key), 'pre', 15);
|
|
354
354
|
expect(subTreeSum).toBe(31);
|
|
355
355
|
let lesserSum = 0;
|
|
356
356
|
treeMultimap.lesserOrGreaterTraverse((node: TreeMultimapNode<number>) => (lesserSum += node.key), CP.lt, 10);
|
|
@@ -358,7 +358,7 @@ describe('TreeMultimap operations test recursively1', () => {
|
|
|
358
358
|
|
|
359
359
|
expect(node15 instanceof TreeMultimapNode);
|
|
360
360
|
if (node15 instanceof TreeMultimapNode) {
|
|
361
|
-
const subTreeAdd = treeMultimap.
|
|
361
|
+
const subTreeAdd = treeMultimap.dfs(node => (node.count += 1), 'pre', 15);
|
|
362
362
|
expect(subTreeAdd);
|
|
363
363
|
}
|
|
364
364
|
const node11 = treeMultimap.getNode(11);
|
|
@@ -85,7 +85,8 @@ class MyGraph<
|
|
|
85
85
|
describe('AbstractGraph Operation Test', () => {
|
|
86
86
|
const myGraph: MyGraph<number, string> = new MyGraph<number, string>();
|
|
87
87
|
|
|
88
|
-
beforeEach(() => {
|
|
88
|
+
beforeEach(() => {
|
|
89
|
+
});
|
|
89
90
|
it('should edge cases', function () {
|
|
90
91
|
myGraph.addVertex('A', 1);
|
|
91
92
|
myGraph.addVertex('B', 2);
|
|
@@ -110,6 +110,8 @@ describe('HashMap Test2', () => {
|
|
|
110
110
|
|
|
111
111
|
test('Inheritability test', () => {
|
|
112
112
|
class ExtendedHashMap<K, V> extends HashMap<K, V> {
|
|
113
|
+
someOtherParam?: string;
|
|
114
|
+
|
|
113
115
|
constructor(
|
|
114
116
|
elements: Iterable<[K, V]> = [],
|
|
115
117
|
options?: {
|
|
@@ -118,8 +120,8 @@ describe('HashMap Test2', () => {
|
|
|
118
120
|
}
|
|
119
121
|
) {
|
|
120
122
|
const { someOtherParam, ...restOptions } = options || {};
|
|
121
|
-
// do something with someOtherParam
|
|
122
123
|
super(elements, restOptions);
|
|
124
|
+
this.someOtherParam = someOtherParam;
|
|
123
125
|
}
|
|
124
126
|
}
|
|
125
127
|
|
|
@@ -620,6 +622,6 @@ describe('LinkedHashMap setMany, keys, values', () => {
|
|
|
620
622
|
});
|
|
621
623
|
|
|
622
624
|
test('print', () => {
|
|
623
|
-
hm.print();
|
|
625
|
+
// hm.print();
|
|
624
626
|
});
|
|
625
627
|
});
|
|
@@ -114,7 +114,8 @@ describe('Deque - Complex Operations', () => {
|
|
|
114
114
|
expect([...deque]).toEqual([1, 2, 3]);
|
|
115
115
|
});
|
|
116
116
|
|
|
117
|
-
test('shrinkToFit should reduce the memory footprint', () => {
|
|
117
|
+
test('shrinkToFit should reduce the memory footprint', () => {
|
|
118
|
+
});
|
|
118
119
|
});
|
|
119
120
|
describe('Deque - Utility Operations', () => {
|
|
120
121
|
let deque: Deque<number>;
|
|
@@ -163,13 +164,14 @@ describe('Deque - Utility Operations', () => {
|
|
|
163
164
|
});
|
|
164
165
|
|
|
165
166
|
test('print should print the deque elements', () => {
|
|
166
|
-
const consoleSpy = jest.spyOn(console, 'log');
|
|
167
|
-
deque.push(1);
|
|
168
|
-
deque.push(2);
|
|
169
|
-
deque.print();
|
|
170
|
-
expect(consoleSpy).toHaveBeenCalledWith([1, 2]);
|
|
167
|
+
// const consoleSpy = jest.spyOn(console, 'log');
|
|
168
|
+
// deque.push(1);
|
|
169
|
+
// deque.push(2);
|
|
170
|
+
// deque.print();
|
|
171
|
+
// expect(consoleSpy).toHaveBeenCalledWith([1, 2]);
|
|
171
172
|
});
|
|
172
173
|
});
|
|
174
|
+
|
|
173
175
|
describe('Deque - Additional Operations', () => {
|
|
174
176
|
let deque: Deque<number>;
|
|
175
177
|
|
|
@@ -33,91 +33,155 @@ const orgStrArr: string[] = [
|
|
|
33
33
|
'trace',
|
|
34
34
|
'transmit'
|
|
35
35
|
];
|
|
36
|
-
const entries: [number,
|
|
37
|
-
[6, 6],
|
|
38
|
-
[1, 1],
|
|
39
|
-
[2, 2],
|
|
40
|
-
[7, 7],
|
|
41
|
-
[5, 5],
|
|
42
|
-
[3, 3],
|
|
43
|
-
[4, 4],
|
|
44
|
-
[9, 9],
|
|
45
|
-
[8, 8]
|
|
36
|
+
const entries: [number, string][] = [
|
|
37
|
+
[6, '6'],
|
|
38
|
+
[1, '1'],
|
|
39
|
+
[2, '2'],
|
|
40
|
+
[7, '7'],
|
|
41
|
+
[5, '5'],
|
|
42
|
+
[3, '3'],
|
|
43
|
+
[4, '4'],
|
|
44
|
+
[9, '9'],
|
|
45
|
+
[8, '8']
|
|
46
46
|
];
|
|
47
47
|
|
|
48
48
|
describe('conversions', () => {
|
|
49
49
|
it('Array to Queue', () => {
|
|
50
50
|
const q = new Queue<number>(orgArr);
|
|
51
51
|
isDebug && q.print();
|
|
52
|
+
expect([...q]).toEqual([6, 1, 2, 7, 5, 3, 4, 9, 8]);
|
|
52
53
|
});
|
|
53
54
|
|
|
54
55
|
it('Array to Deque', () => {
|
|
55
56
|
const dq = new Deque<number>(orgArr);
|
|
56
57
|
isDebug && dq.print();
|
|
58
|
+
expect([...dq]).toEqual([6, 1, 2, 7, 5, 3, 4, 9, 8]);
|
|
57
59
|
});
|
|
58
60
|
|
|
59
61
|
it('Array to SinglyLinkedList', () => {
|
|
60
62
|
const sl = new SinglyLinkedList<number>(orgArr);
|
|
61
63
|
isDebug && sl.print();
|
|
64
|
+
expect([...sl]).toEqual([6, 1, 2, 7, 5, 3, 4, 9, 8]);
|
|
62
65
|
});
|
|
63
66
|
|
|
64
67
|
it('Array to DoublyLinkedList', () => {
|
|
65
68
|
const dl = new DoublyLinkedList<number>(orgArr);
|
|
66
69
|
isDebug && dl.print();
|
|
70
|
+
expect([...dl]).toEqual([6, 1, 2, 7, 5, 3, 4, 9, 8]);
|
|
67
71
|
});
|
|
68
72
|
|
|
69
73
|
it('Array to Stack', () => {
|
|
70
74
|
const stack = new Stack<number>(orgArr);
|
|
71
75
|
isDebug && stack.print();
|
|
76
|
+
expect([...stack]).toEqual([6, 1, 2, 7, 5, 3, 4, 9, 8]);
|
|
72
77
|
});
|
|
73
78
|
|
|
74
79
|
it('Array to MinHeap', () => {
|
|
75
80
|
const minHeap = new MinHeap<number>(orgArr);
|
|
76
81
|
isDebug && minHeap.print();
|
|
82
|
+
expect([...minHeap]).toEqual([1, 5, 2, 7, 6, 3, 4, 9, 8]);
|
|
77
83
|
});
|
|
78
84
|
|
|
79
85
|
it('Array to MaxHeap', () => {
|
|
80
86
|
const maxHeap = new MaxHeap<number>(orgArr);
|
|
81
87
|
isDebug && maxHeap.print();
|
|
88
|
+
expect([...maxHeap]).toEqual([9, 8, 4, 7, 5, 2, 3, 1, 6]);
|
|
82
89
|
});
|
|
83
90
|
|
|
84
91
|
it('Array to MinPriorityQueue', () => {
|
|
85
92
|
const minPQ = new MinPriorityQueue<number>(orgArr);
|
|
86
93
|
isDebug && minPQ.print();
|
|
94
|
+
expect([...minPQ]).toEqual([1, 5, 2, 7, 6, 3, 4, 9, 8]);
|
|
87
95
|
});
|
|
88
96
|
|
|
89
97
|
it('Array to MaxPriorityQueue', () => {
|
|
90
98
|
const maxPQ = new MaxPriorityQueue<number>(orgArr);
|
|
91
99
|
isDebug && maxPQ.print();
|
|
100
|
+
expect([...maxPQ]).toEqual([9, 8, 4, 7, 5, 2, 3, 1, 6]);
|
|
92
101
|
});
|
|
93
102
|
|
|
94
103
|
it('Entry Array to BinaryTree', () => {
|
|
95
104
|
const biTree = new BinaryTree<number>(entries);
|
|
96
105
|
isDebug && biTree.print();
|
|
106
|
+
expect([...biTree]).toEqual([
|
|
107
|
+
[9, '9'],
|
|
108
|
+
[7, '7'],
|
|
109
|
+
[8, '8'],
|
|
110
|
+
[1, '1'],
|
|
111
|
+
[5, '5'],
|
|
112
|
+
[6, '6'],
|
|
113
|
+
[3, '3'],
|
|
114
|
+
[2, '2'],
|
|
115
|
+
[4, '4']
|
|
116
|
+
]);
|
|
97
117
|
});
|
|
98
118
|
|
|
99
119
|
it('Entry Array to BST', () => {
|
|
100
120
|
const bst = new BST<number>(entries);
|
|
101
121
|
expect(bst.size).toBe(9);
|
|
102
122
|
isDebug && bst.print();
|
|
123
|
+
expect([...bst]).toEqual([
|
|
124
|
+
[1, '1'],
|
|
125
|
+
[2, '2'],
|
|
126
|
+
[3, '3'],
|
|
127
|
+
[4, '4'],
|
|
128
|
+
[5, '5'],
|
|
129
|
+
[6, '6'],
|
|
130
|
+
[7, '7'],
|
|
131
|
+
[8, '8'],
|
|
132
|
+
[9, '9']
|
|
133
|
+
]);
|
|
103
134
|
});
|
|
104
135
|
|
|
105
136
|
it('Entry Array to RedBlackTree', () => {
|
|
106
137
|
const rbTree = new RedBlackTree<number>(entries);
|
|
107
138
|
expect(rbTree.size).toBe(9);
|
|
108
139
|
isDebug && rbTree.print();
|
|
140
|
+
expect([...rbTree]).toEqual([
|
|
141
|
+
[1, '1'],
|
|
142
|
+
[2, '2'],
|
|
143
|
+
[3, '3'],
|
|
144
|
+
[4, '4'],
|
|
145
|
+
[5, '5'],
|
|
146
|
+
[6, '6'],
|
|
147
|
+
[7, '7'],
|
|
148
|
+
[8, '8'],
|
|
149
|
+
[9, '9']
|
|
150
|
+
]);
|
|
109
151
|
});
|
|
110
152
|
|
|
111
153
|
it('Entry Array to AVLTree', () => {
|
|
112
154
|
const avl = new AVLTree<number>(entries);
|
|
113
155
|
expect(avl.size).toBe(9);
|
|
114
156
|
isDebug && avl.print();
|
|
157
|
+
expect([...avl]).toEqual([
|
|
158
|
+
[1, '1'],
|
|
159
|
+
[2, '2'],
|
|
160
|
+
[3, '3'],
|
|
161
|
+
[4, '4'],
|
|
162
|
+
[5, '5'],
|
|
163
|
+
[6, '6'],
|
|
164
|
+
[7, '7'],
|
|
165
|
+
[8, '8'],
|
|
166
|
+
[9, '9']
|
|
167
|
+
]);
|
|
115
168
|
});
|
|
116
169
|
|
|
117
170
|
it('Entry Array to TreeMultimap', () => {
|
|
118
171
|
const treeMulti = new TreeMultimap<number>(entries);
|
|
119
172
|
expect(treeMulti.size).toBe(9);
|
|
120
173
|
isDebug && treeMulti.print();
|
|
174
|
+
expect([...treeMulti]).toEqual([
|
|
175
|
+
[1, '1'],
|
|
176
|
+
[2, '2'],
|
|
177
|
+
[3, '3'],
|
|
178
|
+
[4, '4'],
|
|
179
|
+
[5, '5'],
|
|
180
|
+
[6, '6'],
|
|
181
|
+
[7, '7'],
|
|
182
|
+
[8, '8'],
|
|
183
|
+
[9, '9']
|
|
184
|
+
]);
|
|
121
185
|
});
|
|
122
186
|
|
|
123
187
|
it('HashMap to RedBlackTree', () => {
|
|
@@ -126,6 +190,17 @@ describe('conversions', () => {
|
|
|
126
190
|
const rbTree = new RedBlackTree<number>(hm);
|
|
127
191
|
expect(rbTree.size).toBe(9);
|
|
128
192
|
isDebug && rbTree.print();
|
|
193
|
+
expect([...rbTree]).toEqual([
|
|
194
|
+
[1, '1'],
|
|
195
|
+
[2, '2'],
|
|
196
|
+
[3, '3'],
|
|
197
|
+
[4, '4'],
|
|
198
|
+
[5, '5'],
|
|
199
|
+
[6, '6'],
|
|
200
|
+
[7, '7'],
|
|
201
|
+
[8, '8'],
|
|
202
|
+
[9, '9']
|
|
203
|
+
]);
|
|
129
204
|
});
|
|
130
205
|
|
|
131
206
|
it('PriorityQueue to BST', () => {
|
|
@@ -134,6 +209,17 @@ describe('conversions', () => {
|
|
|
134
209
|
const bst = new BST<number>(pq);
|
|
135
210
|
expect(bst.size).toBe(9);
|
|
136
211
|
isDebug && bst.print();
|
|
212
|
+
expect([...bst]).toEqual([
|
|
213
|
+
[1, undefined],
|
|
214
|
+
[2, undefined],
|
|
215
|
+
[3, undefined],
|
|
216
|
+
[4, undefined],
|
|
217
|
+
[5, undefined],
|
|
218
|
+
[6, undefined],
|
|
219
|
+
[7, undefined],
|
|
220
|
+
[8, undefined],
|
|
221
|
+
[9, undefined]
|
|
222
|
+
]);
|
|
137
223
|
});
|
|
138
224
|
|
|
139
225
|
it('Deque to RedBlackTree', () => {
|
|
@@ -142,6 +228,17 @@ describe('conversions', () => {
|
|
|
142
228
|
const rbTree = new RedBlackTree<number>(dq);
|
|
143
229
|
expect(rbTree.size).toBe(9);
|
|
144
230
|
isDebug && rbTree.print();
|
|
231
|
+
expect([...rbTree]).toEqual([
|
|
232
|
+
[1, undefined],
|
|
233
|
+
[2, undefined],
|
|
234
|
+
[3, undefined],
|
|
235
|
+
[4, undefined],
|
|
236
|
+
[5, undefined],
|
|
237
|
+
[6, undefined],
|
|
238
|
+
[7, undefined],
|
|
239
|
+
[8, undefined],
|
|
240
|
+
[9, undefined]
|
|
241
|
+
]);
|
|
145
242
|
});
|
|
146
243
|
|
|
147
244
|
it('Trie to Heap to Deque', () => {
|
|
@@ -151,12 +248,48 @@ describe('conversions', () => {
|
|
|
151
248
|
const heap = new Heap<string>(trie, { comparator: (a, b) => Number(a) - Number(b) });
|
|
152
249
|
expect(heap.size).toBe(10);
|
|
153
250
|
isDebug && heap.print();
|
|
251
|
+
expect([...heap]).toEqual([
|
|
252
|
+
'transmit',
|
|
253
|
+
'trace',
|
|
254
|
+
'tree',
|
|
255
|
+
'trend',
|
|
256
|
+
'track',
|
|
257
|
+
'trial',
|
|
258
|
+
'trip',
|
|
259
|
+
'trie',
|
|
260
|
+
'trick',
|
|
261
|
+
'triangle'
|
|
262
|
+
]);
|
|
154
263
|
const dq = new Deque<string>(heap);
|
|
155
264
|
expect(dq.size).toBe(10);
|
|
156
265
|
isDebug && dq.print();
|
|
266
|
+
expect([...dq]).toEqual([
|
|
267
|
+
'transmit',
|
|
268
|
+
'trace',
|
|
269
|
+
'tree',
|
|
270
|
+
'trend',
|
|
271
|
+
'track',
|
|
272
|
+
'trial',
|
|
273
|
+
'trip',
|
|
274
|
+
'trie',
|
|
275
|
+
'trick',
|
|
276
|
+
'triangle'
|
|
277
|
+
]);
|
|
157
278
|
const entries = dq.map((el, i) => <[number, string]>[i, el]);
|
|
158
279
|
const avl = new AVLTree<number, string>(entries);
|
|
159
280
|
expect(avl.size).toBe(10);
|
|
160
281
|
isDebug && avl.print();
|
|
282
|
+
expect([...avl]).toEqual([
|
|
283
|
+
[0, 'transmit'],
|
|
284
|
+
[1, 'trace'],
|
|
285
|
+
[2, 'tree'],
|
|
286
|
+
[3, 'trend'],
|
|
287
|
+
[4, 'track'],
|
|
288
|
+
[5, 'trial'],
|
|
289
|
+
[6, 'trip'],
|
|
290
|
+
[7, 'trie'],
|
|
291
|
+
[8, 'trick'],
|
|
292
|
+
[9, 'triangle']
|
|
293
|
+
]);
|
|
161
294
|
});
|
|
162
295
|
});
|