24 #include <boost/functional/hash.hpp> 25 #include <unordered_set> 30 using std::unordered_set;
56 operator== (
S const& os)
const 74 operator() (
S const& val)
const noexcept
77 return string_hasher(val.s_);
103 operator== (
V const& ov)
const 111 return boost::hash_value(v.v_);
140 checkHashFunctionInvocation();
141 checkHashtableUsage();
146 checkHashFunctionInvocation ()
148 string p(
"Путин"), pp(p);
153 boost::hash<string> boo_stringHasher;
156 boost::hash<V> boo_customHasher;
158 CHECK(0 < std_stringHasher(p));
159 CHECK(0 < boo_stringHasher(p));
160 CHECK(0 < std_customHasher(p));
161 CHECK(0 < boo_customHasher(p));
163 CHECK(std_stringHasher(p) == std_stringHasher(pp));
164 CHECK(boo_stringHasher(p) == boo_stringHasher(pp));
165 CHECK(std_customHasher(s) == std_customHasher(ss));
166 CHECK(boo_customHasher(v) == boo_customHasher(vv));
169 CHECK(std_stringHasher(p) == std_customHasher(s));
178 CHECK(0 < boo2std_crossHar(v));
181 CHECK(boo2std_crossHar(v) == boo_customHasher(v));
191 checkHashtableUsage ()
197 S s1{o1}, s2{o2}, s3{o3}, s4{o4}, s5{o2}, s6{o1};
198 V v1{o1}, v2{o2}, v3{o3}, v4{o4}, v5{o3}, v6{o2};
200 unordered_set<S> us{s1,s2,s3,s4,s5,s6};
201 unordered_set<V> uv{v1,v2,v3,v1,v5,v6};
203 CHECK(4 == us.size());
204 CHECK(3 == uv.size());
206 CHECK(contains (us, s1));
207 CHECK(contains (us, s2));
208 CHECK(contains (us, s3));
209 CHECK(contains (us, s4));
210 CHECK(contains (us, s5));
211 CHECK(contains (us, s6));
213 CHECK( contains (uv, v1));
214 CHECK( contains (uv, v2));
215 CHECK( contains (uv, v3));
216 CHECK(!contains (uv, v4));
217 CHECK( contains (uv, v5));
218 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
Simplistic 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