using c++ std’s unordered_map i want to map an integer triplet to a single integer, i usually don’t use hash tables(didn’t know they were so cool), but i don’t know the right approach in this case, using the default hashing function should i map the triplets directly (something like < < int,int >,int >->int)
std::unordered_map <std::make_pair <make_pair <int,int>,int>,int> hash;
or maybe use a function to map the triplet to a single value and the use that value with the default function?
int mapping(int a, int b, int c){
}
std::unordered_map <int,int> hash;
both approaches work but i’d like to know wich one is the most efficient one. thank you
First off, you would use
std::tuple<int, int, int>as the key type.Next, you need a way to hash a tuple given that you can hash each element. There is a function called
hash_combinein Boost that does that, but for reasons unclear to me, that one was not included in the standard. Anyway, here it goes: