38# include <type_traits>
103 const auto *p =
static_cast<const unsigned char *
>(key);
106 for (
size_t i = 0; i < len; i++)
122 inline size_t xor_hash(
const void * key,
const size_t len)
noexcept
124 const auto *p =
static_cast<const unsigned char *
>(key);
127 for (
size_t i = 0; i < len; i++)
143 inline size_t rot_hash(
const void * key,
const size_t len)
noexcept
145 const auto *p =
static_cast<const unsigned char *
>(key);
148 for (
size_t i = 0; i < len; i++)
149 h = (
h << 4) ^ (
h >> 28) ^ p[i];
163 inline size_t djb_hash(
const void * key,
const size_t len)
noexcept
165 const auto *p =
static_cast<const unsigned char *
>(key);
168 for (
size_t i = 0; i < len; i++)
183 inline size_t sax_hash(
const void * key,
const size_t len)
noexcept
185 const auto *p =
static_cast<const unsigned char *
>(key);
188 for (
size_t i = 0; i < len; i++)
189 h ^= (
h << 5) + (
h >> 2) + p[i];
203 inline size_t fnv_hash(
const void * key,
const size_t len)
noexcept
205 const auto *p =
static_cast<const unsigned char *
>(key);
206 size_t h = 2166136261;
208 for (
size_t i = 0; i < len; i++)
209 h = (
h * 16777619) ^ p[i];
223 inline size_t oat_hash(
const void * key,
const size_t len)
noexcept
225 const auto *p =
static_cast<const unsigned char *
>(key);
228 for (
size_t i = 0; i < len; i++)
264 extern size_t jsw_hash(
const void * key,
size_t len)
noexcept;
279 inline size_t elf_hash(
const void * key,
const size_t len)
noexcept
281 const auto *p =
static_cast<const unsigned char *
>(key);
284 for (
size_t i = 0; i < len; i++)
287 size_t g =
h & 0xf0000000L;
307 extern size_t jen_hash(
const void *key,
size_t len,
unsigned initval)
noexcept;
332 template <
typename Key>
333 requires std::is_trivially_copyable_v<Key>
353 const size_t len =
strlen(key);
396 memcpy(&val, p,
sizeof(val));
410 const auto * data =
static_cast<const unsigned char *
>(key);
411 std::uint32_t hash =
static_cast<std::uint32_t
>(len) ^
seed;
413 if (len <= 0 || data ==
nullptr)
414 return static_cast<size_t>(hash);
416 const int rem = len & 3;
417 const size_t nblocks = len >> 2;
420 for (
size_t i = 0; i <
nblocks; ++i)
423 const std::uint32_t
tmp = (
static_cast<std::uint32_t
>(
get16bits(data+2)) << 11) ^ hash;
424 hash = (hash << 16) ^
tmp;
435 hash ^=
static_cast<signed char>(data[
sizeof(
uint16_t)]) << 18;
444 hash +=
static_cast<signed char>(*data);
460 return static_cast<size_t>(hash);
512 std::uint64_t
key0 = 0x0706050403020100ULL,
522 template <
typename Key>
523 requires std::is_trivially_copyable_v<Key>
529 template <
typename Key>
530 requires std::is_trivially_copyable_v<Key>
536 template <
typename Key>
537 requires std::is_trivially_copyable_v<Key>
543 template <
typename Key>
544 requires std::is_trivially_copyable_v<Key>
550 template <
typename Key>
551 requires std::is_trivially_copyable_v<Key>
557 template <
typename Key>
558 requires std::is_trivially_copyable_v<Key>
566 template <
typename Key>
567 requires std::is_trivially_copyable_v<Key>
573 template <
typename Key>
574 requires std::is_trivially_copyable_v<Key>
580 template <
typename Key>
581 requires std::is_trivially_copyable_v<Key>
587 template <
typename Key>
588 requires (std::is_trivially_copyable_v<Key>
and
589 (
not std::is_pointer_v<Key>)
and (
not std::is_array_v<Key>))
595 template <
typename Key>
596 requires std::is_trivially_copyable_v<Key>
603 template <
typename Key>
604 requires std::is_trivially_copyable_v<Key>
611 template <
typename Key>
612 requires std::is_trivially_copyable_v<Key>
614 std::uint64_t
key0 = 0x0706050403020100ULL,
622 auto p =
reinterpret_cast<const unsigned char *
>(key);
633 auto p =
reinterpret_cast<const unsigned char *
>(key);
644 auto p =
reinterpret_cast<const unsigned char *
>(key);
648 h = (
h << 4) ^(
h >> 28) ^ *p++;
655 auto p =
reinterpret_cast<const unsigned char *
>(key);
666 auto p =
reinterpret_cast<const unsigned char *
>(key);
670 h ^= (
h << 5) +(
h >> 2) + *p++;
677 auto p =
reinterpret_cast<const unsigned char *
>(key);
678 size_t h = 2166136261;
681 h = (
h * 16777619) ^ *p++;
688 auto p =
reinterpret_cast<const unsigned char *
>(key);
710 extern size_t jsw_hash(
const char * key)
noexcept;
714 auto p =
reinterpret_cast<const unsigned char *
>(key);
720 size_t g =
h & 0xf0000000L;
749 std::uint64_t
key0 = 0x0706050403020100ULL,
759 inline size_t add_hash(
const std::string & key)
noexcept
761 return add_hash(key.data(), key.size());
764 inline size_t xor_hash(
const std::string & key)
noexcept
766 return xor_hash(key.data(), key.size());
769 inline size_t rot_hash(
const std::string & key)
noexcept
771 return rot_hash(key.data(), key.size());
774 inline size_t djb_hash(
const std::string & key)
noexcept
776 return djb_hash(key.data(), key.size());
779 inline size_t sax_hash(
const std::string & key)
noexcept
781 return sax_hash(key.data(), key.size());
784 inline size_t fnv_hash(
const std::string & key)
noexcept
786 return fnv_hash(key.data(), key.size());
789 inline size_t oat_hash(
const std::string & key)
noexcept
791 return oat_hash(key.data(), key.size());
796 inline size_t jsw_hash(
const std::string & key)
noexcept
798 return jsw_hash(key.data(), key.size());
801 inline size_t elf_hash(
const std::string & key)
noexcept
803 return elf_hash(key.data(), key.size());
829 std::uint64_t
key0 = 0x0706050403020100ULL,
852 seed ^=
h +
size_t{0x9e3779b97f4a7c15ULL} + (
seed << 12) + (
seed >> 4);
868 template <
typename T>
888 template <
typename T>
897 (std::is_trivially_copyable_v<T>
898 and not std::is_pointer_v<T>
899 and not std::is_floating_point_v<T>),
900 "Aleph_Hash<T>: T has no aleph_hash_value() in its namespace and cannot "
901 "be safely byte-hashed (pointer, floating-point, or non-trivially-copyable "
903 " size_t aleph_hash_value(const T &) noexcept;\n"
904 "in T's namespace, or specialize Aleph_Hash<T>."
941 if (key == 0.0f) key = 0.0f;
942 std::uint32_t bits = 0;
943 std::memcpy(&bits, &key,
sizeof(bits));
948 if (key == 0.0f) key = 0.0f;
949 std::uint32_t bits = 0;
950 std::memcpy(&bits, &key,
sizeof(bits));
960 if (key == 0.0) key = 0.0;
961 std::uint64_t bits = 0;
962 std::memcpy(&bits, &key,
sizeof(bits));
967 if (key == 0.0) key = 0.0;
968 std::uint64_t bits = 0;
969 std::memcpy(&bits, &key,
sizeof(bits));
999 template <
typename Key>
1000 requires (
not std::is_pointer_v<Key>
and
1001 not std::is_array_v<Key>
and
1002 not std::is_same_v<std::remove_cvref_t<Key>, std::string>)
1008 template <
typename Key>
1009 requires std::is_pointer_v<Key>
1028 template <
typename Key>
1029 requires (
not std::is_pointer_v<Key>
and
1030 not std::is_array_v<Key>
and
1031 not std::is_same_v<std::remove_cvref_t<Key>, std::string>)
1037 template <
typename Key>
1038 requires std::is_pointer_v<Key>
1054 template <
typename Key>
1060 template <
typename Key>
1077 template <
typename Key>
1078 requires (
not std::is_pointer_v<Key>
and
1079 not std::is_array_v<Key>
and
1080 not std::is_same_v<std::remove_cvref_t<Key>, std::string>)
1086 template <
typename Key>
1087 requires std::is_pointer_v<Key>
1103 template <
typename Key>
1109 template<
typename Key,
typename Data,
typename Fct>
1112 return fct(p.first);
1115 template <
typename K1,
typename K2>
1116 requires requires(
const K1 &
k1,
const K2 &
k2)
1128 template <
typename K1,
typename K2>
1129 requires requires(
const K1 &
k1,
const K2 &
k2)
1148 template <
typename K1,
typename K2>
1154 template <
typename K1,
typename K2>
Concept: T provides a semantic hash via ADL.
size_t sax_hash(const void *key, const size_t len) noexcept
Shift-Add-XOR hash (SAX hash)
size_t SuperFastHash(const void *key, size_t len, std::uint32_t seed=0) noexcept
Paul Hsieh super fast hash function.
size_t add_hash(const void *key, const size_t len) noexcept
Additive hash.
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 djb_hash(const void *key, const size_t len) noexcept
Bernstein's hash (DJB hash)
size_t jen_hash(const void *key, size_t length, unsigned initval) noexcept
Jenkins hash (lookup3)
size_t xor_hash(const void *key, const size_t len) noexcept
XOR hash.
size_t fnv_hash(const void *key, const size_t len) noexcept
FNV-1a hash.
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 rot_hash(const void *key, const size_t len) noexcept
Rotating hash.
size_t wyhash_hash(const void *key, size_t len, std::uint64_t seed) noexcept
wyhash non-cryptographic hash.
size_t elf_hash(const void *key, const size_t len) noexcept
ELF hash.
size_t oat_hash(const void *key, const size_t len) noexcept
One-at-a-Time hash (OAT hash)
Main namespace for Aleph-w library functions.
size_t map_hash_fct(Fct fct, const std::pair< Key, Data > &p) noexcept
and
Check uniqueness with explicit hash + equality functors.
size_t pair_snd_hash_fct(const std::pair< K1, K2 > &p) noexcept
void MurmurHash3_x86_32(const void *key, int len, uint32_t seed, void *out)
static constexpr std::uint32_t Aleph_Snd_Hash_Seed
Fixed seed used by the secondary hash function.
void MurmurHash3_x64_128(const void *key, const int len, const uint32_t seed, void *out)
size_t snd_hash_fct(const Key &key) noexcept
Secondary default hash: different distribution from dft_hash_fct.
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.
std::decay_t< typename HeadC::Item_Type > T
size_t aleph_hash_value(const AdversarialTranspositionKey< StateKey > &key) noexcept
size_t pair_snd_hash_ptr_fct(const std::pair< K1, K2 > &p) noexcept
size_t dft_hash_fct(const Key &key) noexcept
Primary default hash: best speed/quality trade-off.
void hash_combine(size_t &seed, size_t h) noexcept
Non-commutative hash combiner (Boost-style golden-ratio mix).
size_t snd_hash_ptr_fct(const Key &key) noexcept
size_t pair_dft_hash_fct(const std::pair< K1, K2 > &p) noexcept
void MurmurHash3_x86_128(const void *key, const int len, uint32_t seed, void *out)
const unsigned Default_Hash_Seed
std::uint16_t get16bits(const void *p) noexcept
size_t pair_dft_hash_ptr_fct(const std::pair< K1, K2 > &p) noexcept
size_t murmur3hash(const Key &key, std::uint32_t seed)
size_t dft_hash_ptr_fct(const Key &key) noexcept
size_t dft_seed_hash_ptr_fct(const Key &key, const unsigned long seed) noexcept
size_t operator()(double key) const noexcept
size_t operator()(double key, std::uint32_t seed) const noexcept
size_t operator()(float key, std::uint32_t seed) const noexcept
size_t operator()(float key) const noexcept
Primary hash functor used internally by dft_hash_fct / snd_hash_fct.
size_t operator()(const T &key, std::uint32_t seed) const noexcept
size_t operator()(const T &key) const noexcept