using System;
namespace PKHeX.Core;
///
/// Fowler–Noll–Vo non-cryptographic hash
///
/// https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
public static class FnvHash
{
private const ulong kFnvPrime_64 = 0x00000100000001b3;
private const ulong kOffsetBasis_64 = 0xCBF29CE484222645;
///
/// Gets the hash code of the input sequence via the alternative Fnv1 method.
///
/// Input sequence
/// Initial hash value
/// Computed hash code
public static ulong HashFnv1a_64(ReadOnlySpan input, ulong hash = kOffsetBasis_64)
{
foreach (var c in input)
{
hash ^= c;
hash *= kFnvPrime_64;
}
return hash;
}
///
/// Gets the hash code of the input sequence via the alternative Fnv1 method.
///
/// Input sequence
/// Initial hash value
/// Computed hash code
public static ulong HashFnv1a_64(ReadOnlySpan input, ulong hash = kOffsetBasis_64)
{
foreach (var c in input)
{
hash ^= c;
hash *= kFnvPrime_64;
}
return hash;
}
}