1

Can I use the Knuth Hash to generate a unique hash number for a byte[]?

The normal Knuth Hash algorithm looks like this:

int KnuthHsh(int v)
{
    v *= 2654435761;
    return v >> 32;
}

Is there also a way to input a byte[] and generate a unique Hash value for it?

Quality Catalyst
  • 6,531
  • 8
  • 38
  • 62
Dark Side
  • 695
  • 2
  • 8
  • 18

1 Answers1

1
    public static ulong CalculateHash(byte[] bytes)
    {
        var hashedValue = 3074457345618258791UL;
        foreach (var b in bytes)
        {
            hashedValue += b;
            hashedValue *= 3074457345618258799UL;
        }
        return hashedValue;
    }
giorgizek
  • 21
  • 1