Check in code for new random number generator

This commit is contained in:
2022-03-31 17:15:15 -04:00
parent 7fc6263e37
commit c48e02642a
9 changed files with 291 additions and 8 deletions

View File

@@ -131,6 +131,31 @@ eng::string hash_to_hex(const HashValue &hv) {
oss << std::hex << std::setw(16) << std::setfill('0') << hv.second;
return oss.str();
}
static inline uint64_t Rot64(uint64_t x, int k)
{
return (x << k) | (x >> (64 - k));
}
uint64_t hash_ints(uint64_t a, uint64_t b, uint64_t c, uint64_t d) {
uint64_t h0 = c ^ 0xc548cebf3714dbb9;
uint64_t h1 = d ^ 0xd23a7edd44383f8d;
uint64_t h2 = a ^ 0x7356f92e4b154df7;
uint64_t h3 = b ^ 0x55ce09295766838d;
h3 ^= h2; h2 = Rot64(h2,15); h3 += h2;
h0 ^= h3; h3 = Rot64(h3,52); h0 += h3;
h1 ^= h0; h0 = Rot64(h0,26); h1 += h0;
h2 ^= h1; h1 = Rot64(h1,51); h2 += h1;
h3 ^= h2; h2 = Rot64(h2,28); h3 += h2;
h0 ^= h3; h3 = Rot64(h3,9); h0 += h3;
h1 ^= h0; h0 = Rot64(h0,47); h1 += h0;
h2 ^= h1; h1 = Rot64(h1,54); h2 += h1;
h3 ^= h2; h2 = Rot64(h2,32); h3 += h2;
h0 ^= h3; h3 = Rot64(h3,25); h0 += h3;
h1 ^= h0; h0 = Rot64(h0,63); h1 += h0;
return h1;
}
StringVec split(const eng::string &s, char sep) {
StringVec result;
@@ -331,7 +356,6 @@ std::string_view sv_read_line(std::string_view &source) {
}
double distance_squared(double x1, double y1, double x2, double y2) {
double dx = x1 - x2;
double dy = y1 - y2;