In general, for this task you will need two hash tables. As you know, hash tables give you a key at the expected constant time. Value search Iterates through the entire data structure, since the value information is not encoded in the hash lookup table.
: () . , "". , .
-: ++ 11 std::unordererd_map.
(, , , const-correctness, ..):
std::unordered_map<K,T> kvMap;
std::unordered_map<T,K> vkMap;
void insert(std::pair<K,T> item) {
kvMap.insert(item);
vkMap.insert(std::make_pair(item.second, item.first));
}
T valueForKey(K key) {
return kvMap[key];
}
K keyForValue(T value) {
return vkMap[value];
}
++ 11 "" - , "" -. .
: , , "". - , ( ) -, -.