fork download
  1. #include <iostream>
  2. #include <unordered_set>
  3.  
  4. namespace std {
  5. template<>
  6. struct hash<unordered_multiset<int>> {
  7. typedef unordered_multiset<int> argument_type;
  8. typedef std::size_t result_type;
  9.  
  10. const result_type BASE = static_cast<result_type>(0xA67);
  11.  
  12. result_type log_pow(result_type ex) const
  13. {
  14. result_type res = 1;
  15. result_type base = BASE;
  16. while (ex > 0)
  17. {
  18. if (ex % 2)
  19. res = res * base;
  20. base *= base;
  21. ex /= 2;
  22. }
  23. return res;
  24. }
  25.  
  26. result_type operator()(argument_type const & val) const {
  27. result_type h = 0;
  28. for (const int& el : val) {
  29. h += log_pow(el);
  30. }
  31. return h;
  32. }
  33. };
  34. };
  35.  
  36. int main() {
  37. std::unordered_set<std::unordered_multiset<int>> mySet;
  38. std::unordered_multiset<int> set1{1,2,3,4};
  39. std::unordered_multiset<int> set2{1,1,2,2,3,3,4,4};
  40. std::cout << "Hash 1: " << std::hash<std::unordered_multiset<int>>()(set1) << std::endl;
  41. std::cout << "Hash 2: " << std::hash<std::unordered_multiset<int>>()(set2) << std::endl;
  42. return 0;
  43. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
Hash 1: 2290886192
Hash 2: 286805088