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 nametime taken (ms)executions per secsample deviation
10,000 add randomly33.0930.224.32e-4
10,000 add & delete randomly74.1213.490.00
10,000 addMany41.7123.970.00
10,000 get28.3735.252.37e-4
+
test nametime taken (ms)executions per secsample deviation
10,000 add randomly30.0533.286.97e-4
10,000 add & delete randomly72.6113.770.00
10,000 addMany35.1828.439.64e-4
10,000 get30.0233.315.36e-4
binary-tree
-
test nametime taken (ms)executions per secsample deviation
1,000 add randomly14.5068.961.33e-4
1,000 add & delete randomly16.2061.722.03e-4
1,000 addMany10.5195.128.76e-5
1,000 get18.2854.691.82e-4
1,000 dfs157.236.367.06e-4
1,000 bfs58.0617.220.01
1,000 morris256.363.900.00
+
test nametime taken (ms)executions per secsample deviation
1,000 add randomly14.7267.921.85e-4
1,000 add & delete randomly18.5553.903.16e-4
1,000 addMany13.4074.620.00
1,000 get18.7053.473.85e-4
1,000 has19.2851.870.00
1,000 dfs158.146.320.01
1,000 bfs56.9817.558.96e-4
1,000 morris260.833.830.00
bst
-
test nametime taken (ms)executions per secsample deviation
10,000 add randomly30.4832.814.13e-4
10,000 add & delete randomly71.8413.920.00
10,000 addMany29.5433.855.25e-4
10,000 get30.5332.750.01
+
test nametime taken (ms)executions per secsample deviation
10,000 add randomly26.6137.586.20e-4
10,000 add & delete randomly68.6414.570.00
10,000 addMany25.6538.998.34e-5
10,000 get33.1130.210.02
rb-tree
-
test nametime taken (ms)executions per secsample deviation
100,000 add90.8911.000.00
100,000 CPT add50.6519.740.00
100,000 add & delete randomly230.084.350.02
100,000 getNode38.9725.665.82e-4
100,000 add & iterator118.328.450.01
+
test nametime taken (ms)executions per secsample deviation
100,000 add85.6111.680.00
100,000 add & delete randomly214.044.670.01
100,000 getNode154.496.474.10e-4
100,000 add & iterator115.208.680.00
comparison
-
test nametime taken (ms)executions per secsample deviation
SRC PQ 10,000 add0.146939.331.74e-6
CJS PQ 10,000 add0.156881.641.91e-6
MJS PQ 10,000 add0.571745.921.60e-5
CPT PQ 10,000 add0.571744.711.01e-5
SRC PQ 10,000 add & pop3.51284.936.79e-4
CJS PQ 10,000 add & pop3.42292.554.04e-5
MJS PQ 10,000 add & pop3.41293.385.11e-5
CPT PQ 10,000 add & pop2.09478.762.28e-5
CPT OM 100,000 add43.2223.140.00
CPT HM 10,000 set0.581721.251.85e-5
CPT HM 10,000 set & get0.681477.311.26e-5
CPT LL 1,000,000 unshift81.3812.290.02
CPT PQ 10,000 add & pop2.10476.501.60e-4
CPT DQ 1,000,000 push22.5144.420.00
CPT Q 1,000,000 push47.8520.900.01
CPT ST 1,000,000 push42.5423.510.01
CPT ST 1,000,000 push & pop50.0819.970.00
+
test nametime taken (ms)executions per secsample deviation
SRC PQ 10,000 add0.166447.353.77e-5
CJS PQ 10,000 add0.156865.395.18e-6
MJS PQ 10,000 add0.581737.031.95e-5
SRC PQ 10,000 add & pop3.44290.596.14e-5
CJS PQ 10,000 add & pop3.43291.485.86e-5
MJS PQ 10,000 add & pop4.29233.181.71e-4
directed-graph
-
test nametime taken (ms)executions per secsample deviation
1,000 addVertex0.119501.346.10e-6
1,000 addEdge6.35157.556.69e-4
1,000 getVertex0.052.14e+42.50e-6
1,000 getEdge25.0039.990.01
tarjan219.464.560.01
tarjan all218.154.580.00
topologicalSort176.835.660.00
+
test nametime taken (ms)executions per secsample deviation
1,000 addVertex0.109639.133.31e-6
1,000 addEdge6.21161.122.90e-4
1,000 getVertex0.052.13e+41.42e-6
1,000 getEdge27.3436.570.01
tarjan228.624.370.01
tarjan all241.474.140.05
topologicalSort193.235.180.02
hash-map
-
test nametime taken (ms)executions per secsample deviation
1,000,000 set254.463.930.04
1,000,000 CPT set251.213.980.03
1,000,000 Map set211.274.730.01
1,000,000 Set add175.155.710.02
1,000,000 set & get370.542.700.11
1,000,000 CPT set & get283.343.530.07
1,000,000 Map set & get287.093.480.04
1,000,000 Set add & has190.505.250.01
1,000,000 ObjKey set & get880.471.140.10
1,000,000 Map ObjKey set & get334.472.990.05
1,000,000 Set ObjKey add & has310.123.220.06
+
test nametime taken (ms)executions per secsample deviation
1,000,000 set116.858.560.04
1,000,000 Map set216.074.630.02
1,000,000 Set add173.915.750.01
1,000,000 set & get124.878.010.04
1,000,000 Map set & get323.103.100.04
1,000,000 Set add & has180.325.550.02
1,000,000 ObjKey set & get335.512.980.07
1,000,000 Map ObjKey set & get310.643.220.06
1,000,000 Set ObjKey add & has271.153.690.05
heap
-
test nametime taken (ms)executions per secsample deviation
100,000 add & pop80.1312.480.00
100,000 add & dfs35.0828.500.00
10,000 fib add & pop367.842.720.01
+
test nametime taken (ms)executions per secsample deviation
100,000 add & pop79.4312.590.00
100,000 add & dfs34.7828.750.00
10,000 fib add & pop356.182.810.00
doubly-linked-list
-
test nametime taken (ms)executions per secsample deviation
1,000,000 push237.284.210.07
1,000,000 CPT push75.6613.220.03
1,000,000 unshift226.384.420.05
1,000,000 CPT unshift93.3410.710.07
1,000,000 unshift & shift188.345.310.05
1,000,000 insertBefore329.603.030.05
+
test nametime taken (ms)executions per secsample deviation
1,000,000 push222.754.490.05
1,000,000 unshift235.704.240.06
1,000,000 unshift & shift179.265.580.04
1,000,000 insertBefore340.922.930.07
singly-linked-list
-
test nametime taken (ms)executions per secsample deviation
10,000 push & pop221.324.520.01
10,000 insertBefore255.523.910.01
+
test nametime taken (ms)executions per secsample deviation
10,000 push & pop213.004.690.01
10,000 insertBefore248.654.020.01
max-priority-queue
-
test nametime taken (ms)executions per secsample deviation
10,000 refill & poll9.07110.242.71e-4
+
test nametime taken (ms)executions per secsample deviation
10,000 refill & poll9.15109.234.05e-4
priority-queue
-
test nametime taken (ms)executions per secsample deviation
100,000 add & pop101.939.817.95e-4
100,000 CPT add & pop28.5435.040.00
+
test nametime taken (ms)executions per secsample deviation
100,000 add & pop102.309.780.00
deque
-
test nametime taken (ms)executions per secsample deviation
1,000,000 push14.4369.292.36e-4
1,000,000 CPT push25.0839.870.01
1,000,000 push & pop22.8743.726.05e-4
1,000,000 push & shift25.2839.550.01
1,000,000 unshift & shift21.8845.712.05e-4
+
test nametime taken (ms)executions per secsample deviation
1,000,000 push14.5868.591.47e-4
1,000,000 push & pop23.4442.671.85e-4
1,000,000 push & shift24.5140.801.39e-4
1,000,000 unshift & shift22.7843.910.00
queue
-
test nametime taken (ms)executions per secsample deviation
1,000,000 push38.4925.989.08e-4
1,000,000 CPT push43.9322.760.01
1,000,000 push & shift82.8512.070.00
+
test nametime taken (ms)executions per secsample deviation
1,000,000 push39.3625.410.01
1,000,000 push & shift81.8112.220.00
stack
-
test nametime taken (ms)executions per secsample deviation
1,000,000 push40.1924.880.01
1,000,000 CPT push39.8725.080.00
1,000,000 push & pop41.6724.000.01
1,000,000 CPT push & pop46.6521.440.00
+
test nametime taken (ms)executions per secsample deviation
1,000,000 push38.8925.720.00
1,000,000 push & pop44.2122.620.01
trie
-
test nametime taken (ms)executions per secsample deviation
100,000 push43.4223.037.57e-4
100,000 getWords93.4110.710.00
+
test nametime taken (ms)executions per secsample deviation
100,000 push44.2222.610.00
100,000 getWords89.3111.200.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'); }); });