I want to calculate some stats about my hash function (like max/avg amount of collision). I wrote dummy hash function (which mapped all keys to 1) and waited to see number of max/avg collisions equal to amount of keys. But I have equal numbers for different functions. Can someone explain this? Code:
#include <iostream>
#include <unordered_set>
struct DummyHash
{
size_t operator()(int key) const
{
return static_cast<size_t>(1);
}
};
int main()
{
std::unordered_set<int, DummyHash> a;
std::unordered_set<int> b;
int c = 10000;
for (int i = 0; i < c; i++)
{
a.insert(i);
}
std::cout << "a ended" << std::endl;
for (int i = 0; i < c; i++)
{
b.insert(i);
}
std::cout << "b ended" << std::endl;
std::cout << "a = " << a.max_load_factor() << ' ' << a.load_factor() << ' '
<< a.max_size() << ' ' << a.max_bucket_count() << ' ' << a.bucket_count() << '\n';
std::cout << "b = " << b.max_load_factor() << ' ' << b.load_factor() << ' '
<< b.max_size() << ' ' << b.max_bucket_count() << ' ' << b.bucket_count() << '\n';
return 0;
}
Result:
a ended
b ended
a = 1 0.659065 768614336404564650 768614336404564650 15173
b = 1 0.659065 1152921504606846975 1152921504606846975 15173