void hashCollisionTest(int num_bits, int num_trials) { typedef uint64_t key_type; keyHandler<key_type> kh; size_t num_keys = 1 << (num_bits/2); std::unordered_set<key_type> keys, hashes; kh.generate_distinct_keys( num_keys, keys); int successes = 0; for(int trial = 0; trial < num_trials; ++trial) { std::unordered_set<key_type> hashes; for(auto it = keys.begin(); it != keys.end(); ++it) { key_type hash = HashUtil::MurmurHash64A( &(*it), sizeof(key_type), trial); hash = hashBits( hash, num_bits ); hashes.insert(hash); } successes += (hashes.size() == num_keys ); std::cout << "Success rate: " << (double) successes/(trial+1) << std::endl; } }
template <class T, class TT> inline U32 hash(TT* const& value) { return hashBits((U32)(UPTR)value); }
template <> inline U32 hash<Vec4f> (const Vec4f& value) { return hashBits(floatToBits(value.x), floatToBits(value.y), floatToBits(value.z), floatToBits(value.w)); }
template <> inline U32 hash<Vec4i> (const Vec4i& value) { return hashBits(value.x, value.y, value.z, value.w); }
template <> inline U32 hash<Vec2i> (const Vec2i& value) { return hashBits(value.x, value.y); }
template <> inline U32 hash<F32> (const F32& value) { return hashBits(floatToBits(value)); }
template <> inline U32 hash<U32> (const U32& value) { return hashBits(value); }
template <> inline U32 hash<S16> (const S16& value) { return hashBits(value); }
U32 computeHash() const { return hashBits(hash<String>(m_name), floatToBits(m_SAHNodeCost), floatToBits(m_SAHTriangleCost), hashBits(m_triBatchSize, m_nodeBatchSize, m_minLeafSize, m_maxLeafSize)); }