c++ STL之unordered_map

1.1 Features

  1. Associativity: retrieve value by key, not by absolute address (unlike sequential containers)
  2. Disorder: use hash table storage, internal disorder
  3. Map : each value corresponds to a key value
  4. Key Uniqueness: No two elements have the same key
  5. Dynamic memory management: use the memory management model to dynamically manage the required memory space

  

2.1 Iterators

The iterator of unordered_map is a pointer to this element, and its value is obtained through the iterator.

unordered_map<Key,T>::iterator it;
(*it).first;             // the key value (of type Key)
(*it).second;            // the mapped value (of type T)
(*it);

Its keys are the first and second properties of the iterator, respectively

it->first;               // same as (*it).first   (the key value)
it->second;              // same as (*it).second  (the mapped value) 

So there is a difference between '.' and '->' : -> is an indirect address value operator; . is a direct address value operator.

 

Less runtime and occupancy compared to map

 

Reference article:

https://blog.csdn.net/hk2291976/article/details/51037095

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325345444&siteId=291194637