33# include <gsl/gsl_rng.h>
37# include <shared_mutex>
54static std::atomic<bool>
init{
false};
65#define FORCE_INLINE __attribute__((always_inline)) inline
67#define FORCE_INLINE inline
72 return (x <<
r) | (x >> (32 -
r));
77 return (x <<
r) | (x >> (64 -
r));
80#define ROTL32(x,y) rotl32(x,y)
81#define ROTL64(x,y) rotl64(x,y)
83#define BIG_CONSTANT(x) (x##LLU)
89#define getblock(p, i) (p[i])
118 if constexpr (std::numeric_limits<size_t>::digits >= 64)
119 return static_cast<size_t>(hash);
122 constexpr unsigned bits = std::numeric_limits<size_t>::digits;
123 const std::uint64_t mask = (std::uint64_t{1} << bits) - 1;
124 hash ^= hash >> bits;
125 return static_cast<size_t>(hash & mask);
131 return static_cast<std::uint32_t
>(p[0])
132 | (
static_cast<std::uint32_t
>(p[1]) << 8)
133 | (
static_cast<std::uint32_t
>(p[2]) << 16)
134 | (
static_cast<std::uint32_t
>(p[3]) << 24);
139 return static_cast<std::uint64_t
>(p[0])
140 | (
static_cast<std::uint64_t
>(p[1]) << 8)
141 | (
static_cast<std::uint64_t
>(p[2]) << 16)
142 | (
static_cast<std::uint64_t
>(p[3]) << 24)
143 | (
static_cast<std::uint64_t
>(p[4]) << 32)
144 | (
static_cast<std::uint64_t
>(p[5]) << 40)
145 | (
static_cast<std::uint64_t
>(p[6]) << 48)
146 | (
static_cast<std::uint64_t
>(p[7]) << 56);
151 p[0] =
static_cast<std::uint8_t
>(
value);
152 p[1] =
static_cast<std::uint8_t
>(
value >> 8);
153 p[2] =
static_cast<std::uint8_t
>(
value >> 16);
154 p[3] =
static_cast<std::uint8_t
>(
value >> 24);
164 std::uint64_t rhs)
noexcept
166#ifdef __SIZEOF_INT128__
168 return static_cast<std::uint64_t
>(
prod)
169 ^
static_cast<std::uint64_t
>(
prod >> 64);
171 const std::uint64_t
lhs_lo = lhs & 0xffffffffULL;
172 const std::uint64_t
lhs_hi = lhs >> 32;
173 const std::uint64_t
rhs_lo = rhs & 0xffffffffULL;
174 const std::uint64_t
rhs_hi = rhs >> 32;
182 const std::uint64_t
mid =
lh << 32;
185 const std::uint64_t
mid2 =
hl << 32;
188 std::uint64_t high =
hh + (
lh >> 32) + (
hl >> 32) +
carry;
194 std::uint64_t
input)
noexcept
196 constexpr std::uint64_t
prime2 = 14029467366897019727ULL;
197 constexpr std::uint64_t
prime1 = 11400714785074694791ULL;
205 std::uint64_t
value)
noexcept
207 constexpr std::uint64_t
prime1 = 11400714785074694791ULL;
208 constexpr std::uint64_t
prime4 = 9650029242287828579ULL;
216 std::uint64_t rhs)
noexcept
223 state = state * 1664525u + 1013904223u;
239 for (
int i = 0; i < 256; ++i)
241 init.store(
true, std::memory_order_release);
246 for (
int i = 0; i < 256; ++i)
251 init.store(
true, std::memory_order_release);
256 return init.load(std::memory_order_acquire);
270 catch (
const std::system_error &)
275 std::unique_lock<std::shared_mutex> lock(
jsw_mtx);
276 if (
not init.load(std::memory_order_acquire))
286 std::unique_lock<std::shared_mutex> lock(
jsw_mtx);
290size_t jsw_hash(
const void * key,
size_t len)
noexcept
292 if (
not init.load(std::memory_order_acquire))
301 catch (
const std::system_error &)
304 if (
not init.load(std::memory_order_acquire))
310 std::shared_lock<std::shared_mutex> lock(
jsw_mtx);
311 const unsigned char *p = (
const unsigned char*) key;
314 for (
size_t i = 0; i < len; i++)
315 h = (
h << 1 |
h >> 31) ^
tab[p[i]];
322 if (
not init.load(std::memory_order_acquire))
329 catch (
const std::system_error &)
332 if (
not init.load(std::memory_order_acquire))
337 std::shared_lock<std::shared_mutex> lock(
jsw_mtx);
338 const unsigned char * p = (
const unsigned char*) key;
347#define jen_mix(a,b,c) \
349 a -= c; a ^= ROTL32(c, 4); c += b; \
350 b -= a; b ^= ROTL32(a, 6); a += c; \
351 c -= b; c ^= ROTL32(b, 8); b += a; \
352 a -= c; a ^= ROTL32(c,16); c += b; \
353 b -= a; b ^= ROTL32(a,19); a += c; \
354 c -= b; c ^= ROTL32(b, 4); b += a; \
357#define jen_final(a,b,c) \
359 c ^= b; c -= ROTL32(b,14); \
360 a ^= c; a -= ROTL32(c,11); \
361 b ^= a; b -= ROTL32(a,25); \
362 c ^= b; c -= ROTL32(b,16); \
363 a ^= c; a -= ROTL32(c,4); \
364 b ^= a; b -= ROTL32(a,14); \
365 c ^= b; c -= ROTL32(b,24); \
404 case 0 :
return static_cast<size_t>(c);
408 return static_cast<size_t>(c);
440 h1 =
h1*5+0xe6546b64;
454 case 1:
k1 ^= tail[0];
490 const uint8_t * block = data + i*16;
527 case 13:
k4 ^= tail[12] << 0;
533 case 9:
k3 ^= tail[ 8] << 0;
539 case 5:
k2 ^= tail[ 4] << 0;
545 case 1:
k1 ^= tail[ 0] << 0;
552 h1 ^= len;
h2 ^= len;
h3 ^= len;
h4 ^= len;
590 const uint8_t * block = data + i*16;
636 h1 ^= len;
h2 ^= len;
654 constexpr std::uint64_t
prime1 = 11400714785074694791ULL;
655 constexpr std::uint64_t
prime2 = 14029467366897019727ULL;
656 constexpr std::uint64_t
prime3 = 1609587929392839161ULL;
657 constexpr std::uint64_t
prime4 = 9650029242287828579ULL;
658 constexpr std::uint64_t
prime5 = 2870177450012600261ULL;
660 const auto * p =
static_cast<const std::uint8_t *
>(key);
674 const auto *
const end = p + len;
675 std::uint64_t hash = 0;
679 const auto *
const limit = end - 32;
682 std::uint64_t
v3 =
seed + 0;
722 hash ^=
static_cast<std::uint64_t
>(*p++) *
prime5;
737 static constexpr std::uint64_t
secret[] =
739 0xa0761d6478bd642fULL,
740 0xe7037ed1a0b428dbULL,
741 0x8ebc6af09c88c6e3ULL,
742 0x589965cc75374cc3ULL
745 const auto * p =
static_cast<const std::uint8_t *
>(key);
748 std::uint64_t remaining = len;
752 auto read_wyr3 = [] (
const std::uint8_t * data,
size_t n)
noexcept
754 return (
static_cast<std::uint64_t
>(data[0]) << 16)
755 | (
static_cast<std::uint64_t
>(data[n >> 1]) << 8)
756 |
static_cast<std::uint64_t
>(data[n - 1]);
763 const size_t delta = (remaining >> 3) << 2;
764 a = (
static_cast<std::uint64_t
>(
read_le32(p)) << 32)
766 b = (
static_cast<std::uint64_t
>(
read_le32(p + remaining - 4)) << 32)
769 else if (remaining > 0)
788 while (remaining > 48);
792 while (remaining > 16)
803 return static_cast<size_t>(
808 std::uint64_t
key0, std::uint64_t
key1)
noexcept
810 const auto *
in =
static_cast<const std::uint8_t *
>(key);
812 std::uint64_t
v0 = 0x736f6d6570736575ULL ^
key0;
813 std::uint64_t v1 = 0x646f72616e646f6dULL ^
key1;
814 std::uint64_t v2 = 0x6c7967656e657261ULL ^
key0;
815 std::uint64_t
v3 = 0x7465646279746573ULL ^
key1;
838 const std::uint64_t b = 0;
844 return static_cast<size_t>(
v0 ^ v1 ^ v2 ^
v3);
847 const auto *
const end =
in + (len - (len & 7));
849 for (;
in != end;
in += 8)
858 std::uint64_t b =
static_cast<std::uint64_t
>(len) << 56;
861 case 7: b |=
static_cast<std::uint64_t
>(
in[6]) << 48; [[
fallthrough]];
862 case 6: b |=
static_cast<std::uint64_t
>(
in[5]) << 40; [[
fallthrough]];
863 case 5: b |=
static_cast<std::uint64_t
>(
in[4]) << 32; [[
fallthrough]];
864 case 4: b |=
static_cast<std::uint64_t
>(
in[3]) << 24; [[
fallthrough]];
865 case 3: b |=
static_cast<std::uint64_t
>(
in[2]) << 16; [[
fallthrough]];
866 case 2: b |=
static_cast<std::uint64_t
>(
in[1]) << 8; [[
fallthrough]];
867 case 1: b |=
static_cast<std::uint64_t
>(
in[0]); [[
fallthrough]];
881 return static_cast<size_t>(
v0 ^ v1 ^ v2 ^
v3);
Exception handling system with formatted messages for Aleph-w.
size_t size_t int32_t value
size_t size_t int32_t * out
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
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)
Standard hash functions for Aleph types.
Main namespace for Aleph-w library functions.
static void write_le32(std::uint8_t *p, std::uint32_t value) noexcept
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
static uint64_t fmix64(uint64_t k)
static uint64_t rotl64(uint64_t x, int8_t r)
static void write_le64(std::uint8_t *p, std::uint64_t value) noexcept
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 jsw_fallback_next(std::uint32_t &state) noexcept
static size_t fold_hash64_to_size_t(std::uint64_t hash) noexcept
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)