With the establishment of C++0X standard, C + + standard library also finally has a hash table this thing.
For a long time, the STL has only provided <map> as a container to store the corresponding relationship, the interior is usually implemented with a red-black tree, which is said to be due to various operations of the two-fork balance tree (such as the red-black tree), insert, delete, search, etc., are stable time complexity, that is, O (log n); But for the hash table, , because the performance problems caused by Re-hash can not be avoided, even if the performance of the hash table is very good in most cases, the instability caused by re-hash is intolerable at that time.
However, because of the performance advantage of the hash table, its use is still very wide, so the third party's class library basically provides support, such as Msvc
So we can now write the following code:
#include <iostream>
#include <string>
#include <unordered_map>
int main ()
{
Std::unordered_map<std::string, int> months;
months["January"] =;
months["February"] =;
months["march"] =;
months["April"] =
Months["may"] =;
months["June"] =
months["July"] =;
months["August"] =;
months["September"] =
months["October"] =;
months["November"] =
months["December"] =;
Std::cout << "September->" << months["September"] << Std::endl;
Std::cout << "April ->" << months["April"] << Std::endl;
Std::cout << "December->" << months["December"] << Std::endl;
Std::cout << "February->" << months["February"] << Std::endl;
return 0;
}