unordered_mapã«pairãçªã£è¾¼ãã ãåããªãã¦æ©ãã ãã§ãããèªåã®ä½ã£ãã¯ã©ã¹ã ãã§ãªãpairã¨ãtupleã§ãhashãå®ç¾©ããªãã¨åããªãã¿ããã§ãã
namespace stdã«æå®ããæ¹æ³ã¨ããã·ã¥é¢æ°ãunordered_mapã«æ¸¡ãæ¹æ³ã®2種é¡ãããã¿ããã§ãããã¨ããããstdã®ä¸ã«ä½ã£ã¦ãã¾ãä¾ã
#include <unordered_map> #include <iostream> namespace std { template <> class hash<std::pair<int, int>> { public: size_t operator()(const std::pair<int, int>& x) const{ return hash<int>()(x.first) ^ hash<int>()(x.second); } }; } int main(void) { std::unordered_map<std::pair<int, int>, int> umap; umap[std::make_pair(0, 0)] = 0; std::cout << umap[std::make_pair(0, 0)] << std::endl; return 0; }
âã®Wikipediaã®è¨äºãå ã«æ¸ãã¦ãã¾ãããhashé¢æ°ã®å®ç¾©ã¯XORã§ãããã§ããããï¼
ããã¨ãç´ æ°ãããã¦è¶³ããããã¦modããã»ãããããã§ãããï¼