33 #include <boost/functional/hash.hpp> 34 #include <unordered_set> 39 using std::unordered_set;
65 operator== (
S const& os)
const 83 operator() (
S const& val)
const noexcept
86 return string_hasher(val.s_);
112 operator== (
V const& ov)
const 120 return boost::hash_value(v.v_);
149 checkHashFunctionInvocation();
150 checkHashtableUsage();
155 checkHashFunctionInvocation ()
157 string p(
"Путин"), pp(p);
162 boost::hash<string> boo_stringHasher;
165 boost::hash<V> boo_customHasher;
167 CHECK(0 < std_stringHasher(p));
168 CHECK(0 < boo_stringHasher(p));
169 CHECK(0 < std_customHasher(p));
170 CHECK(0 < boo_customHasher(p));
172 CHECK(std_stringHasher(p) == std_stringHasher(pp));
173 CHECK(boo_stringHasher(p) == boo_stringHasher(pp));
174 CHECK(std_customHasher(s) == std_customHasher(ss));
175 CHECK(boo_customHasher(v) == boo_customHasher(vv));
178 CHECK(std_stringHasher(p) == std_customHasher(s));
187 CHECK(0 < boo2std_crossHar(v));
190 CHECK(boo2std_crossHar(v) == boo_customHasher(v));
200 checkHashtableUsage ()
206 S s1{o1}, s2{o2}, s3{o3}, s4{o4}, s5{o2}, s6{o1};
207 V v1{o1}, v2{o2}, v3{o3}, v4{o4}, v5{o3}, v6{o2};
209 unordered_set<S> us{s1,s2,s3,s4,s5,s6};
210 unordered_set<V> uv{v1,v2,v3,v1,v5,v6};
212 CHECK(4 == us.size());
213 CHECK(3 == uv.size());
215 CHECK(contains (us, s1));
216 CHECK(contains (us, s2));
217 CHECK(contains (us, s3));
218 CHECK(contains (us, s4));
219 CHECK(contains (us, s5));
220 CHECK(contains (us, s6));
222 CHECK( contains (uv, v1));
223 CHECK( contains (uv, v2));
224 CHECK( contains (uv, v3));
225 CHECK(!contains (uv, v4));
226 CHECK( contains (uv, v5));
227 CHECK( contains (uv, v6));
Custom-Datatype 2: uses boost::hash extension point.
Primary class template for std::hash.
Implementation namespace for support and library code.
string randStr(size_t len)
create garbage string of given length
Simple test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
Helper to use a single extension point for specialised hash functions.
A collection of frequently used helper functions to support unit testing.
HashVal hash_value(QueryText const &entry)
support using queries in hashtables.
Custom-Datatype 1: uses std::hash extension point.
bool contains(SEQ const &cont, typename SEQ::const_reference val)
shortcut for brute-force containment test in any sequential container