|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace codedweller { |
|
|
namespace codedweller { |
|
|
|
|
|
|
|
|
uint32_t primes[256] { |
|
|
|
|
|
|
|
|
const uint32_t primes[256] { |
|
|
1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, |
|
|
1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, |
|
|
1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, |
|
|
1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, |
|
|
1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, |
|
|
1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, |
|
|
|
|
|
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline size_t mod256(size_t n) noexcept { return (n & 0xff); } |
|
|
|
|
|
|
|
|
inline size_t selectedPrime(size_t n) noexcept { return primes[n &0xff]; } |
|
|
|
|
|
|
|
|
uint32_t mishmash(const unsigned char* buffer, size_t length) noexcept { |
|
|
|
|
|
uint64_t accumulator = selectedPrime(length); |
|
|
|
|
|
|
|
|
uint64_t mishmash(const unsigned char* buffer, size_t length, uint64_t accumulator) noexcept { |
|
|
for(size_t index = 0; index < length; index++) { |
|
|
for(size_t index = 0; index < length; index++) { |
|
|
unsigned char byte = buffer[index]; |
|
|
unsigned char byte = buffer[index]; |
|
|
accumulator += selectedPrime(index + accumulator); |
|
|
|
|
|
accumulator *= selectedPrime(byte + accumulator); |
|
|
|
|
|
|
|
|
accumulator += selectedPrime(byte + accumulator); |
|
|
|
|
|
accumulator *= selectedPrime(accumulator); |
|
|
accumulator += accumulator >> 32; |
|
|
accumulator += accumulator >> 32; |
|
|
accumulator &= 0x00000fffffffffff; |
|
|
|
|
|
|
|
|
accumulator &= 0x000fffffffffffff; |
|
|
} |
|
|
} |
|
|
return static_cast<uint32_t>(accumulator); |
|
|
|
|
|
|
|
|
return accumulator; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
uint32_t mishmash(const unsigned char* buffer, size_t length) noexcept { |
|
|
|
|
|
uint64_t accumulator = mishmash(buffer, length, 0); |
|
|
|
|
|
return static_cast<uint32_t>(accumulator & 0x00000000ffffffff); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
uint32_t mishmash(const std::string& s) noexcept { |
|
|
uint32_t mishmash(const std::string& s) noexcept { |