STL之(底层哈希表)hash_set、hash_multiset、hash_map,hash_multimap

10 篇文章 0 订阅

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_++

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值