An alternative version of FNV-1a hash spread on the internet, which operates directly on integers instead of bytes. The offset basis and prime are the same used in the original version, which operates on bytes.
With this version, is the statistical quality of the produced hash similar to the original algorithm?
Alternative version operating on integers:
#include <cstdint>
#define OFFSET_BASIS 2166136261ul
#define FNV_PRIME 16777619ul
uint32_t hash(uint32_t i, uint32_t j, uint32_t k)
{
return ((((((OFFSET_BASIS ^ i) * FNV_PRIME) ^ j) * FNV_PRIME) ^ k) * FNV_PRIME);
}
Original version operating on bytes:
#include <cstdint>
#define OFFSET_BASIS 2166136261ul
#define FNV_PRIME 16777619ul
uint32_t hash(char* data, size_t bytes)
{
uint32_t h = OFFSET_BASIS;
for (size_t i = 0; i < bytes; ++i)
{
h = (h ^ data[i]) * FNV_PRIME;
}
return h;
}