I'm using xxHash
for C# to hash a value for consistency.
ComputeHash
returns a byte[]
, but I need to store the results in a long
.
I'm able to convert the results into an int32
using the BitConverter
. Here is what I've tried:
var xxHash = new System.Data.HashFunction.xxHash();
byte[] hashedValue = xxHash.ComputeHash(Encoding.UTF8.GetBytes(valueItem));
long value = BitConverter.ToInt64(hashedValue, 0);
When I use int
this works fine, but when I change to ToInt64
it fails.
Here's the exception I get:
Destination array is not long enough to copy all the items in the collection. Check array index and length.
Adding a new answer because current implementation of xxHash from Brandon Dahler uses a hashing factory where you initialize the factory with a configuration containing hashsize and seed: