data-structure-typed 1.50.0 → 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 +37 -1
- package/benchmark/report.json +374 -20
- package/package.json +12 -41
- package/test/unit/data-structures/hash/hash-map.test.ts +1 -1
- package/test/unit/data-structures/queue/deque.test.ts +6 -5
- package/test/unit/data-structures/queue/queue.test.ts +1 -1
- package/test/unit/unrestricted-interconversion.test.ts +143 -10
|
@@ -164,13 +164,14 @@ describe('Deque - Utility Operations', () => {
|
|
|
164
164
|
});
|
|
165
165
|
|
|
166
166
|
test('print should print the deque elements', () => {
|
|
167
|
-
const consoleSpy = jest.spyOn(console, 'log');
|
|
168
|
-
deque.push(1);
|
|
169
|
-
deque.push(2);
|
|
170
|
-
deque.print();
|
|
171
|
-
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]);
|
|
172
172
|
});
|
|
173
173
|
});
|
|
174
|
+
|
|
174
175
|
describe('Deque - Additional Operations', () => {
|
|
175
176
|
let deque: Deque<number>;
|
|
176
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
|
});
|