fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. int main()
  5. {
  6. unordered_map<ll, ll> umap;
  7. ll num = 2e7;
  8. ll val;
  9.  
  10. for (ll i = 0; i < num; ++i)
  11. {
  12. val = rand() % (10000009);
  13. cin >> umap[i];
  14. }
  15.  
  16. ll n = umap.bucket_count();
  17. cout << "umap has " << n << " buckets.\n\n";
  18.  
  19. ll collisions = 0;
  20. for (ll i = 0; i < n; i++) {
  21. if(umap.bucket_size(i) > 1)
  22. {
  23. cout << "Bucket " << i << " has "
  24. << umap.bucket_size(i) << " elements.\n";
  25. collisions++;
  26. }
  27. }
  28.  
  29. cout << "Total Collisions: "<< collisions << "\n";
  30. return 0;
  31. }
  32.  
Success #stdin #stdout 2.21s 989796KB
stdin
Standard input is empty
stdout
umap has 36473443 buckets.

Total Collisions: 0