The .NET Framework has a dictionary <TKey, TValue> class, which is implemented as a hash table and provides data in constant time (O (1)). I am looking for a similar implementation in C ++. I know about std :: map, but this data search requires logarithmic time. Is there a good hash table implementation in C ++ that will receive data in constant time?
If I write my own, how will I calculate the hash code for the key? Like .NET, I was thinking of the GetHashCode () method for types.
template<typename TKey,typename TVal>
class Dictionary
{
public:
void Add(TKey key, TVal val){
int hashCode = key.GetHashCode();
}
}
If I liked it above, and this type of key does not have the GetHashCode () method, the compiler will throw an error. But this method will not work if the key is a primitive type of type int. I may need to write a wrapper for int, providing GetHashCode.
, ++- ?
?