Skip to content

Commit a652a3f

Browse files
committed
The IHasher infrastructure has been redesigned. Hasher implementations are now directly addressable via their algorithm names (for example, CrcHasher.Ulong).
1 parent 7a5bdf0 commit a652a3f

23 files changed

+520
-444
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,12 @@ Faster.Map supports **pluggable hash functions** for maximum performance:
107107
- **WyHash** – High-speed general purpose hashing.
108108
- **XXHash3** – Optimized for throughput and low latency.
109109
- **FastHash** – AES-based hashing (requires X86Aes support).
110+
- **CrcHasher** – Non-cryptographic hash with good distribution (requires Sse42)
111+
- **DefaultHasher** – .NET's built-in `GetHashCode()`.
110112

111113
Example:
112114
```csharp
113-
var map = new BlitzMap<int, string, XxHash3StringHasher>();
115+
var map = new BlitzMap<int, string, XxHash3Hasher.String>();
114116
map.Insert(1, "Value One");
115117
map.Insert(2, "Value Two");
116118
```

benchmarks/Faster.Map.Benchmark/AddBenchmark.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Collections;
77
using BenchmarkDotNet.Engines;
88
using Faster.Map.Benchmark.Utilities;
9-
using Faster.Map.Hasher;
109
using Faster.Map.Core;
1110

1211
namespace Faster.Map.Benchmark

benchmarks/Faster.Map.Benchmark/CorrelatedKeyBenchmark.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ public class CorrelatedKeyBenchmark
1919
{
2020
#region Fields
2121

22-
private DenseMap<uint, uint, FastHasherUint> _denseMapAES;
22+
private DenseMap<uint, uint, FastHasher.UInt> _denseMapAES;
2323
private DenseMap<uint, uint, AvalancheHasherUint> _denseMapAvalanche;
24-
private BlitzMap<uint, uint, FastHasherUint> _blitzMapAes;
24+
private BlitzMap<uint, uint, FastHasher.UInt> _blitzMapAes;
2525
private BlitzMap<uint, uint, AvalancheHasherUint> _blitzMapAvalance;
2626
private uint[] keys;
2727

@@ -67,9 +67,9 @@ public void Setup()
6767

6868
uint capacity = BitOperations.RoundUpToPowerOf2(Length);
6969

70-
_denseMapAES = new DenseMap<uint, uint, FastHasherUint>(capacity);
70+
_denseMapAES = new DenseMap<uint, uint, FastHasher.UInt>(capacity);
7171
_denseMapAvalanche = new DenseMap<uint, uint, AvalancheHasherUint>(capacity);
72-
_blitzMapAes = new BlitzMap<uint, uint, FastHasherUint>((int)capacity);
72+
_blitzMapAes = new BlitzMap<uint, uint, FastHasher.UInt>((int)capacity);
7373
_blitzMapAvalance = new BlitzMap<uint, uint, AvalancheHasherUint>((int)capacity);
7474

7575
foreach (var key in keys)

benchmarks/Faster.Map.Benchmark/EnumerableBenchmark.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
using BenchmarkDotNet.Attributes;
2-
using BenchmarkDotNet.Engines;
32
using Faster.Map.Benchmark.Utilities;
43
using Faster.Map.Core;
5-
using Faster.Map.Hasher;
6-
using System;
74
using System.Collections;
85
using System.Collections.Generic;
96
using System.Linq;
107
using System.Numerics;
8+
119
namespace Faster.Map.Benchmark;
1210

1311
//[MarkdownExporterAttribute.GitHub]

benchmarks/Faster.Map.Benchmark/GetBenchmark.cs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,15 @@ namespace Faster.Map.Benchmark
1414
{
1515
[MarkdownExporterAttribute.GitHub]
1616
[SimpleJob(RunStrategy.Monitoring, launchCount: 1, iterationCount: 20, warmupCount: 5)]
17-
//[HardwareCounters(
18-
//HardwareCounter.BranchMispredictions,
19-
//HardwareCounter.BranchInstructions,
20-
//HardwareCounter.CacheMisses,
21-
//HardwareCounter.TotalCycles)]
2217

2318
public class GetBenchmark
2419
{
2520
#region Fields
2621

27-
private DenseMap<uint, uint, FastHasherUint> _denseMap;
28-
private BlitzMap<uint, uint, FastHasherUint> _blitz;
22+
private DenseMap<uint, uint, FastHasher.UInt> _denseMap;
23+
private BlitzMap<uint, uint, CrcHasher.UInt> _blitz;
2924
private Dictionary<uint, uint> _dictionary;
30-
private RobinhoodMap<uint, uint, FastHasherUint> _robinHoodMap;
25+
private RobinhoodMap<uint, uint, FastHasher.UInt> _robinHoodMap;
3126

3227
private uint[] keys;
3328

@@ -62,11 +57,11 @@ public void Setup()
6257
uint length = BitOperations.RoundUpToPowerOf2(Length);
6358
int dicLength = HashHelpers.GetPrime((int)Length);
6459

65-
_denseMap = new DenseMap<uint, uint, FastHasherUint>(length);
66-
_blitz = new BlitzMap<uint, uint, FastHasherUint>((int)length, LoadFactor);
60+
_denseMap = new DenseMap<uint, uint, FastHasher.UInt>(length);
61+
_blitz = new BlitzMap<uint, uint, CrcHasher.UInt>((int)length, LoadFactor);
6762

6863
_dictionary = new Dictionary<uint, uint>(dicLength);
69-
_robinHoodMap = new RobinhoodMap<uint, uint, FastHasherUint>(length, 0.9);
64+
_robinHoodMap = new RobinhoodMap<uint, uint, FastHasher.UInt>(length, 0.9);
7065

7166
foreach (var key in keys)
7267
{

benchmarks/Faster.Map.Benchmark/LargeStringCustomHasherBenchmark.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using BenchmarkDotNet.Engines;
33
using Faster.Map.Benchmark.Utilities;
44
using Faster.Map.Core;
5-
using Faster.Map.Hasher;
65
using Faster.Map.Hashing;
76
using System;
87
using System.Collections;
@@ -22,9 +21,9 @@ public class LargeStringCustomHasherBenchmark
2221

2322
private Dictionary<string, string> _dictionary;
2423
private BlitzMap<string, string> _blitzMap;
25-
private BlitzMap<string, string, XxHash3StringHasher> _blitzMap1;
26-
private BlitzMap<string, string, FastHasherString> _blitzMap2;
27-
private BlitzMap<string, string, WyHasher> _blitzMap3;
24+
private BlitzMap<string, string, XxHash3Hasher.String> _blitzMap1;
25+
private BlitzMap<string, string, FastHasher.String> _blitzMap2;
26+
private BlitzMap<string, string, WyHasher.String> _blitzMap3;
2827

2928
private string[] keys;
3029

@@ -66,9 +65,9 @@ public void Setup()
6665
int dicLength = HashHelpers.GetPrime((int)Length);
6766

6867
_blitzMap = new BlitzMap<string, string>((int)length, 0.8);
69-
_blitzMap1 = new BlitzMap<string, string, XxHash3StringHasher>((int)length, 0.8);
70-
_blitzMap2 = new BlitzMap<string, string, FastHasherString>((int)length, 0.8);
71-
_blitzMap3 = new BlitzMap<string, string, WyHasher>((int)length, 0.8);
68+
_blitzMap1 = new BlitzMap<string, string, XxHash3Hasher.String>((int)length, 0.8);
69+
_blitzMap2 = new BlitzMap<string, string, FastHasher.String>((int)length, 0.8);
70+
_blitzMap3 = new BlitzMap<string, string, WyHasher.String>((int)length, 0.8);
7271

7372
_dictionary = new Dictionary<string, string>(dicLength);
7473

benchmarks/Faster.Map.Benchmark/RemoveBenchmark.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
using System;
22
using System.Collections;
33
using System.Collections.Generic;
4-
using System.IO;
54
using System.Linq;
65
using System.Numerics;
76
using BenchmarkDotNet.Attributes;
87
using BenchmarkDotNet.Engines;
98
using BenchmarkDotNet.Running;
109
using Faster.Map.Benchmark.Utilities;
1110
using Faster.Map.Core;
12-
using Faster.Map.Hasher;
1311

1412
namespace Faster.Map.Benchmark
1513
{

benchmarks/Faster.Map.Benchmark/StringCustomHasherBenchmark.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ public class StringCustomHasherBenchmark
2222
////fixed size, dont want to measure resize()
2323
private Dictionary<string, string> _dictionary;
2424
private BlitzMap<string, string> _blitzMap;
25-
private BlitzMap<string, string, XxHash3StringHasher> _blitzMap1;
26-
private BlitzMap<string, string, FastHasherString> _blitzMap2;
27-
private BlitzMap<string, string, WyHasher> _blitzMap3;
25+
private BlitzMap<string, string, XxHash3Hasher.String> _blitzMap1;
26+
private BlitzMap<string, string, FastHasher.String> _blitzMap2;
27+
private BlitzMap<string, string, WyHasher.String> _blitzMap3;
2828

2929
private string[] keys;
3030

@@ -60,9 +60,9 @@ public void Setup()
6060
int dicLength = HashHelpers.GetPrime((int)Length);
6161

6262
_blitzMap = new BlitzMap<string, string>((int)length, 0.8);
63-
_blitzMap1 = new BlitzMap<string, string, XxHash3StringHasher>((int)length, 0.8);
64-
_blitzMap2 = new BlitzMap<string, string, FastHasherString>((int)length, 0.8);
65-
_blitzMap3 = new BlitzMap<string, string, WyHasher>((int)length, 0.8);
63+
_blitzMap1 = new BlitzMap<string, string, XxHash3Hasher.String>((int)length, 0.8);
64+
_blitzMap2 = new BlitzMap<string, string, FastHasher.String>((int)length, 0.8);
65+
_blitzMap3 = new BlitzMap<string, string, WyHasher.String>((int)length, 0.8);
6666

6767

6868
_dictionary = new Dictionary<string, string>(dicLength);

benchmarks/Faster.Map.Benchmark/UpdateBenchmark.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
using System;
22
using System.Collections;
33
using System.Collections.Generic;
4-
using System.IO;
54
using System.Linq;
65
using System.Numerics;
76
using BenchmarkDotNet.Attributes;
87
using BenchmarkDotNet.Engines;
98
using Faster.Map.Benchmark.Utilities;
109
using Faster.Map.Core;
11-
using Faster.Map.Hasher;
1210

1311
namespace Faster.Map.Benchmark
1412
{

src/Core/BlitzMap.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace Faster.Map.Core;
2121
/// </summary>
2222
/// <typeparam name="TKey">The type of the keys in the map.</typeparam>
2323
/// <typeparam name="TValue">The type of the values in the map.</typeparam>
24-
public class BlitzMap<TKey, TValue> : BlitzMap<TKey, TValue, DefaultHasher<TKey>>
24+
public class BlitzMap<TKey, TValue> : BlitzMap<TKey, TValue, DefaultHasher.Generic<TKey>>
2525
{
2626
/// <summary>
2727
/// Initializes a new instance of the <see cref="BlitzMap{TKey, TValue}"/> class

0 commit comments

Comments
 (0)