I think you misunderstood the guarantees of complexity of std::unordered_mapinserting, deleting and searching. In the worst case, O(size())it is only mentioned if you implement a terrible hash function for a type Keythat generates many collisions, but different keys are not compared with equal ones.
Say what you have
struct terrible_hash
{
std::size_t operator()(int i) const
{ return 42; }
};
std::unordered_map<int, foo, terrible_hash> m;
All inserts of new keys into the above map will be O(m.size()), because the function will be forced to search linearly through each element, since they all have the same value.
Given an acceptable hash function, these operations should be (amortized) constant time.
string 128- (UUID) ; , , , . , :
hash<string> . , / , VS2013:
size_t _Val = 14695981039346656037ULL;
for (size_t _Next = 0; _Next < _Count; ++_Next)
{
_Val ^= (size_t)_First[_Next];
_Val *= 1099511628211ULL;
}
return _Val;
128- 64- . , 64- .
template <class T>
inline void hash_combine(std::size_t& seed, const T& v)
{
std::hash<T> hasher;
seed ^= hasher(v) + 0x9e3779b9 + (seed<<6) + (seed>>2);
}
boost::hash_combine. , MSVC std::hash<uint64_t>, 64- unsigned char * , , , .
, , , .