/// <summary> /// Returns the upper and lower base hash values from which the k hashes are /// derived using the given hash bytes directly. The result will be the /// same regardless of the endianness of the architecture. Used by a unit /// test to confirm the calculation is compatible with the HashKernel from /// https://github.com/tylertreat/BoomFilters running in Go. /// </summary> /// <param name="hashBytes">The hash bytes.</param> /// <returns>A HashKernel</returns> public static HashKernelReturnValue HashKernelFromHashBytes(byte[] hashBytes) { return(HashKernelReturnValue.Create( HashBytesToUInt32(hashBytes, 0), HashBytesToUInt32(hashBytes, 4) )); }
/// <summary> /// Returns the upper and lower base hash values from which the k hashes are /// derived. /// </summary> /// <param name="data">The data bytes to hash.</param> /// <param name="algorithm">The hashing algorithm to use.</param> /// <returns>A HashKernel</returns> public static HashKernelReturnValue HashKernel(byte[] data, HashAlgorithm algorithm) { var hash = new Hash(algorithm); hash.ComputeHash(data); var sum = hash.Sum(); return(HashKernelReturnValue.Create( ToBigEndianUInt32(sum.Skip(4).Take(4).ToArray()), ToBigEndianUInt32(sum.Take(4).ToArray()) )); }