data-structure-typed 1.49.4 → 1.49.6
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 +15 -26
- package/README_zh-CN.md +1 -1
- package/benchmark/report.html +14 -23
- package/benchmark/report.json +163 -256
- package/dist/cjs/data-structures/base/iterable-base.d.ts +1 -1
- package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +53 -48
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +55 -49
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +154 -143
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +211 -198
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +83 -71
- package/dist/cjs/data-structures/binary-tree/bst.js +113 -89
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +37 -35
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +62 -59
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +46 -55
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js +59 -94
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.js +3 -2
- 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/map-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 +1 -1
- package/dist/cjs/data-structures/hash/hash-map.js +2 -2
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.js +2 -3
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/matrix/index.d.ts +0 -2
- package/dist/cjs/data-structures/matrix/index.js +0 -2
- package/dist/cjs/data-structures/matrix/index.js.map +1 -1
- package/dist/cjs/data-structures/matrix/matrix.d.ts +128 -10
- package/dist/cjs/data-structures/matrix/matrix.js +400 -15
- package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +2 -2
- package/dist/cjs/data-structures/queue/deque.js +5 -7
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +3 -3
- package/dist/cjs/types/common.d.ts +3 -3
- package/dist/cjs/types/common.js +2 -2
- package/dist/cjs/types/common.js.map +1 -1
- package/dist/cjs/types/data-structures/base/base.d.ts +1 -1
- package/dist/cjs/types/data-structures/heap/heap.d.ts +1 -1
- package/dist/cjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/cjs/utils/utils.d.ts +1 -0
- package/dist/cjs/utils/utils.js +6 -1
- package/dist/cjs/utils/utils.js.map +1 -1
- package/dist/mjs/data-structures/base/iterable-base.d.ts +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +53 -48
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +57 -50
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +154 -143
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +212 -199
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +83 -71
- package/dist/mjs/data-structures/binary-tree/bst.js +115 -90
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +37 -35
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +64 -60
- package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +46 -55
- package/dist/mjs/data-structures/binary-tree/tree-multimap.js +61 -95
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +1 -1
- package/dist/mjs/data-structures/graph/abstract-graph.js +4 -3
- package/dist/mjs/data-structures/hash/hash-map.d.ts +1 -1
- package/dist/mjs/data-structures/hash/hash-map.js +2 -2
- package/dist/mjs/data-structures/heap/heap.js +2 -3
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +1 -1
- package/dist/mjs/data-structures/matrix/index.d.ts +0 -2
- package/dist/mjs/data-structures/matrix/index.js +0 -2
- package/dist/mjs/data-structures/matrix/matrix.d.ts +128 -10
- package/dist/mjs/data-structures/matrix/matrix.js +399 -16
- package/dist/mjs/data-structures/queue/deque.d.ts +2 -2
- package/dist/mjs/data-structures/queue/deque.js +7 -9
- package/dist/mjs/data-structures/queue/queue.d.ts +1 -1
- package/dist/mjs/data-structures/queue/queue.js +1 -1
- package/dist/mjs/interfaces/binary-tree.d.ts +3 -3
- package/dist/mjs/types/common.d.ts +3 -3
- package/dist/mjs/types/common.js +2 -2
- package/dist/mjs/types/data-structures/base/base.d.ts +1 -1
- package/dist/mjs/types/data-structures/heap/heap.d.ts +1 -1
- package/dist/mjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/mjs/utils/utils.d.ts +1 -0
- package/dist/mjs/utils/utils.js +4 -0
- package/dist/umd/data-structure-typed.js +853 -943
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +4 -3
- package/src/data-structures/base/index.ts +1 -1
- package/src/data-structures/base/iterable-base.ts +7 -10
- package/src/data-structures/binary-tree/avl-tree.ts +73 -61
- package/src/data-structures/binary-tree/binary-tree.ts +301 -270
- package/src/data-structures/binary-tree/bst.ts +139 -115
- package/src/data-structures/binary-tree/rb-tree.ts +81 -73
- package/src/data-structures/binary-tree/tree-multimap.ts +72 -103
- package/src/data-structures/graph/abstract-graph.ts +13 -11
- package/src/data-structures/graph/directed-graph.ts +1 -3
- package/src/data-structures/graph/map-graph.ts +6 -1
- package/src/data-structures/graph/undirected-graph.ts +3 -6
- package/src/data-structures/hash/hash-map.ts +18 -16
- package/src/data-structures/heap/heap.ts +7 -10
- package/src/data-structures/heap/max-heap.ts +2 -1
- package/src/data-structures/heap/min-heap.ts +2 -1
- package/src/data-structures/linked-list/singly-linked-list.ts +2 -3
- package/src/data-structures/matrix/index.ts +0 -2
- package/src/data-structures/matrix/matrix.ts +442 -13
- package/src/data-structures/priority-queue/min-priority-queue.ts +11 -10
- package/src/data-structures/queue/deque.ts +18 -39
- package/src/data-structures/queue/queue.ts +1 -1
- package/src/interfaces/binary-tree.ts +9 -4
- package/src/types/common.ts +5 -5
- package/src/types/data-structures/base/base.ts +14 -3
- package/src/types/data-structures/base/index.ts +1 -1
- package/src/types/data-structures/graph/abstract-graph.ts +4 -2
- package/src/types/data-structures/hash/hash-map.ts +3 -3
- package/src/types/data-structures/heap/heap.ts +2 -2
- package/src/types/data-structures/priority-queue/priority-queue.ts +2 -2
- package/src/utils/utils.ts +7 -1
- package/test/integration/avl-tree.test.ts +18 -1
- package/test/integration/bst.test.ts +2 -2
- package/test/performance/data-structures/binary-tree/avl-tree.test.ts +4 -12
- package/test/performance/data-structures/binary-tree/binary-tree-overall.test.ts +37 -0
- package/test/performance/data-structures/binary-tree/binary-tree.test.ts +6 -16
- package/test/performance/data-structures/binary-tree/bst.test.ts +5 -13
- package/test/performance/data-structures/binary-tree/rb-tree.test.ts +6 -16
- package/test/performance/data-structures/comparison/comparison.test.ts +19 -47
- package/test/performance/data-structures/graph/directed-graph.test.ts +3 -14
- package/test/performance/data-structures/hash/hash-map.test.ts +14 -38
- package/test/performance/data-structures/heap/heap.test.ts +5 -18
- package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +0 -2
- package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +0 -2
- package/test/performance/data-structures/priority-queue/max-priority-queue.test.ts +2 -4
- package/test/performance/data-structures/priority-queue/priority-queue.test.ts +4 -14
- package/test/performance/data-structures/queue/deque.test.ts +6 -7
- package/test/performance/data-structures/queue/queue.test.ts +13 -29
- package/test/performance/data-structures/stack/stack.test.ts +6 -18
- package/test/performance/data-structures/trie/trie.test.ts +2 -6
- package/test/performance/reportor.ts +14 -15
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +14 -3
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +65 -29
- package/test/unit/data-structures/binary-tree/bst.test.ts +69 -27
- package/test/unit/data-structures/binary-tree/overall.test.ts +16 -18
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +17 -6
- package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +37 -21
- package/test/unit/data-structures/graph/directed-graph.test.ts +104 -45
- package/test/unit/data-structures/graph/undirected-graph.test.ts +57 -40
- package/test/unit/data-structures/hash/hash-map.test.ts +48 -28
- package/test/unit/data-structures/hash/hash-table.test.ts +0 -4
- package/test/unit/data-structures/heap/heap.test.ts +0 -1
- package/test/unit/data-structures/heap/min-heap.test.ts +6 -5
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +10 -11
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +3 -4
- package/test/unit/data-structures/matrix/matrix.test.ts +345 -52
- package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +1 -1
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +0 -1
- package/test/unit/data-structures/queue/deque.test.ts +0 -6
- package/test/unit/data-structures/queue/queue.test.ts +1 -1
- package/test/unit/data-structures/stack/stack.test.ts +3 -4
- package/test/unit/unrestricted-interconversion.test.ts +50 -44
- package/test/utils/performanc.ts +1 -1
- package/typedoc.json +30 -0
- package/dist/cjs/data-structures/matrix/matrix2d.d.ts +0 -107
- package/dist/cjs/data-structures/matrix/matrix2d.js +0 -200
- package/dist/cjs/data-structures/matrix/matrix2d.js.map +0 -1
- package/dist/cjs/data-structures/matrix/vector2d.d.ts +0 -200
- package/dist/cjs/data-structures/matrix/vector2d.js +0 -291
- package/dist/cjs/data-structures/matrix/vector2d.js.map +0 -1
- package/dist/mjs/data-structures/matrix/matrix2d.d.ts +0 -107
- package/dist/mjs/data-structures/matrix/matrix2d.js +0 -196
- package/dist/mjs/data-structures/matrix/vector2d.d.ts +0 -200
- package/dist/mjs/data-structures/matrix/vector2d.js +0 -289
- package/src/data-structures/matrix/matrix2d.ts +0 -211
- package/src/data-structures/matrix/vector2d.ts +0 -315
- package/test/performance/data-structures/binary-tree/overall.test.ts +0 -0
- package/test/performance/data-structures/matrix/matrix2d.test.ts +0 -0
- package/test/performance/data-structures/matrix/vector2d.test.ts +0 -0
- package/test/unit/data-structures/matrix/matrix2d.test.ts +0 -345
- package/test/unit/data-structures/matrix/vector2d.test.ts +0 -171
|
@@ -176,53 +176,52 @@ describe('UndirectedGraph', () => {
|
|
|
176
176
|
|
|
177
177
|
test('Removing an edge of a UndirectedGraph should not delete additional edges', () => {
|
|
178
178
|
const dg = new UndirectedGraph();
|
|
179
|
-
dg.addVertex('hello')
|
|
180
|
-
dg.addVertex('hi')
|
|
181
|
-
dg.addVertex('hey')
|
|
182
|
-
dg.addEdge('hello', 'hi')
|
|
183
|
-
dg.addEdge('hello', 'hey')
|
|
184
|
-
expect(dg.getEdge('hello', 'hi')?.vertexMap[0]).toBe('hello')
|
|
185
|
-
expect(dg.getEdge('hello', 'hi')?.vertexMap[1]).toBe('hi')
|
|
186
|
-
expect(dg.getEdge('hello', 'hey')?.vertexMap[0]).toBe('hello')
|
|
187
|
-
expect(dg.getEdge('hello', 'hey')?.vertexMap[1]).toBe('hey')
|
|
188
|
-
dg.deleteEdge('hello', 'hi')
|
|
189
|
-
expect(dg.getEdge('hello', 'hi')).toBe(undefined)
|
|
190
|
-
expect(dg.getEdge('hello', 'hey')).toBeInstanceOf(UndirectedEdge)
|
|
179
|
+
dg.addVertex('hello');
|
|
180
|
+
dg.addVertex('hi');
|
|
181
|
+
dg.addVertex('hey');
|
|
182
|
+
dg.addEdge('hello', 'hi');
|
|
183
|
+
dg.addEdge('hello', 'hey');
|
|
184
|
+
expect(dg.getEdge('hello', 'hi')?.vertexMap[0]).toBe('hello');
|
|
185
|
+
expect(dg.getEdge('hello', 'hi')?.vertexMap[1]).toBe('hi');
|
|
186
|
+
expect(dg.getEdge('hello', 'hey')?.vertexMap[0]).toBe('hello');
|
|
187
|
+
expect(dg.getEdge('hello', 'hey')?.vertexMap[1]).toBe('hey');
|
|
188
|
+
dg.deleteEdge('hello', 'hi');
|
|
189
|
+
expect(dg.getEdge('hello', 'hi')).toBe(undefined);
|
|
190
|
+
expect(dg.getEdge('hello', 'hey')).toBeInstanceOf(UndirectedEdge);
|
|
191
191
|
});
|
|
192
192
|
|
|
193
|
-
|
|
194
193
|
test('Removing a vertex of a DirectedGraph should delete additional edges', () => {
|
|
195
194
|
const graph = new UndirectedGraph();
|
|
196
195
|
|
|
197
|
-
graph.addVertex(
|
|
198
|
-
graph.addVertex(
|
|
196
|
+
graph.addVertex('Hello');
|
|
197
|
+
graph.addVertex('Hi');
|
|
199
198
|
|
|
200
|
-
graph.addEdge(
|
|
201
|
-
graph.deleteVertex(
|
|
199
|
+
graph.addEdge('Hello', 'Hi');
|
|
200
|
+
graph.deleteVertex('Hello');
|
|
202
201
|
|
|
203
|
-
expect(graph.edgesOf(
|
|
204
|
-
})
|
|
202
|
+
expect(graph.edgesOf('Hi')).toEqual([]);
|
|
203
|
+
});
|
|
205
204
|
|
|
206
205
|
test('Removing a vertex from a UndirectedGraph should remove its edges', () => {
|
|
207
206
|
const dg = new UndirectedGraph();
|
|
208
|
-
dg.addVertex('hello')
|
|
209
|
-
dg.addVertex('world')
|
|
210
|
-
dg.addVertex('earth')
|
|
207
|
+
dg.addVertex('hello');
|
|
208
|
+
dg.addVertex('world');
|
|
209
|
+
dg.addVertex('earth');
|
|
211
210
|
|
|
212
|
-
dg.addEdge('hello', 'world')
|
|
213
|
-
dg.addEdge('hello', 'earth')
|
|
214
|
-
dg.addEdge('world', 'earth')
|
|
211
|
+
dg.addEdge('hello', 'world');
|
|
212
|
+
dg.addEdge('hello', 'earth');
|
|
213
|
+
dg.addEdge('world', 'earth');
|
|
215
214
|
|
|
216
215
|
expect(dg.getEdge('hello', 'world')?.vertexMap[0]).toBe('hello');
|
|
217
|
-
expect(dg.edgeSet().length).toBe(3)
|
|
218
|
-
expect(dg.edgeSet()[0].vertexMap).toEqual(['hello', 'world'])
|
|
216
|
+
expect(dg.edgeSet().length).toBe(3);
|
|
217
|
+
expect(dg.edgeSet()[0].vertexMap).toEqual(['hello', 'world']);
|
|
219
218
|
|
|
220
|
-
dg.deleteVertex('hello')
|
|
221
|
-
expect(dg.edgeSet().length).toBe(1)
|
|
222
|
-
expect(dg.edgeSet()?.[0].vertexMap[0]).toBe('world')
|
|
219
|
+
dg.deleteVertex('hello');
|
|
220
|
+
expect(dg.edgeSet().length).toBe(1);
|
|
221
|
+
expect(dg.edgeSet()?.[0].vertexMap[0]).toBe('world');
|
|
223
222
|
|
|
224
223
|
expect(dg.getEdge('hello', 'world')).toBe(undefined);
|
|
225
|
-
})
|
|
224
|
+
});
|
|
226
225
|
});
|
|
227
226
|
|
|
228
227
|
describe('cycles, strongly connected components, bridges, articular points in UndirectedGraph', () => {
|
|
@@ -258,8 +257,7 @@ describe('cycles, strongly connected components, bridges, articular points in Un
|
|
|
258
257
|
expect(lowMap.size).toBe(8);
|
|
259
258
|
});
|
|
260
259
|
|
|
261
|
-
it(
|
|
262
|
-
|
|
260
|
+
it('Should return Infinity if dest is not found', () => {
|
|
263
261
|
const graph = new UndirectedGraph<string>();
|
|
264
262
|
|
|
265
263
|
for (let i = 0; i < 3; ++i) {
|
|
@@ -291,8 +289,12 @@ describe('UndirectedGraph getCycles', () => {
|
|
|
291
289
|
graph.addEdge('E', 'B');
|
|
292
290
|
const cycles = graph.getCycles();
|
|
293
291
|
expect(cycles.length).toBe(3);
|
|
294
|
-
expect(cycles).toEqual([
|
|
295
|
-
|
|
292
|
+
expect(cycles).toEqual([
|
|
293
|
+
['A', 'B', 'D', 'C'],
|
|
294
|
+
['A', 'B', 'E', 'D', 'C'],
|
|
295
|
+
['B', 'D', 'E']
|
|
296
|
+
]);
|
|
297
|
+
});
|
|
296
298
|
|
|
297
299
|
test('should simple cycles graph getCycles return correct result', () => {
|
|
298
300
|
const graph = new UndirectedGraph();
|
|
@@ -308,8 +310,12 @@ describe('UndirectedGraph getCycles', () => {
|
|
|
308
310
|
graph.addEdge('A', 'D');
|
|
309
311
|
graph.addEdge('D', 'C');
|
|
310
312
|
const cycles = graph.getCycles();
|
|
311
|
-
expect(cycles.length).toBe(3)
|
|
312
|
-
expect(cycles).toEqual([
|
|
313
|
+
expect(cycles.length).toBe(3);
|
|
314
|
+
expect(cycles).toEqual([
|
|
315
|
+
['A', 'B', 'C'],
|
|
316
|
+
['A', 'B', 'C', 'D'],
|
|
317
|
+
['A', 'C', 'D']
|
|
318
|
+
]);
|
|
313
319
|
});
|
|
314
320
|
|
|
315
321
|
test('should 3 cycles graph getCycles return correct result', () => {
|
|
@@ -335,7 +341,18 @@ describe('UndirectedGraph getCycles', () => {
|
|
|
335
341
|
graph.addEdge('G', 'A');
|
|
336
342
|
|
|
337
343
|
const cycles = graph.getCycles();
|
|
338
|
-
expect(cycles.length).toBe(10)
|
|
339
|
-
expect(cycles).toEqual([
|
|
344
|
+
expect(cycles.length).toBe(10);
|
|
345
|
+
expect(cycles).toEqual([
|
|
346
|
+
['A', 'B', 'D', 'C'],
|
|
347
|
+
['A', 'B', 'D', 'C', 'G'],
|
|
348
|
+
['A', 'B', 'E', 'D', 'C'],
|
|
349
|
+
['A', 'B', 'E', 'D', 'C', 'G'],
|
|
350
|
+
['A', 'B', 'F', 'E', 'D', 'C'],
|
|
351
|
+
['A', 'B', 'F', 'E', 'D', 'C', 'G'],
|
|
352
|
+
['A', 'C', 'G'],
|
|
353
|
+
['B', 'D', 'E'],
|
|
354
|
+
['B', 'D', 'E', 'F'],
|
|
355
|
+
['B', 'E', 'F']
|
|
356
|
+
]);
|
|
340
357
|
});
|
|
341
|
-
})
|
|
358
|
+
});
|
|
@@ -54,7 +54,6 @@ describe('HashMap Test1', () => {
|
|
|
54
54
|
hashMap.set('one', 1);
|
|
55
55
|
hashMap.set('two', 2);
|
|
56
56
|
hashMap.set('three', 3);
|
|
57
|
-
|
|
58
57
|
});
|
|
59
58
|
|
|
60
59
|
it('should resize the table when load factor is exceeded', () => {
|
|
@@ -181,7 +180,6 @@ describe('HashMap Test2', () => {
|
|
|
181
180
|
}
|
|
182
181
|
compareHashMaps(hashMap, stdMap);
|
|
183
182
|
});
|
|
184
|
-
|
|
185
183
|
});
|
|
186
184
|
|
|
187
185
|
describe('HashMap for coordinate object keys', () => {
|
|
@@ -207,30 +205,39 @@ describe('HashMap for coordinate object keys', () => {
|
|
|
207
205
|
|
|
208
206
|
test('delete elements in hash map', () => {
|
|
209
207
|
for (let i = 0; i < 1000; i++) {
|
|
210
|
-
if (i === 500) expect(hashMap.size).toBe(500)
|
|
208
|
+
if (i === 500) expect(hashMap.size).toBe(500);
|
|
211
209
|
const codObj = codObjs[i];
|
|
212
210
|
if (codObj) hashMap.delete(codObj);
|
|
213
211
|
}
|
|
214
212
|
expect(hashMap.size).toBe(0);
|
|
215
213
|
});
|
|
216
|
-
|
|
217
214
|
});
|
|
218
215
|
|
|
219
216
|
describe('HashMap setMany, keys, values', () => {
|
|
220
217
|
const hm: HashMap<number, number> = new HashMap<number, number>();
|
|
221
218
|
|
|
222
219
|
beforeEach(() => {
|
|
223
|
-
hm.clear()
|
|
224
|
-
hm.setMany([
|
|
225
|
-
|
|
226
|
-
|
|
220
|
+
hm.clear();
|
|
221
|
+
hm.setMany([
|
|
222
|
+
[2, 2],
|
|
223
|
+
[3, 3],
|
|
224
|
+
[4, 4],
|
|
225
|
+
[5, 5]
|
|
226
|
+
]);
|
|
227
|
+
hm.setMany([
|
|
228
|
+
[2, 2],
|
|
229
|
+
[3, 3],
|
|
230
|
+
[4, 4],
|
|
231
|
+
[6, 6]
|
|
232
|
+
]);
|
|
233
|
+
});
|
|
227
234
|
|
|
228
235
|
test('keys', () => {
|
|
229
|
-
expect([...hm.keys()]).toEqual([2, 3, 4, 5, 6])
|
|
236
|
+
expect([...hm.keys()]).toEqual([2, 3, 4, 5, 6]);
|
|
230
237
|
});
|
|
231
238
|
|
|
232
239
|
test('values', () => {
|
|
233
|
-
expect([...hm.values()]).toEqual([2, 3, 4, 5, 6])
|
|
240
|
+
expect([...hm.values()]).toEqual([2, 3, 4, 5, 6]);
|
|
234
241
|
});
|
|
235
242
|
});
|
|
236
243
|
|
|
@@ -245,7 +252,7 @@ describe('HashMap HOF', () => {
|
|
|
245
252
|
});
|
|
246
253
|
|
|
247
254
|
test('every() returns true if all elements match the condition', () => {
|
|
248
|
-
expect(hashMap.every(
|
|
255
|
+
expect(hashMap.every(value => typeof value === 'string')).toBe(true);
|
|
249
256
|
});
|
|
250
257
|
|
|
251
258
|
test('some() returns true if any element matches the condition', () => {
|
|
@@ -259,7 +266,7 @@ describe('HashMap HOF', () => {
|
|
|
259
266
|
});
|
|
260
267
|
|
|
261
268
|
test('map() should transform each element', () => {
|
|
262
|
-
const newHashMap = hashMap.map(
|
|
269
|
+
const newHashMap = hashMap.map(value => value.toUpperCase());
|
|
263
270
|
expect(newHashMap.get('key1')).toBe('VALUE1');
|
|
264
271
|
});
|
|
265
272
|
|
|
@@ -274,7 +281,6 @@ describe('HashMap HOF', () => {
|
|
|
274
281
|
});
|
|
275
282
|
});
|
|
276
283
|
|
|
277
|
-
|
|
278
284
|
describe('LinkedHashMap Test1', () => {
|
|
279
285
|
let hashMap: LinkedHashMap<string, number>;
|
|
280
286
|
|
|
@@ -368,7 +374,6 @@ describe('LinkedHashMap Test1', () => {
|
|
|
368
374
|
// expect(hashMap.table[0].length).toBe(2);
|
|
369
375
|
});
|
|
370
376
|
|
|
371
|
-
|
|
372
377
|
// it('should handle number keys correctly', () => {
|
|
373
378
|
// const hm = new LinkedHashMap();
|
|
374
379
|
// hm.set(999, { a: '999Value' });
|
|
@@ -529,50 +534,65 @@ describe('LinkedHashMap for coordinate object keys', () => {
|
|
|
529
534
|
|
|
530
535
|
test('delete elements in hash map', () => {
|
|
531
536
|
for (let i = 0; i < 1000; i++) {
|
|
532
|
-
if (i === 500) expect(hashMap.size).toBe(500)
|
|
537
|
+
if (i === 500) expect(hashMap.size).toBe(500);
|
|
533
538
|
const codObj = codObjs[i];
|
|
534
539
|
if (codObj) hashMap.delete(codObj);
|
|
535
540
|
}
|
|
536
541
|
expect(hashMap.size).toBe(0);
|
|
537
542
|
});
|
|
538
|
-
|
|
539
543
|
});
|
|
540
544
|
|
|
541
545
|
describe('LinkedHashMap setMany, keys, values', () => {
|
|
542
546
|
const hm: LinkedHashMap<number, number> = new LinkedHashMap<number, number>();
|
|
543
547
|
|
|
544
548
|
beforeEach(() => {
|
|
545
|
-
hm.clear()
|
|
546
|
-
hm.setMany([
|
|
547
|
-
|
|
548
|
-
|
|
549
|
+
hm.clear();
|
|
550
|
+
hm.setMany([
|
|
551
|
+
[2, 2],
|
|
552
|
+
[3, 3],
|
|
553
|
+
[4, 4],
|
|
554
|
+
[5, 5]
|
|
555
|
+
]);
|
|
556
|
+
hm.setMany([
|
|
557
|
+
[2, 2],
|
|
558
|
+
[3, 3],
|
|
559
|
+
[4, 4],
|
|
560
|
+
[6, 6]
|
|
561
|
+
]);
|
|
562
|
+
});
|
|
549
563
|
|
|
550
564
|
test('keys', () => {
|
|
551
|
-
expect([...hm.keys()]).toEqual([2, 3, 4, 5, 6])
|
|
565
|
+
expect([...hm.keys()]).toEqual([2, 3, 4, 5, 6]);
|
|
552
566
|
});
|
|
553
567
|
|
|
554
568
|
test('values', () => {
|
|
555
|
-
expect([...hm.values()]).toEqual([2, 3, 4, 5, 6])
|
|
569
|
+
expect([...hm.values()]).toEqual([2, 3, 4, 5, 6]);
|
|
556
570
|
});
|
|
557
571
|
|
|
558
572
|
test('entries', () => {
|
|
559
|
-
expect([...hm.entries()]).toEqual([
|
|
573
|
+
expect([...hm.entries()]).toEqual([
|
|
574
|
+
[2, 2],
|
|
575
|
+
[3, 3],
|
|
576
|
+
[4, 4],
|
|
577
|
+
[5, 5],
|
|
578
|
+
[6, 6]
|
|
579
|
+
]);
|
|
560
580
|
});
|
|
561
581
|
|
|
562
582
|
test('every', () => {
|
|
563
|
-
expect(hm.every(value => value > 4)).toBe(false)
|
|
583
|
+
expect(hm.every(value => value > 4)).toBe(false);
|
|
564
584
|
});
|
|
565
585
|
|
|
566
586
|
test('some', () => {
|
|
567
|
-
expect(hm.some(value => value > 6)).toBe(false)
|
|
587
|
+
expect(hm.some(value => value > 6)).toBe(false);
|
|
568
588
|
});
|
|
569
589
|
|
|
570
590
|
test('hasValue', () => {
|
|
571
|
-
expect(hm.hasValue(3)).toBe(true)
|
|
572
|
-
expect(hm.hasValue(7)).toBe(false)
|
|
591
|
+
expect(hm.hasValue(3)).toBe(true);
|
|
592
|
+
expect(hm.hasValue(7)).toBe(false);
|
|
573
593
|
});
|
|
574
594
|
|
|
575
595
|
test('print', () => {
|
|
576
596
|
hm.print();
|
|
577
597
|
});
|
|
578
|
-
});
|
|
598
|
+
});
|
|
@@ -185,7 +185,6 @@ describe('HashTable performance', function () {
|
|
|
185
185
|
});
|
|
186
186
|
});
|
|
187
187
|
|
|
188
|
-
|
|
189
188
|
describe('HashTable methods', () => {
|
|
190
189
|
let hashTable: HashTable<string, string>;
|
|
191
190
|
|
|
@@ -215,7 +214,6 @@ describe('HashTable methods', () => {
|
|
|
215
214
|
// }
|
|
216
215
|
// });
|
|
217
216
|
|
|
218
|
-
|
|
219
217
|
test('filter should return a new HashTable with elements that satisfy the condition', () => {
|
|
220
218
|
const filtered = hashTable.filter(([key]) => key.endsWith('1') || key.endsWith('3'));
|
|
221
219
|
|
|
@@ -237,6 +235,4 @@ describe('HashTable methods', () => {
|
|
|
237
235
|
|
|
238
236
|
expect(result).toBe('-value5-value7-value3-value4-value6-value0-value2-value8-value1-value9');
|
|
239
237
|
});
|
|
240
|
-
|
|
241
238
|
});
|
|
242
|
-
|
|
@@ -50,17 +50,15 @@ describe('MinHeap', () => {
|
|
|
50
50
|
expect(minHeap.isEmpty()).toBe(true);
|
|
51
51
|
});
|
|
52
52
|
|
|
53
|
-
|
|
54
53
|
const n = 100000;
|
|
55
54
|
|
|
56
55
|
it('should push & dfs', () => {
|
|
57
56
|
for (let i = 0; i < n; i++) {
|
|
58
57
|
minHeap.add(i);
|
|
59
58
|
}
|
|
60
|
-
expect(minHeap.dfs()[0]).toBe(0)
|
|
61
|
-
expect(minHeap.dfs()[999]).toBe(4126)
|
|
59
|
+
expect(minHeap.dfs()[0]).toBe(0);
|
|
60
|
+
expect(minHeap.dfs()[999]).toBe(4126);
|
|
62
61
|
});
|
|
63
|
-
|
|
64
62
|
});
|
|
65
63
|
|
|
66
64
|
describe('Heap iterative methods', () => {
|
|
@@ -89,7 +87,10 @@ describe('Heap iterative methods', () => {
|
|
|
89
87
|
});
|
|
90
88
|
|
|
91
89
|
test('map method correctly maps elements', () => {
|
|
92
|
-
const result = heap.map(
|
|
90
|
+
const result = heap.map(
|
|
91
|
+
x => x / 10,
|
|
92
|
+
(a: number, b: number) => a - b
|
|
93
|
+
);
|
|
93
94
|
expect([...result]).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
|
94
95
|
});
|
|
95
96
|
|
|
@@ -398,16 +398,15 @@ describe('DoublyLinkedList Operation Test', () => {
|
|
|
398
398
|
});
|
|
399
399
|
});
|
|
400
400
|
|
|
401
|
-
|
|
402
401
|
describe('iterable methods', () => {
|
|
403
402
|
it('should forEach, some, every, filter, map, reduce of the deque', () => {
|
|
404
|
-
const dl = new DoublyLinkedList<number>()
|
|
403
|
+
const dl = new DoublyLinkedList<number>();
|
|
405
404
|
dl.push(1);
|
|
406
405
|
dl.push(2);
|
|
407
406
|
dl.push(3);
|
|
408
407
|
|
|
409
408
|
const mockCallback = jest.fn();
|
|
410
|
-
dl.forEach(
|
|
409
|
+
dl.forEach(element => {
|
|
411
410
|
mockCallback(element);
|
|
412
411
|
});
|
|
413
412
|
|
|
@@ -426,7 +425,7 @@ describe('iterable methods', () => {
|
|
|
426
425
|
});
|
|
427
426
|
|
|
428
427
|
test('values', () => {
|
|
429
|
-
const dl = new DoublyLinkedList<number>()
|
|
428
|
+
const dl = new DoublyLinkedList<number>();
|
|
430
429
|
dl.push(1);
|
|
431
430
|
dl.push(2);
|
|
432
431
|
dl.push(3);
|
|
@@ -435,11 +434,11 @@ describe('iterable methods', () => {
|
|
|
435
434
|
dl.shift();
|
|
436
435
|
dl.pop();
|
|
437
436
|
dl.unshift(3);
|
|
438
|
-
expect([...dl.values()]).toEqual([3, 1])
|
|
439
|
-
})
|
|
437
|
+
expect([...dl.values()]).toEqual([3, 1]);
|
|
438
|
+
});
|
|
440
439
|
|
|
441
440
|
test('some', () => {
|
|
442
|
-
const dl = new DoublyLinkedList<number>()
|
|
441
|
+
const dl = new DoublyLinkedList<number>();
|
|
443
442
|
dl.push(1);
|
|
444
443
|
dl.push(2);
|
|
445
444
|
dl.push(3);
|
|
@@ -448,7 +447,7 @@ describe('iterable methods', () => {
|
|
|
448
447
|
dl.shift();
|
|
449
448
|
dl.pop();
|
|
450
449
|
dl.unshift(3);
|
|
451
|
-
expect(dl.some(value => value > 1)).toBe(true)
|
|
452
|
-
expect(dl.some(value => value > 100)).toBe(false)
|
|
453
|
-
})
|
|
454
|
-
});
|
|
450
|
+
expect(dl.some(value => value > 1)).toBe(true);
|
|
451
|
+
expect(dl.some(value => value > 100)).toBe(false);
|
|
452
|
+
});
|
|
453
|
+
});
|
|
@@ -472,13 +472,12 @@ describe('SinglyLinkedList', () => {
|
|
|
472
472
|
});
|
|
473
473
|
});
|
|
474
474
|
|
|
475
|
-
|
|
476
475
|
describe('iterable methods', () => {
|
|
477
476
|
it('should forEach, some, every, filter, map, reduce of the deque', () => {
|
|
478
|
-
const sl = new SinglyLinkedList<number>([1, 2, 3])
|
|
477
|
+
const sl = new SinglyLinkedList<number>([1, 2, 3]);
|
|
479
478
|
|
|
480
479
|
const mockCallback = jest.fn();
|
|
481
|
-
sl.forEach(
|
|
480
|
+
sl.forEach(element => {
|
|
482
481
|
mockCallback(element);
|
|
483
482
|
});
|
|
484
483
|
|
|
@@ -495,4 +494,4 @@ describe('iterable methods', () => {
|
|
|
495
494
|
expect([...sl.map(element => element * 2)]).toEqual([2, 4, 6]);
|
|
496
495
|
expect(sl.reduce((accumulator, element) => accumulator + element, 0)).toEqual(6);
|
|
497
496
|
});
|
|
498
|
-
});
|
|
497
|
+
});
|