fork(8) download
  1. #include <vector>
  2. #include <assert.h>
  3. #include <algorithm>
  4. #include <unordered_map>
  5. #include <iostream>
  6.  
  7. class Node {
  8. public:
  9. int a, b, c;
  10. Node(std::vector<int> v) {
  11. assert(v.size() > 2);
  12. std::sort(begin(v), end(v));
  13. a = v[0]; b = v[1]; c = v[2];
  14. }
  15. };
  16.  
  17. int main() {
  18. auto hash = [](const Node& n){
  19. size_t res = 17;
  20. res = res * 31 + std::hash<int>()(n.a);
  21. res = res * 31 + std::hash<int>()(n.b);
  22. res = res * 31 + std::hash<int>()(n.c);
  23. return res;
  24. };
  25. auto equal = [](const Node& n1, const Node& n2){
  26. return n1.a == n2.a && n1.b == n2.b && n1.c == n2.c;
  27. };
  28. std::unordered_map<Node, int, decltype(hash), decltype(equal)> m(8, hash, equal);
  29.  
  30. std::vector<int> v {3, 8, 9};
  31. Node n(v);
  32. m[n] = 0;
  33.  
  34. for (auto const &nd : m)
  35. std::cout << nd.first.a << ", " << nd.first.b << ", " << nd.first.c << ", " << nd.second << std::endl;
  36.  
  37. return 0;
  38. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
3, 8, 9, 0