hash_set与hash_multiset:
实值就是键值
以hashtable为底层机制,所以几乎所有的hash_set行为,都是转调hashtable的操作行为。
与set、multiset相比,hash_set、hash_multiset没有自动排序功能。
hash_set与set一样,实值就是键值。使用方式与set完全相同
插入元素操作采用底层机制hashtable的insert_unique()。
hash_multiset与multiset一样,键值可以重复,使用方式和multiset相同。
插入元素操作采用底层机制hashtable的insert_equal()。
hash_map与hash_multimap:
每一个元素同时拥有实值和键值
以hashtable为底层机制,所以几乎所有的hash_map行为,都是转调hashtable的操作行为。
与map、multimap相比,hash_map、hash_multimap没有自动排序功能。
hash_map与map一样,实值就是键值。使用方式与set完全相同
插入元素操作采用底层机制hashtable的insert_unique()。
hash_multimap与multimap一样,键值可以重复,pair<key,value>
插入元素操作采用底层机制hashtable的insert_equal()。
#include<iostream>
#include<unordered_map>
#include<cstring>
using namespace std;
int main()
{
unordered_map<const char*,int>days;
days["january"]=31;
days["february"]=28;
days["march"]=31;
days["april"]=30;
days["may"]=30;
days["june"]=30;
cout<<"june->"<<days["june"]<<endl;//30
unordered_map<const char*,int>::iterator ite1=days.begin();
unordered_map<const char*,int>::iterator ite2=days.end();
for(;ite1!=ite2;++ite1)
cout<<ite1->first<<" "<<ite1->second<<endl;
system("pause");
}
无序容器在现在的c++11中命名为unordered_++