49# include <type_traits>
114 const auto *p =
static_cast<const unsigned char *
>(key);
117 for (
size_t i = 0; i < len; i++)
133 inline size_t xor_hash(
const void * key,
const size_t len)
noexcept
135 const auto *p =
static_cast<const unsigned char *
>(key);
138 for (
size_t i = 0; i < len; i++)
154 inline size_t rot_hash(
const void * key,
const size_t len)
noexcept
156 const auto *p =
static_cast<const unsigned char *
>(key);
159 for (
size_t i = 0; i < len; i++)
160 h = (
h << 4) ^ (
h >> 28) ^ p[i];
174 inline size_t djb_hash(
const void * key,
const size_t len)
noexcept
176 const auto *p =
static_cast<const unsigned char *
>(key);
179 for (
size_t i = 0; i < len; i++)
194 inline size_t sax_hash(
const void * key,
const size_t len)
noexcept
196 const auto *p =
static_cast<const unsigned char *
>(key);
199 for (
size_t i = 0; i < len; i++)
200 h ^= (
h << 5) + (
h >> 2) + p[i];
214 inline size_t fnv_hash(
const void * key,
const size_t len)
noexcept
216 const auto *p =
static_cast<const unsigned char *
>(key);
217 size_t h = 2166136261;
219 for (
size_t i = 0; i < len; i++)
220 h = (
h * 16777619) ^ p[i];
234 inline size_t oat_hash(
const void * key,
const size_t len)
noexcept
236 const auto *p =
static_cast<const unsigned char *
>(key);
239 for (
size_t i = 0; i < len; i++)
275 extern size_t jsw_hash(
const void * key,
size_t len)
noexcept;
290 inline size_t elf_hash(
const void * key,
const size_t len)
noexcept
292 const auto *p =
static_cast<const unsigned char *
>(key);
295 for (
size_t i = 0; i < len; i++)
298 size_t g =
h & 0xf0000000L;
318 extern size_t jen_hash(
const void *key,
size_t len,
unsigned initval)
noexcept;
352# if defined(__x86_64__) || defined(__aarch64__) \
353 || defined(_M_X64) || defined(_M_ARM64)
354# define ALEPH_HASH_USE_MURMUR3_64 1
356# define ALEPH_HASH_USE_MURMUR3_64 0
359 template <
typename Key>
360 requires std::is_trivially_copyable_v<Key>
363# if ALEPH_HASH_USE_MURMUR3_64
367 std::uint32_t buf = 0;
380 const size_t len =
strlen(key);
381# if ALEPH_HASH_USE_MURMUR3_64
385 std::uint32_t buf = 0;
397# if ALEPH_HASH_USE_MURMUR3_64
401 std::uint32_t buf = 0;
423 memcpy(&val, p,
sizeof(val));
437 const auto * data =
static_cast<const unsigned char *
>(key);
438 std::uint32_t hash =
static_cast<std::uint32_t
>(len) ^
seed;
440 if (len <= 0 || data ==
nullptr)
441 return static_cast<size_t>(hash);
443 const int rem = len & 3;
444 const size_t nblocks = len >> 2;
447 for (
size_t i = 0; i <
nblocks; ++i)
450 const std::uint32_t
tmp = (
static_cast<std::uint32_t
>(
get16bits(data+2)) << 11) ^ hash;
451 hash = (hash << 16) ^
tmp;
462 hash ^=
static_cast<signed char>(data[
sizeof(
uint16_t)]) << 18;
471 hash +=
static_cast<signed char>(*data);
487 return static_cast<size_t>(hash);
539 std::uint64_t
key0 = 0x0706050403020100ULL,
549 template <
typename Key>
550 requires std::is_trivially_copyable_v<Key>
556 template <
typename Key>
557 requires std::is_trivially_copyable_v<Key>
563 template <
typename Key>
564 requires std::is_trivially_copyable_v<Key>
570 template <
typename Key>
571 requires std::is_trivially_copyable_v<Key>
577 template <
typename Key>
578 requires std::is_trivially_copyable_v<Key>
584 template <
typename Key>
585 requires std::is_trivially_copyable_v<Key>
593 template <
typename Key>
594 requires std::is_trivially_copyable_v<Key>
600 template <
typename Key>
601 requires std::is_trivially_copyable_v<Key>
607 template <
typename Key>
608 requires std::is_trivially_copyable_v<Key>
614 template <
typename Key>
615 requires (std::is_trivially_copyable_v<Key>
and
616 (
not std::is_pointer_v<Key>)
and (
not std::is_array_v<Key>))
622 template <
typename Key>
623 requires std::is_trivially_copyable_v<Key>
630 template <
typename Key>
631 requires std::is_trivially_copyable_v<Key>
638 template <
typename Key>
639 requires std::is_trivially_copyable_v<Key>
641 std::uint64_t
key0 = 0x0706050403020100ULL,
649 auto p =
reinterpret_cast<const unsigned char *
>(key);
660 auto p =
reinterpret_cast<const unsigned char *
>(key);
671 auto p =
reinterpret_cast<const unsigned char *
>(key);
675 h = (
h << 4) ^(
h >> 28) ^ *p++;
682 auto p =
reinterpret_cast<const unsigned char *
>(key);
693 auto p =
reinterpret_cast<const unsigned char *
>(key);
697 h ^= (
h << 5) +(
h >> 2) + *p++;
704 auto p =
reinterpret_cast<const unsigned char *
>(key);
705 size_t h = 2166136261;
708 h = (
h * 16777619) ^ *p++;
715 auto p =
reinterpret_cast<const unsigned char *
>(key);
737 extern size_t jsw_hash(
const char * key)
noexcept;
741 auto p =
reinterpret_cast<const unsigned char *
>(key);
747 size_t g =
h & 0xf0000000L;
776 std::uint64_t
key0 = 0x0706050403020100ULL,
786 inline size_t add_hash(
const std::string & key)
noexcept
788 return add_hash(key.data(), key.size());
791 inline size_t xor_hash(
const std::string & key)
noexcept
793 return xor_hash(key.data(), key.size());
796 inline size_t rot_hash(
const std::string & key)
noexcept
798 return rot_hash(key.data(), key.size());
801 inline size_t djb_hash(
const std::string & key)
noexcept
803 return djb_hash(key.data(), key.size());
806 inline size_t sax_hash(
const std::string & key)
noexcept
808 return sax_hash(key.data(), key.size());
811 inline size_t fnv_hash(
const std::string & key)
noexcept
813 return fnv_hash(key.data(), key.size());
816 inline size_t oat_hash(
const std::string & key)
noexcept
818 return oat_hash(key.data(), key.size());
823 inline size_t jsw_hash(
const std::string & key)
noexcept
825 return jsw_hash(key.data(), key.size());
828 inline size_t elf_hash(
const std::string & key)
noexcept
830 return elf_hash(key.data(), key.size());
856 std::uint64_t
key0 = 0x0706050403020100ULL,
879 seed ^=
h +
size_t{0x9e3779b97f4a7c15ULL} + (
seed << 12) + (
seed >> 4);
895 template <
typename T>
915 template <
typename T>
924 (std::is_trivially_copyable_v<T>
925 and not std::is_pointer_v<T>
926 and not std::is_floating_point_v<T>),
927 "Aleph_Hash<T>: T has no aleph_hash_value() in its namespace and cannot "
928 "be safely byte-hashed (pointer, floating-point, or non-trivially-copyable "
930 " size_t aleph_hash_value(const T &) noexcept;\n"
931 "in T's namespace, or specialize Aleph_Hash<T>."
968 if (key == 0.0f) key = 0.0f;
969 std::uint32_t bits = 0;
970 std::memcpy(&bits, &key,
sizeof(bits));
975 if (key == 0.0f) key = 0.0f;
976 std::uint32_t bits = 0;
977 std::memcpy(&bits, &key,
sizeof(bits));
987 if (key == 0.0) key = 0.0;
988 std::uint64_t bits = 0;
989 std::memcpy(&bits, &key,
sizeof(bits));
994 if (key == 0.0) key = 0.0;
995 std::uint64_t bits = 0;
996 std::memcpy(&bits, &key,
sizeof(bits));
1026 template <
typename Key>
1027 requires (
not std::is_pointer_v<Key>
and
1028 not std::is_array_v<Key>
and
1029 not std::is_same_v<std::remove_cvref_t<Key>, std::string>)
1035 template <
typename Key>
1036 requires std::is_pointer_v<Key>
1055 template <
typename Key>
1056 requires (
not std::is_pointer_v<Key>
and
1057 not std::is_array_v<Key>
and
1058 not std::is_same_v<std::remove_cvref_t<Key>, std::string>)
1064 template <
typename Key>
1065 requires std::is_pointer_v<Key>
1081 template <
typename Key>
1087 template <
typename Key>
1104 template <
typename Key>
1105 requires (
not std::is_pointer_v<Key>
and
1106 not std::is_array_v<Key>
and
1107 not std::is_same_v<std::remove_cvref_t<Key>, std::string>)
1113 template <
typename Key>
1114 requires std::is_pointer_v<Key>
1130 template <
typename Key>
1136 template<
typename Key,
typename Data,
typename Fct>
1139 return fct(p.first);
1142 template <
typename K1,
typename K2>
1143 requires requires(
const K1 &
k1,
const K2 &
k2)
1155 template <
typename K1,
typename K2>
1156 requires requires(
const K1 &
k1,
const K2 &
k2)
1175 template <
typename K1,
typename K2>
1181 template <
typename K1,
typename K2>
size_t size_t int32_t * out
Concept: T provides a semantic hash via ADL.
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 sax_hash(const void *key, const size_t len) noexcept
Shift-Add-XOR hash (SAX hash)
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 SuperFastHash(const void *key, const size_t len, std::uint32_t seed=0) noexcept
Paul Hsieh super fast hash function.
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
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.
and
Check uniqueness with explicit hash + equality functors.
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