52#include <gtest/gtest.h>
221 unsigned seed = 12345;
229 auto h4 =
jen_hash((
void*)test_std_string.c_str(), test_std_string.size(),
seed);
253 unsigned long seed = 42;
414 char data1[] = {1, 0, 2, 0, 3};
415 char data2[] = {1, 0, 2, 0, 3};
432 const char*
s1 =
"hello";
433 const char*
s2 =
"world";
434 const char*
s3 =
"hello1";
468 const std::string key =
"test_key";
507 int arr1[] = {1, 2, 3, 4, 5};
508 int arr2[] = {1, 2, 3, 4, 5};
509 int arr3[] = {1, 2, 3, 4, 6};
538 s1.a = 1;
s1.b = 2.5;
s1.c =
'x';
539 s2.a = 1;
s2.b = 2.5;
s2.c =
'x';
540 s3.a = 1;
s3.b = 2.5;
s3.c =
'y';
571 double val = 3.14159;
584 long long val = 9223372036854775807LL;
599 std::pair<int, int> p1{1, 2};
600 std::pair<int, int> p2{1, 2};
601 std::pair<int, int> p3{2, 1};
614 std::pair<std::string, std::string> p1{
"hello",
"world"};
615 std::pair<std::string, std::string> p2{
"hello",
"world"};
625 std::pair<char, std::string> p1{
'a',
"world"};
626 std::pair<std::string, char> p2{
"hello",
'z'};
634 std::pair<char, std::string> p1{
'a',
"world"};
635 std::pair<std::string, char> p2{
"hello",
'z'};
713 std::mt19937
gen(42);
714 std::uniform_int_distribution<>
len_dist(5, 20);
715 std::uniform_int_distribution<>
char_dist(
'a',
'z');
717 for (
size_t i = 0; i <
NUM_KEYS; ++i)
722 for (
int j = 0; j < len; ++j)
724 keys.push_back(std::move(s));
732 std::set<size_t>
unique_hashes(hashes.begin(), hashes.end());
734 static_cast<double>(hashes.size());
742 std::vector<size_t> hashes;
743 hashes.reserve(NUM_KEYS);
744 for (
const auto& key :
keys)
747 double uniqueness = measureHashUniqueness(hashes);
748 EXPECT_GT(uniqueness, 0.90) <<
"FNV hash uniqueness: " << uniqueness;
753 std::vector<size_t> hashes;
754 hashes.reserve(NUM_KEYS);
755 for (
const auto& key :
keys)
758 double uniqueness = measureHashUniqueness(hashes);
759 EXPECT_GT(uniqueness, 0.90) <<
"OAT hash uniqueness: " << uniqueness;
764 std::vector<size_t> hashes;
765 hashes.reserve(NUM_KEYS);
766 for (
const auto& key :
keys)
769 double uniqueness = measureHashUniqueness(hashes);
770 EXPECT_GT(uniqueness, 0.90) <<
"SuperFastHash uniqueness: " << uniqueness;
775 std::vector<size_t> hashes;
776 hashes.reserve(NUM_KEYS);
777 for (
const auto& key :
keys)
780 double uniqueness = measureHashUniqueness(hashes);
781 EXPECT_GT(uniqueness, 0.90) <<
"Jenkins hash uniqueness: " << uniqueness;
786 std::vector<size_t> hashes;
787 hashes.reserve(NUM_KEYS);
788 for (
const auto& key :
keys)
791 double uniqueness = measureHashUniqueness(hashes);
792 EXPECT_GT(uniqueness, 0.90) <<
"MurmurHash3 uniqueness: " << uniqueness;
797 std::vector<size_t> hashes;
798 hashes.reserve(NUM_KEYS);
799 for (
const auto& key :
keys)
802 double uniqueness = measureHashUniqueness(hashes);
803 EXPECT_GT(uniqueness, 0.90) <<
"dft_hash_fct uniqueness: " << uniqueness;
808 std::vector<size_t> hashes;
809 hashes.reserve(NUM_KEYS);
810 for (
const auto& key :
keys)
813 double uniqueness = measureHashUniqueness(hashes);
814 EXPECT_GT(uniqueness, 0.90) <<
"xxhash64 uniqueness: " << uniqueness;
819 std::vector<size_t> hashes;
820 hashes.reserve(NUM_KEYS);
821 for (
const auto& key :
keys)
824 double uniqueness = measureHashUniqueness(hashes);
825 EXPECT_GT(uniqueness, 0.90) <<
"wyhash uniqueness: " << uniqueness;
830 std::vector<size_t> hashes;
831 hashes.reserve(NUM_KEYS);
832 for (
const auto& key :
keys)
835 double uniqueness = measureHashUniqueness(hashes);
836 EXPECT_GT(uniqueness, 0.90) <<
"siphash24 uniqueness: " << uniqueness;
863 unsigned char data1[16] = {0};
864 unsigned char data2[16] = {0};
873 <<
"Jenkins hash has poor avalanche property";
878 unsigned char data1[16] = {0};
879 unsigned char data2[16] = {0};
887 <<
"MurmurHash3 has poor avalanche property";
892 unsigned char data1[16] = {0};
893 unsigned char data2[16] = {0};
901 <<
"xxhash64 has poor avalanche property";
906 unsigned char data1[16] = {0};
907 unsigned char data2[16] = {0};
915 <<
"wyhash has poor avalanche property";
920 unsigned char data1[16] = {0};
921 unsigned char data2[16] = {0};
929 <<
"siphash24 has poor avalanche property";
934 unsigned char data1[16] = {0};
935 unsigned char data2[16] = {0};
943 <<
"One-at-a-Time hash has poor avalanche property";
971 static constexpr std::array<std::uint64_t, 16>
expected =
973 0x726fdb47dd0e0e31ULL, 0x74f839c593dc67fdULL,
974 0x0d6c8009d9a94f5aULL, 0x85676696d7fb7e2dULL,
975 0xcf2794e0277187b7ULL, 0x18765564cd99a68dULL,
976 0xcbc9466e58fee3ceULL, 0xab0200f58b01d137ULL,
977 0x93f5f5799a932462ULL, 0x9e0082df0ba9e4b0ULL,
978 0x7a5dbbc594ddb9f3ULL, 0xf4b32f46226bada7ULL,
979 0x751e8fbc860ee5fbULL, 0x14ea5627c0843d90ULL,
980 0xf723ca908e7af2eeULL, 0xa129ca6149be45e5ULL
983 std::array<unsigned char, 16> msg = {};
984 for (
size_t i = 0; i < msg.size(); ++i)
985 msg[i] =
static_cast<unsigned char>(i);
987 for (
size_t len = 0; len <
expected.size(); ++len)
990 0x0706050403020100ULL,
991 0x0f0e0d0c0b0a0908ULL),
992 static_cast<size_t>(
expected[len]));
1000 const std::string data =
"test";
1008 const std::string key =
"test_key";
1021 unsigned int unsigned_val =
static_cast<unsigned int>(-1);
1034 const char* ptr =
"hello";
1035 std::string str =
"hello";
1064 std::string
large_data(10 * 1024 * 1024,
'x');
1088 for (
int i = 0; i < 100000; ++i)
static int bitDifference(size_t h1, size_t h2)
const std::string test_std_string
double measureHashUniqueness(const std::vector< size_t > &hashes)
static constexpr size_t NUM_KEYS
std::vector< std::string > keys
const std::string empty_std_string
const char * empty_string
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.
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)
TEST_F(HashConsistencyTest, AddHashConsistency)
testing::Environment *const hash_env
Main namespace for Aleph-w library functions.
size_t pair_snd_hash_fct(const std::pair< K1, K2 > &p) noexcept
static constexpr std::uint32_t Aleph_Snd_Hash_Seed
Fixed seed used by the secondary hash function.
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.
bool diff(const C1 &c1, const C2 &c2, Eq e=Eq())
Check if two containers differ.
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
const unsigned Default_Hash_Seed
size_t murmur3hash(const Key &key, std::uint32_t seed)
size_t dft_hash_ptr_fct(const Key &key) noexcept
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
T sum(const Container &container, const T &init=T{})
Compute sum of all elements.
size_t aleph_hash_value(const Point3D &p) noexcept
Point3D(double x, double y, double z, std::string l)