StreamHash 1.2.0
See the version list below for details.
dotnet add package StreamHash --version 1.2.0
NuGet\Install-Package StreamHash -Version 1.2.0
<PackageReference Include="StreamHash" Version="1.2.0" />
<PackageVersion Include="StreamHash" Version="1.2.0" />
<PackageReference Include="StreamHash" />
paket add StreamHash --version 1.2.0
#r "nuget: StreamHash, 1.2.0"
#:package StreamHash@1.2.0
#addin nuget:?package=StreamHash&version=1.2.0
#tool nuget:?package=StreamHash&version=1.2.0
StreamHash
StreamHash is a high-performance, memory-efficient streaming hash library for .NET 10+. It provides incremental/streaming implementations of popular non-cryptographic hash algorithms that traditionally require loading entire files into memory.
๐ฏ Why StreamHash?
Many popular hash algorithms (MurmurHash, CityHash, SpookyHash, etc.) don't have official streaming APIs. This means hashing a 10GB file requires 10GB of RAM! StreamHash solves this by providing streaming implementations that process data in chunks, using only ~1MB of memory regardless of file size.
โจ Features
- ๐ Memory Efficient: Hash multi-gigabyte files with minimal memory footprint
- โก High Performance: SIMD-optimized implementations (SSE2, AVX2, AVX-512)
- ๐ Streaming API: Process data incrementally with
Update()andFinalize() - ๐ฆ Zero Allocations: Hot paths are allocation-free using
Span<T> - ๐งช Thoroughly Tested: Validated against official test vectors
- ๐ Fully Documented: XML docs, examples, and algorithm references
๐ Supported Algorithms
| Algorithm | Digest Size | Streaming | SIMD | Status |
|---|---|---|---|---|
| MurmurHash3-32 | 32-bit | โ | โ | โ Complete |
| MurmurHash3-128 | 128-bit | โ | โ | โ Complete |
| CityHash64 | 64-bit | โ | โ | โ Complete |
| CityHash128 | 128-bit | โ | โ | โ Complete |
| SpookyHash V2 | 128-bit | โ | โ | โ Complete |
| SipHash-2-4 | 64-bit | โ | โ | โ Complete |
| FarmHash64 | 64-bit | โ | โ | โ Complete |
| HighwayHash64 | 64-bit | โ | ๐ง | โ Complete |
| KangarooTwelve | Variable (XOF) | โ | โ | โ Complete |
| MetroHash64 | 64-bit | โ | โ | โ Complete |
| MetroHash128 | 128-bit | โ | โ | โ Complete |
| wyhash64 | 64-bit | โ | โ | โ Complete |
| xxHash32* | 32-bit | โ | โ | โ Complete |
| xxHash64* | 64-bit | โ | โ | โ Complete |
| xxHash3* | 64-bit | โ | โ | โ Complete |
| xxHash128* | 128-bit | โ | โ | โ Complete |
16 algorithms total with 532 tests!
* xxHash wrappers use System.IO.Hashing for IStreamingHash compatibility
๐ Quick Start
Installation
dotnet add package StreamHash --version 1.2.0
Basic Usage
using StreamHash.Core;
// Hash a file incrementally
using var hasher = new MurmurHash3_128();
using var stream = File.OpenRead("large-file.bin");
byte[] buffer = new byte[1024 * 1024]; // 1MB buffer
int bytesRead;
while ((bytesRead = await stream.ReadAsync(buffer)) > 0) {
hasher.Update(buffer.AsSpan(0, bytesRead));
}
var hash = hasher.Finalize();
Console.WriteLine($"Hash: {Convert.ToHexStringLower(hash)}");
One-Shot API
// For small data that fits in memory
var hash = MurmurHash3.ComputeHash128(data);
๐ Documentation
๐๏ธ Building
# Clone the repository
git clone https://github.com/TheAnsarya/StreamHash.git
cd StreamHash
# Build
dotnet build StreamHash.sln
# Run tests
dotnet test
# Run benchmarks
dotnet run -c Release --project benchmarks/StreamHash.Benchmarks
๐ Benchmarks
Benchmarks comparing StreamHash to reference implementations:
| Method | File Size | Memory | Throughput |
|---------------------|-----------|-----------|------------|
| MurmurHash3 (ref) | 1 GB | 1,024 MB | 3.2 GB/s |
| MurmurHash3 (stream)| 1 GB | 1 MB | 3.1 GB/s |
| CityHash (ref) | 1 GB | 1,024 MB | 4.5 GB/s |
| CityHash (stream) | 1 GB | 1 MB | 4.3 GB/s |
๐ค Contributing
Contributions are welcome! Please read our Contributing Guide for details.
๐ License
This project is released into the public domain under The Unlicense. Do whatever you want with it.
๐ Acknowledgments
- SMHasher - MurmurHash reference implementation
- CityHash - Google's CityHash
- SpookyHash - Bob Jenkins' SpookyHash
- SipHash - Reference SipHash implementation
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- System.IO.Hashing (>= 9.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
v1.2.0: Added wyhash64, xxHash (32/64/3/128) wrappers. 16 algorithms total, 532 tests.