darrenkopp / murmurhash-net Goto Github PK
View Code? Open in Web Editor NEW.NET implementation of the murmurhash
License: Apache License 2.0
.NET implementation of the murmurhash
License: Apache License 2.0
With the same seed, the two algorithms do not generate the same hashes given the same input. Is this expected?
// Example
var murmur86 = MurmurHash.Create128(0, true, AlgorithmPreference.X86);
var murmur64 = MurmurHash.Create128(0, true, AlgorithmPreference.X64);
byte[] data = Guid.NewGuid().ToByteArray();
// Assert fails
Assert.Equal(murmur86.ComputeHash(data), murmur64.ComputeHash(data));
I ran into this on accident because the default argument, AlgorithmPreference.Auto picks based on bitness of the application. I was generating hashes from two different applications against the same data store. One of those applications happened to be 32bit and the other 64.
In dependency track this package is reporting as not having a licence type specified
The PackageLicenseExpression property is set in the csproj so thay the NUGET package has the information. This can then be included in the SBOM so that analysis can occur in the appropriate tools
Ignore them, bundle licence file into package & reference the file.
N/a
i initialize MurMurHash with a fixed seed (131).
Different assemblies calling ComputeHash with a given array of bytes produce different hashes .
I double checked and i swear i'm sober :)
How is that possible?
There should only be a single csproj file which when compiled produces dll's for each framework and all also produces a nuget package containing the appropriate dll's.
Hello.
I just saw the usage of this library in Seq's tutorial: https://blog.datalust.co/serilog-tutorial/ (check for Event type enrichment).
When I created the enrichment listed there I notice the Murmur32 class is a IDisposable
and Seq's example does't dispose it.
Should I create this instance every time I need to hash something and then dispose it or I should have a global static instance?
Thanks.
Testing with the value "test", I receive the int
value: 332557242
(see here: https://dotnetfiddle.net/p72M2c)
When compared to other implementations in other languages, this is an incorrect value (should be 3127628307).
Currently this library cannot be used in .Net Core apps. It would be great if this library can target .Net Standard.
When the length of the input data is not a multiple of 16, TransformBlock() does not behave correctly. In the following example, the same hash is generated for different byte sequences:
using System.Security.Cryptography;
using System.Text;
using Murmur;
{
using HashAlgorithm hashAlgorithm = MurmurHash.Create128(preference: AlgorithmPreference.X64);
TransformSingleByte(hashAlgorithm, 1);
TransformSingleByte(hashAlgorithm, 1);
TransformSingleByte(hashAlgorithm, 1);
TransformSingleByte(hashAlgorithm, 1);
hashAlgorithm.TransformFinalBlock(Array.Empty<byte>(), 0, 0);
PrintBytes(hashAlgorithm.Hash!);
}
{
using HashAlgorithm hashAlgorithm = MurmurHash.Create128(preference: AlgorithmPreference.X64);
TransformSingleByte(hashAlgorithm, 0);
TransformSingleByte(hashAlgorithm, 0);
TransformSingleByte(hashAlgorithm, 0);
TransformSingleByte(hashAlgorithm, 0);
hashAlgorithm.TransformFinalBlock(Array.Empty<byte>(), 0, 0);
PrintBytes(hashAlgorithm.Hash!);
}
{
using HashAlgorithm hashAlgorithm = MurmurHash.Create128(preference: AlgorithmPreference.X64);
TransformSingleByte(hashAlgorithm, 0);
TransformSingleByte(hashAlgorithm, 0);
TransformSingleByte(hashAlgorithm, 1);
TransformSingleByte(hashAlgorithm, 1);
hashAlgorithm.TransformFinalBlock(Array.Empty<byte>(), 0, 0);
PrintBytes(hashAlgorithm.Hash!);
}
{
using HashAlgorithm hashAlgorithm = MurmurHash.Create128(preference: AlgorithmPreference.X64);
TransformSingleByte(hashAlgorithm, 0);
TransformSingleByte(hashAlgorithm, 1);
TransformSingleByte(hashAlgorithm, 0);
TransformSingleByte(hashAlgorithm, 1);
hashAlgorithm.TransformFinalBlock(Array.Empty<byte>(), 0, 0);
PrintBytes(hashAlgorithm.Hash!);
}
static void TransformSingleByte(
HashAlgorithm hashAlgorithm,
byte @byte) =>
hashAlgorithm.TransformBlock(new[] {@byte}, 0, 1, null, 0);
static void PrintBytes(IEnumerable<byte> bytes)
{
var stringBuilder = new StringBuilder();
foreach (var @byte in bytes)
{
stringBuilder.AppendFormat("{0:X2}", @byte);
}
Console.WriteLine(stringBuilder.ToString());
}
Output:
BC764CD8DDF7A0CFF126F51C16239658
BC764CD8DDF7A0CFF126F51C16239658
BC764CD8DDF7A0CFF126F51C16239658
BC764CD8DDF7A0CFF126F51C16239658
I wish for the nuget packages to have a more informative readme.
The nuget package should be using the same readme as the repo to make it as easy as possible for a user to get started with the package.
Does it make sense to add some benchmarks? That would be great to compare performance with another implementations.
The generic HashAlgorithm.TryComputeHash(ReadOnlySpan<byte> source, Span<byte> destination, out int bytesWritten)
implementation of this function gives an error on the FinalBlock call.
It would be nice to overload this method
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.