24 static const std::vector<long>
28 static const std::vector<double>
29 dbl_test{ 0, 1.0, 1.000001, 1.12e12, 1.12001e12, 1.12001e-12
30 -1.0, -1.000001, -1.12e12, -1.12001e12, -1.12001e-12};
32 static std::vector<const char *>
48 std::vector<bphash::HashValue> & all_hashes)
53 const char * type =
typeid(T).name();
57 cout <<
"Testing type: " << type <<
"\n";
60 <<
" conv: " << convert_hash<size_t>(val_hash) <<
"\n";
62 all_hashes.push_back(move(val_hash));
67 template<
typename To,
typename From>
70 std::vector<bphash::HashValue> & all_hashes)
72 for(
const auto & it : vals)
73 test_single(static_cast<To>(it), htype, all_hashes);
77 template<
typename To,
typename From>
80 std::vector<bphash::HashValue> & all_hashes)
82 std::vector<To *> new_rptrs;
83 std::vector<std::unique_ptr<To>> new_uptrs;
84 std::vector<std::shared_ptr<To>> new_sptrs;
86 for(
const auto & it : vals)
88 To new_val =
static_cast<To
>(it);
89 new_rptrs.push_back(
new To(new_val));
90 new_uptrs.push_back(std::unique_ptr<To>(
new To(new_val)));
91 new_sptrs.push_back(std::shared_ptr<To>(
new To(new_val)));
94 for(
const auto & it : new_rptrs)
97 for(
const auto & it : new_uptrs)
100 for(
const auto & it : new_sptrs)
103 for(
const auto & it : new_rptrs)
108 template<
typename To,
typename From,
size_t N>
111 std::vector<bphash::HashValue> & all_hashes)
113 std::array<To, N> arr_values;
116 for(
size_t i = 0; i < N; i++)
118 arr_values[i] =
static_cast<To
>(vec.at(i));
119 plain_arr[i] =
static_cast<To
>(vec.at(i));
129 #define HANDLE_TEST_ARRAY(N) \ 131 test_array_helper<To, From, N>(values, htype, all_hashes); \ 134 template<
typename To,
typename From>
137 std::vector<bphash::HashValue> & all_hashes)
140 for(
size_t i = 0; i < values.size(); i++)
170 #undef HANDLE_TEST_ARRAY 173 template<
typename To,
typename From>
176 std::vector<bphash::HashValue> & all_hashes)
179 for(
size_t i = 0; i <= values.size(); i++)
181 std::vector<To> new_vec{values.begin(), values.begin() + i};
182 std::list<To> new_list{values.begin(), values.begin() + i};
183 std::unordered_set<To> new_uset{values.begin(), values.begin() + i};
184 std::forward_list<To> new_flist{values.begin(), values.begin() + i};
185 std::set<To> new_set{values.begin(), values.begin() + i};
197 template<
typename To,
typename From>
200 std::vector<bphash::HashValue> & all_hashes)
202 test_values<To>(values, htype, all_hashes);
203 test_pointers<To>(values, htype, all_hashes);
204 test_arrays<To>(values, htype, all_hashes);
205 test_containers<To>(values, htype, all_hashes);
210 template<
typename To1,
typename To2,
211 typename From1,
typename From2>
213 const std::vector<From2> & values2,
215 std::vector<bphash::HashValue> & all_hashes)
217 typedef std::tuple<To1, To2> To12;
218 typedef std::pair<To1, To2> ToPair12;
220 std::vector<To12> tup12;
221 std::vector<ToPair12> pair12;
223 for(
size_t i = 0; i < values1.size(); i++)
224 for(
size_t j = 0; j < values2.size(); j++)
226 tup12.push_back(std::make_tuple<To1, To2>(
227 static_cast<To1>(values1.at(i)),
228 static_cast<To2>(values2.at(j))));
230 pair12.push_back(std::make_pair<To1, To2>(
231 static_cast<To1>(values1.at(i)),
232 static_cast<To2>(values2.at(j))));
236 test_values <To12>(tup12, htype, all_hashes);
237 test_pointers<To12>(tup12, htype, all_hashes);
238 test_arrays <To12>(tup12, htype, all_hashes);
239 test_values <ToPair12>(pair12, htype, all_hashes);
240 test_pointers<ToPair12>(pair12, htype, all_hashes);
241 test_arrays <ToPair12>(pair12, htype, all_hashes);
245 for(
size_t i = 0; i <= tup12.size(); i++)
247 std::vector<To12> new_vec{tup12.begin(), tup12.begin() + i};
248 std::list<To12> new_list{tup12.begin(), tup12.begin() + i};
252 for(
size_t i = 0; i <= pair12.size(); i++)
254 std::vector<ToPair12> new_vec{pair12.begin(), pair12.begin() + i};
255 std::list<ToPair12> new_list{pair12.begin(), pair12.begin() + i};
void test_arrays(const std::vector< From > &values, bphash::HashType htype, std::vector< bphash::HashValue > &all_hashes)
void test_single(const T &val, bphash::HashType htype, std::vector< bphash::HashValue > &all_hashes)
void test_tuples_2(const std::vector< From1 > &values1, const std::vector< From2 > &values2, bphash::HashType htype, std::vector< bphash::HashValue > &all_hashes)
HashValue truncate_hash(const HashValue &hash, size_t nbytes)
Truncate the hash to a given number of bytes.
std::string hash_to_string(const HashValue &hash)
Return a string representation of a hash.
void test_array_helper(const std::vector< From > &vec, bphash::HashType htype, std::vector< bphash::HashValue > &all_hashes)
A class that hashes objects (header)
static const std::vector< double > dbl_test
HashValue make_hash(HashType type, const Targs &...objs)
Convenience function for hashing objects in a single function call.
HashType
Type of hash to use.
std::vector< uint8_t > HashValue
Stores the value of a hash.
void test_pointers(const std::vector< From > &vals, bphash::HashType htype, std::vector< bphash::HashValue > &all_hashes)
PointerWrapper< T > hash_pointer(const T *ptr, size_t len=1)
Wrap a raw pointer so that it can be hashed.
#define HANDLE_TEST_ARRAY(N)
void test_values(const std::vector< From > &vals, bphash::HashType htype, std::vector< bphash::HashValue > &all_hashes)
void test_containers(const std::vector< From > &values, bphash::HashType htype, std::vector< bphash::HashValue > &all_hashes)
static const std::vector< long > int_test
A convenience header that includes all the types supported by bphash.
static std::vector< const char * > str_test
void test_fundamental(const std::vector< From > &values, bphash::HashType htype, std::vector< bphash::HashValue > &all_hashes)