33# include <gsl/gsl_rng.h>
36# include <shared_mutex>
53static std::atomic<bool>
init{
false};
64#define FORCE_INLINE __attribute__((always_inline)) inline
66#define FORCE_INLINE inline
71 return (x <<
r) | (x >> (32 -
r));
76 return (x <<
r) | (x >> (64 -
r));
79#define ROTL32(x,y) rotl32(x,y)
80#define ROTL64(x,y) rotl64(x,y)
82#define BIG_CONSTANT(x) (x##LLU)
88#define getblock(p, i) (p[i])
117 return static_cast<std::uint32_t
>(p[0])
118 | (
static_cast<std::uint32_t
>(p[1]) << 8)
119 | (
static_cast<std::uint32_t
>(p[2]) << 16)
120 | (
static_cast<std::uint32_t
>(p[3]) << 24);
125 return static_cast<std::uint64_t
>(p[0])
126 | (
static_cast<std::uint64_t
>(p[1]) << 8)
127 | (
static_cast<std::uint64_t
>(p[2]) << 16)
128 | (
static_cast<std::uint64_t
>(p[3]) << 24)
129 | (
static_cast<std::uint64_t
>(p[4]) << 32)
130 | (
static_cast<std::uint64_t
>(p[5]) << 40)
131 | (
static_cast<std::uint64_t
>(p[6]) << 48)
132 | (
static_cast<std::uint64_t
>(p[7]) << 56);
136 std::uint64_t
rhs)
noexcept
138#ifdef __SIZEOF_INT128__
140 return static_cast<std::uint64_t
>(
prod)
141 ^
static_cast<std::uint64_t
>(
prod >> 64);
143 const std::uint64_t
lhs_lo =
lhs & 0xffffffffULL;
145 const std::uint64_t
rhs_lo =
rhs & 0xffffffffULL;
154 const std::uint64_t
mid =
lh << 32;
157 const std::uint64_t
mid2 =
hl << 32;
160 std::uint64_t high =
hh + (
lh >> 32) + (
hl >> 32) +
carry;
166 std::uint64_t
input)
noexcept
168 constexpr std::uint64_t
prime2 = 14029467366897019727ULL;
169 constexpr std::uint64_t
prime1 = 11400714785074694791ULL;
177 std::uint64_t value)
noexcept
179 constexpr std::uint64_t
prime1 = 11400714785074694791ULL;
180 constexpr std::uint64_t
prime4 = 9650029242287828579ULL;
188 std::uint64_t
rhs)
noexcept
203 for (
int i = 0; i < 256; ++i)
208 init.store(
true, std::memory_order_release);
213 return init.load(std::memory_order_acquire);
227 catch (
const std::system_error &)
232 std::unique_lock<std::shared_mutex> lock(
jsw_mtx);
233 if (
not init.load(std::memory_order_acquire))
243 std::unique_lock<std::shared_mutex> lock(
jsw_mtx);
247size_t jsw_hash(
const void * key,
size_t len)
noexcept
249 if (
not init.load(std::memory_order_acquire))
258 catch (
const std::system_error &)
261 if (
not init.load(std::memory_order_acquire))
267 std::shared_lock<std::shared_mutex> lock(
jsw_mtx);
268 const unsigned char *p = (
const unsigned char*) key;
271 for (
size_t i = 0; i < len; i++)
272 h = (
h << 1 |
h >> 31) ^
tab[p[i]];
279 if (
not init.load(std::memory_order_acquire))
286 catch (
const std::system_error &)
289 if (
not init.load(std::memory_order_acquire))
294 std::shared_lock<std::shared_mutex> lock(
jsw_mtx);
295 const unsigned char * p = (
const unsigned char*) key;
304#define jen_mix(a,b,c) \
306 a -= c; a ^= ROTL32(c, 4); c += b; \
307 b -= a; b ^= ROTL32(a, 6); a += c; \
308 c -= b; c ^= ROTL32(b, 8); b += a; \
309 a -= c; a ^= ROTL32(c,16); c += b; \
310 b -= a; b ^= ROTL32(a,19); a += c; \
311 c -= b; c ^= ROTL32(b, 4); b += a; \
314#define jen_final(a,b,c) \
316 c ^= b; c -= ROTL32(b,14); \
317 a ^= c; a -= ROTL32(c,11); \
318 b ^= a; b -= ROTL32(a,25); \
319 c ^= b; c -= ROTL32(b,16); \
320 a ^= c; a -= ROTL32(c,4); \
321 b ^= a; b -= ROTL32(a,14); \
322 c ^= b; c -= ROTL32(b,24); \
361 case 0 :
return static_cast<size_t>(c);
365 return static_cast<size_t>(c);
399 h1 =
h1*5+0xe6546b64;
413 case 1:
k1 ^= tail[0];
487 case 13:
k4 ^= tail[12] << 0;
493 case 9:
k3 ^= tail[ 8] << 0;
499 case 5:
k2 ^= tail[ 4] << 0;
505 case 1:
k1 ^= tail[ 0] << 0;
512 h1 ^= len;
h2 ^= len;
h3 ^= len;
h4 ^= len;
596 h1 ^= len;
h2 ^= len;
613 constexpr std::uint64_t
prime1 = 11400714785074694791ULL;
614 constexpr std::uint64_t
prime2 = 14029467366897019727ULL;
615 constexpr std::uint64_t
prime3 = 1609587929392839161ULL;
616 constexpr std::uint64_t
prime4 = 9650029242287828579ULL;
617 constexpr std::uint64_t
prime5 = 2870177450012600261ULL;
619 const auto * p =
static_cast<const std::uint8_t *
>(key);
630 return static_cast<size_t>(hash);
633 const auto *
const end = p + len;
634 std::uint64_t hash = 0;
638 const auto *
const limit = end - 32;
641 std::uint64_t
v3 =
seed + 0;
681 hash ^=
static_cast<std::uint64_t
>(*p++) *
prime5;
691 return static_cast<size_t>(hash);
696 static constexpr std::uint64_t
secret[] =
698 0xa0761d6478bd642fULL,
699 0xe7037ed1a0b428dbULL,
700 0x8ebc6af09c88c6e3ULL,
701 0x589965cc75374cc3ULL
704 const auto * p =
static_cast<const std::uint8_t *
>(key);
707 std::uint64_t remaining = len;
711 auto read_wyr3 = [] (
const std::uint8_t * data,
size_t n)
noexcept
713 return (
static_cast<std::uint64_t
>(data[0]) << 16)
714 | (
static_cast<std::uint64_t
>(data[n >> 1]) << 8)
715 |
static_cast<std::uint64_t
>(data[n - 1]);
722 const size_t delta = (remaining >> 3) << 2;
723 a = (
static_cast<std::uint64_t
>(
read_le32(p)) << 32)
725 b = (
static_cast<std::uint64_t
>(
read_le32(p + remaining - 4)) << 32)
728 else if (remaining > 0)
747 while (remaining > 48);
751 while (remaining > 16)
762 return static_cast<size_t>(
767 std::uint64_t
key0, std::uint64_t
key1)
noexcept
769 const auto *
in =
static_cast<const std::uint8_t *
>(key);
771 std::uint64_t
v0 = 0x736f6d6570736575ULL ^
key0;
772 std::uint64_t v1 = 0x646f72616e646f6dULL ^
key1;
773 std::uint64_t v2 = 0x6c7967656e657261ULL ^
key0;
774 std::uint64_t
v3 = 0x7465646279746573ULL ^
key1;
797 const std::uint64_t b = 0;
803 return static_cast<size_t>(
v0 ^ v1 ^ v2 ^
v3);
806 const auto *
const end =
in + (len - (len & 7));
808 for (;
in != end;
in += 8)
817 std::uint64_t b =
static_cast<std::uint64_t
>(len) << 56;
820 case 7: b |=
static_cast<std::uint64_t
>(
in[6]) << 48; [[
fallthrough]];
821 case 6: b |=
static_cast<std::uint64_t
>(
in[5]) << 40; [[
fallthrough]];
822 case 5: b |=
static_cast<std::uint64_t
>(
in[4]) << 32; [[
fallthrough]];
823 case 4: b |=
static_cast<std::uint64_t
>(
in[3]) << 24; [[
fallthrough]];
824 case 3: b |=
static_cast<std::uint64_t
>(
in[2]) << 16; [[
fallthrough]];
825 case 2: b |=
static_cast<std::uint64_t
>(
in[1]) << 8; [[
fallthrough]];
826 case 1: b |=
static_cast<std::uint64_t
>(
in[0]); [[
fallthrough]];
840 return static_cast<size_t>(
v0 ^ v1 ^ v2 ^
v3);
Exception handling system with formatted messages for Aleph-w.
size_t jsw_hash(const void *key, size_t len) noexcept
JSW hash (Julienne Walker)
size_t xxhash64_hash(const void *key, size_t len, std::uint64_t seed) noexcept
xxHash64 from the xxHash family.
size_t jen_hash(const void *key, size_t length, unsigned initval) noexcept
Jenkins hash (lookup3)
size_t siphash24_hash(const void *key, size_t len, std::uint64_t key0, std::uint64_t key1) noexcept
SipHash-2-4 keyed hash.
bool is_jsw_initialized() noexcept
Checks if the jsw_hash() lookup table has been initialized.
void init_jsw() noexcept
Initializes the randomized lookup table used by jsw_hash().
size_t wyhash_hash(const void *key, size_t len, std::uint64_t seed) noexcept
wyhash non-cryptographic hash.
#define jen_final(a, b, c)
Main namespace for Aleph-w library functions.
static uint32_t fmix32(uint32_t h)
void MurmurHash3_x86_32(const void *key, int len, uint32_t seed, void *out)
static std::uint64_t xxh64_round(std::uint64_t acc, std::uint64_t input) noexcept
void MurmurHash3_x64_128(const void *key, const int len, const uint32_t seed, void *out)
static std::once_flag jsw_init_flag
static std::uint64_t mul_xor_fold64(std::uint64_t lhs, std::uint64_t rhs) noexcept
static std::shared_mutex jsw_mtx
static long & low(typename GT::Node *p)
Internal helper: low-link value stored directly in NODE_COOKIE(p).
static uint32_t rotl32(uint32_t x, int8_t r)
static std::uint64_t wyhash_mix(std::uint64_t lhs, std::uint64_t rhs) noexcept
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
static uint64_t fmix64(uint64_t k)
static uint64_t rotl64(uint64_t x, int8_t r)
void MurmurHash3_x86_128(const void *key, const int len, uint32_t seed, void *out)
static std::uint64_t read_le64(const std::uint8_t *p) noexcept
const unsigned Default_Hash_Seed
static std::uint32_t read_le32(const std::uint8_t *p) noexcept
static void jsw_fill_table(std::uint32_t seed) noexcept
static std::atomic< bool > init
static std::uint64_t xxh64_merge_round(std::uint64_t acc, std::uint64_t value) noexcept
FooMap m(5, fst_unit_pair_hash, snd_unit_pair_hash)