diff --git a/README.md b/README.md
index 1e2291a..04b3ae1 100644
--- a/README.md
+++ b/README.md
@@ -782,52 +782,52 @@ avl2.print();
[//]: # (No deletion!!! Start of Replace Section)
avl-tree
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
10,000 add randomly | 33.09 | 30.22 | 4.32e-4 |
10,000 add & delete randomly | 74.12 | 13.49 | 0.00 |
10,000 addMany | 41.71 | 23.97 | 0.00 |
10,000 get | 28.37 | 35.25 | 2.37e-4 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
10,000 add randomly | 30.05 | 33.28 | 6.97e-4 |
10,000 add & delete randomly | 72.61 | 13.77 | 0.00 |
10,000 addMany | 35.18 | 28.43 | 9.64e-4 |
10,000 get | 30.02 | 33.31 | 5.36e-4 |
binary-tree
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000 add randomly | 14.50 | 68.96 | 1.33e-4 |
1,000 add & delete randomly | 16.20 | 61.72 | 2.03e-4 |
1,000 addMany | 10.51 | 95.12 | 8.76e-5 |
1,000 get | 18.28 | 54.69 | 1.82e-4 |
1,000 dfs | 157.23 | 6.36 | 7.06e-4 |
1,000 bfs | 58.06 | 17.22 | 0.01 |
1,000 morris | 256.36 | 3.90 | 0.00 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000 add randomly | 14.72 | 67.92 | 1.85e-4 |
1,000 add & delete randomly | 18.55 | 53.90 | 3.16e-4 |
1,000 addMany | 13.40 | 74.62 | 0.00 |
1,000 get | 18.70 | 53.47 | 3.85e-4 |
1,000 has | 19.28 | 51.87 | 0.00 |
1,000 dfs | 158.14 | 6.32 | 0.01 |
1,000 bfs | 56.98 | 17.55 | 8.96e-4 |
1,000 morris | 260.83 | 3.83 | 0.00 |
bst
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
10,000 add randomly | 30.48 | 32.81 | 4.13e-4 |
10,000 add & delete randomly | 71.84 | 13.92 | 0.00 |
10,000 addMany | 29.54 | 33.85 | 5.25e-4 |
10,000 get | 30.53 | 32.75 | 0.01 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
10,000 add randomly | 26.61 | 37.58 | 6.20e-4 |
10,000 add & delete randomly | 68.64 | 14.57 | 0.00 |
10,000 addMany | 25.65 | 38.99 | 8.34e-5 |
10,000 get | 33.11 | 30.21 | 0.02 |
rb-tree
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
100,000 add | 90.89 | 11.00 | 0.00 |
100,000 CPT add | 50.65 | 19.74 | 0.00 |
100,000 add & delete randomly | 230.08 | 4.35 | 0.02 |
100,000 getNode | 38.97 | 25.66 | 5.82e-4 |
100,000 add & iterator | 118.32 | 8.45 | 0.01 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
100,000 add | 85.61 | 11.68 | 0.00 |
100,000 add & delete randomly | 214.04 | 4.67 | 0.01 |
100,000 getNode | 154.49 | 6.47 | 4.10e-4 |
100,000 add & iterator | 115.20 | 8.68 | 0.00 |
comparison
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
SRC PQ 10,000 add | 0.14 | 6939.33 | 1.74e-6 |
CJS PQ 10,000 add | 0.15 | 6881.64 | 1.91e-6 |
MJS PQ 10,000 add | 0.57 | 1745.92 | 1.60e-5 |
CPT PQ 10,000 add | 0.57 | 1744.71 | 1.01e-5 |
SRC PQ 10,000 add & pop | 3.51 | 284.93 | 6.79e-4 |
CJS PQ 10,000 add & pop | 3.42 | 292.55 | 4.04e-5 |
MJS PQ 10,000 add & pop | 3.41 | 293.38 | 5.11e-5 |
CPT PQ 10,000 add & pop | 2.09 | 478.76 | 2.28e-5 |
CPT OM 100,000 add | 43.22 | 23.14 | 0.00 |
CPT HM 10,000 set | 0.58 | 1721.25 | 1.85e-5 |
CPT HM 10,000 set & get | 0.68 | 1477.31 | 1.26e-5 |
CPT LL 1,000,000 unshift | 81.38 | 12.29 | 0.02 |
CPT PQ 10,000 add & pop | 2.10 | 476.50 | 1.60e-4 |
CPT DQ 1,000,000 push | 22.51 | 44.42 | 0.00 |
CPT Q 1,000,000 push | 47.85 | 20.90 | 0.01 |
CPT ST 1,000,000 push | 42.54 | 23.51 | 0.01 |
CPT ST 1,000,000 push & pop | 50.08 | 19.97 | 0.00 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
SRC PQ 10,000 add | 0.16 | 6447.35 | 3.77e-5 |
CJS PQ 10,000 add | 0.15 | 6865.39 | 5.18e-6 |
MJS PQ 10,000 add | 0.58 | 1737.03 | 1.95e-5 |
SRC PQ 10,000 add & pop | 3.44 | 290.59 | 6.14e-5 |
CJS PQ 10,000 add & pop | 3.43 | 291.48 | 5.86e-5 |
MJS PQ 10,000 add & pop | 4.29 | 233.18 | 1.71e-4 |
directed-graph
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000 addVertex | 0.11 | 9501.34 | 6.10e-6 |
1,000 addEdge | 6.35 | 157.55 | 6.69e-4 |
1,000 getVertex | 0.05 | 2.14e+4 | 2.50e-6 |
1,000 getEdge | 25.00 | 39.99 | 0.01 |
tarjan | 219.46 | 4.56 | 0.01 |
tarjan all | 218.15 | 4.58 | 0.00 |
topologicalSort | 176.83 | 5.66 | 0.00 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000 addVertex | 0.10 | 9639.13 | 3.31e-6 |
1,000 addEdge | 6.21 | 161.12 | 2.90e-4 |
1,000 getVertex | 0.05 | 2.13e+4 | 1.42e-6 |
1,000 getEdge | 27.34 | 36.57 | 0.01 |
tarjan | 228.62 | 4.37 | 0.01 |
tarjan all | 241.47 | 4.14 | 0.05 |
topologicalSort | 193.23 | 5.18 | 0.02 |
hash-map
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000,000 set | 254.46 | 3.93 | 0.04 |
1,000,000 CPT set | 251.21 | 3.98 | 0.03 |
1,000,000 Map set | 211.27 | 4.73 | 0.01 |
1,000,000 Set add | 175.15 | 5.71 | 0.02 |
1,000,000 set & get | 370.54 | 2.70 | 0.11 |
1,000,000 CPT set & get | 283.34 | 3.53 | 0.07 |
1,000,000 Map set & get | 287.09 | 3.48 | 0.04 |
1,000,000 Set add & has | 190.50 | 5.25 | 0.01 |
1,000,000 ObjKey set & get | 880.47 | 1.14 | 0.10 |
1,000,000 Map ObjKey set & get | 334.47 | 2.99 | 0.05 |
1,000,000 Set ObjKey add & has | 310.12 | 3.22 | 0.06 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000,000 set | 116.85 | 8.56 | 0.04 |
1,000,000 Map set | 216.07 | 4.63 | 0.02 |
1,000,000 Set add | 173.91 | 5.75 | 0.01 |
1,000,000 set & get | 124.87 | 8.01 | 0.04 |
1,000,000 Map set & get | 323.10 | 3.10 | 0.04 |
1,000,000 Set add & has | 180.32 | 5.55 | 0.02 |
1,000,000 ObjKey set & get | 335.51 | 2.98 | 0.07 |
1,000,000 Map ObjKey set & get | 310.64 | 3.22 | 0.06 |
1,000,000 Set ObjKey add & has | 271.15 | 3.69 | 0.05 |
heap
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
100,000 add & pop | 80.13 | 12.48 | 0.00 |
100,000 add & dfs | 35.08 | 28.50 | 0.00 |
10,000 fib add & pop | 367.84 | 2.72 | 0.01 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
100,000 add & pop | 79.43 | 12.59 | 0.00 |
100,000 add & dfs | 34.78 | 28.75 | 0.00 |
10,000 fib add & pop | 356.18 | 2.81 | 0.00 |
doubly-linked-list
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000,000 push | 237.28 | 4.21 | 0.07 |
1,000,000 CPT push | 75.66 | 13.22 | 0.03 |
1,000,000 unshift | 226.38 | 4.42 | 0.05 |
1,000,000 CPT unshift | 93.34 | 10.71 | 0.07 |
1,000,000 unshift & shift | 188.34 | 5.31 | 0.05 |
1,000,000 insertBefore | 329.60 | 3.03 | 0.05 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000,000 push | 222.75 | 4.49 | 0.05 |
1,000,000 unshift | 235.70 | 4.24 | 0.06 |
1,000,000 unshift & shift | 179.26 | 5.58 | 0.04 |
1,000,000 insertBefore | 340.92 | 2.93 | 0.07 |
singly-linked-list
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
10,000 push & pop | 221.32 | 4.52 | 0.01 |
10,000 insertBefore | 255.52 | 3.91 | 0.01 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
10,000 push & pop | 213.00 | 4.69 | 0.01 |
10,000 insertBefore | 248.65 | 4.02 | 0.01 |
max-priority-queue
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
10,000 refill & poll | 9.07 | 110.24 | 2.71e-4 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
10,000 refill & poll | 9.15 | 109.23 | 4.05e-4 |
priority-queue
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
100,000 add & pop | 101.93 | 9.81 | 7.95e-4 |
100,000 CPT add & pop | 28.54 | 35.04 | 0.00 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
100,000 add & pop | 102.30 | 9.78 | 0.00 |
deque
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000,000 push | 14.43 | 69.29 | 2.36e-4 |
1,000,000 CPT push | 25.08 | 39.87 | 0.01 |
1,000,000 push & pop | 22.87 | 43.72 | 6.05e-4 |
1,000,000 push & shift | 25.28 | 39.55 | 0.01 |
1,000,000 unshift & shift | 21.88 | 45.71 | 2.05e-4 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000,000 push | 14.58 | 68.59 | 1.47e-4 |
1,000,000 push & pop | 23.44 | 42.67 | 1.85e-4 |
1,000,000 push & shift | 24.51 | 40.80 | 1.39e-4 |
1,000,000 unshift & shift | 22.78 | 43.91 | 0.00 |
queue
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000,000 push | 38.49 | 25.98 | 9.08e-4 |
1,000,000 CPT push | 43.93 | 22.76 | 0.01 |
1,000,000 push & shift | 82.85 | 12.07 | 0.00 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000,000 push | 39.36 | 25.41 | 0.01 |
1,000,000 push & shift | 81.81 | 12.22 | 0.00 |
stack
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000,000 push | 40.19 | 24.88 | 0.01 |
1,000,000 CPT push | 39.87 | 25.08 | 0.00 |
1,000,000 push & pop | 41.67 | 24.00 | 0.01 |
1,000,000 CPT push & pop | 46.65 | 21.44 | 0.00 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000,000 push | 38.89 | 25.72 | 0.00 |
1,000,000 push & pop | 44.21 | 22.62 | 0.01 |
trie
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
100,000 push | 43.42 | 23.03 | 7.57e-4 |
100,000 getWords | 93.41 | 10.71 | 0.00 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
100,000 push | 44.22 | 22.61 | 0.00 |
100,000 getWords | 89.31 | 11.20 | 0.00 |
[//]: # (No deletion!!! End of Replace Section)
diff --git a/src/data-structures/hash/hash-map.ts b/src/data-structures/hash/hash-map.ts
index a2a3498..bcf87b9 100644
--- a/src/data-structures/hash/hash-map.ts
+++ b/src/data-structures/hash/hash-map.ts
@@ -304,6 +304,10 @@ export class HashMap {
return accumulator;
}
+ print(): void{
+ console.log([...this.entries()]);
+ }
+
protected _hashFn: (key: K) => string = (key: K) => String(key);
protected _isObjKey(key: any): key is (object | ((...args: any[]) => any)) {
diff --git a/test/unit/data-structures/hash/hash-map.test.ts b/test/unit/data-structures/hash/hash-map.test.ts
index e71a10e..f7135e6 100644
--- a/test/unit/data-structures/hash/hash-map.test.ts
+++ b/test/unit/data-structures/hash/hash-map.test.ts
@@ -245,7 +245,7 @@ describe('HashMap HOF', () => {
});
test('every() returns true if all elements match the condition', () => {
- expect(hashMap.every((value, key) => typeof value === 'string')).toBe(true);
+ expect(hashMap.every((value) => typeof value === 'string')).toBe(true);
});
test('some() returns true if any element matches the condition', () => {
@@ -259,7 +259,7 @@ describe('HashMap HOF', () => {
});
test('map() should transform each element', () => {
- const newHashMap = hashMap.map((value, key) => value.toUpperCase());
+ const newHashMap = hashMap.map((value) => value.toUpperCase());
expect(newHashMap.get('key1')).toBe('VALUE1');
});
@@ -269,7 +269,7 @@ describe('HashMap HOF', () => {
});
test('reduce() should accumulate values', () => {
- const result = hashMap.reduce((acc, value, key) => acc + value, '');
+ const result = hashMap.reduce((acc, value) => acc + value, '');
expect(result).toBe('value1value2value3');
});
});