c5be STL源码剖析-关联式容器之hash_set、hash_map、hash_multiset和hash_multimap
2017-04-20 16:23
603 查看
一、hash_set
1、hash_set以hashtable为底层机制,hash_set的操作几乎都是转调用hashtable的函数而已。
2、hash_set的元素没有自动排序功能。
3、hash_set的使用方式与set完全相同。
4、测试例子
二、hash_map
1、 hash_map以hashtable为底层机制,hash_map的操作几乎都是转调用hashtable的函数而已。
2、 hash_map的元素没有自动排序功能。
3、 hash_map的使用方式与map完全相同。
4、 测试例子
三、hash_multiset
hash_multiset的特性及用法和multiset完全相同,唯一的差别在于它的底层机制是hashtable,元素不会被自动排序。
四、hash_multimap
hash_multimap的特性及用法和multimap完全相同,唯一的差别在于它的底层机制是hashtable,元素不会被自动排序。
1、hash_set以hashtable为底层机制,hash_set的操作几乎都是转调用hashtable的函数而已。
2、hash_set的元素没有自动排序功能。
3、hash_set的使用方式与set完全相同。
4、测试例子
#include<hash_set> #include<iostream> using namespace std; int main(){ int ia[] = { 1, 4, 2, 6, 5, 3 }; hash_set<int> iset(begin(ia), end(ia)); cout << "size=" << iset.size() << endl; //size=6 cout << "3 count=" << iset.count(3) << endl;//3 count=1 iset.insert(3); cout << "size=" << iset.size() << endl;//size=6 cout << "3 count=" << iset.count(3) << endl;//3 count=1 iset.insert(7); cout << "size=" << iset.size() << endl;//size=7 cout << "3 count=" << iset.count(3) << endl;//3 count=1 iset.erase(1); cout << "size=" << iset.size() << endl;//size=6 cout << "1 count=" << iset.count(1) << endl;//1 count=0 hash_set<int>::iterator it; for (it = iset.begin(); it != iset.end(); ++it) cout << *it << " "; //4 2 6 5 3 7 没有排序功能 cout << endl; it = find(iset.begin(), iset.end(), 3); if (it != iset.end()) cout << "3 found" << endl;//3 found it = find(iset.begin(), iset.end(), 1); if (it == iset.end()) cout << "1 not found" << endl;//1 not found system("pause"); return 0; }
二、hash_map
1、 hash_map以hashtable为底层机制,hash_map的操作几乎都是转调用hashtable的函数而已。
2、 hash_map的元素没有自动排序功能。
3、 hash_map的使用方式与map完全相同。
4、 测试例子
#include<hash_map> #include<string> #include<iostream> using namespace std; int main(){ hash_map<string, int> mp; mp["Jack"] = 1; mp["John"] = 2; mp["Lily"] = 3; mp["Kate"] = 4; pair<string, int> value("Tom", 5); hash_map<string, int>::iterator it; for (it = mp.begin(); it != mp.end(); ++it) cout << it->first << " " << it->second << endl; cout << mp["Kate"] << endl; it = mp.find("John"); if (it != mp.end()) cout << "John found" << endl; it->second = 8; cout << mp["John"] << endl; system("pause"); return 0; }
三、hash_multiset
hash_multiset的特性及用法和multiset完全相同,唯一的差别在于它的底层机制是hashtable,元素不会被自动排序。
四、hash_multimap
hash_multimap的特性及用法和multimap完全相同,唯一的差别在于它的底层机制是hashtable,元素不会被自动排序。
相关文章推荐
- 【STL源码剖析读书笔记】【第5章】关联式容器之hash_set、hash_map、hash_multiset和hash_multimap
- 【STL源码剖析读书笔记】【第5章】关联式容器之hash_set、hash_map、hash_multiset和hash_multimap
- 【STL源码剖析读书笔记】【第5章】关联式容器之set、map、multiset和multimap
- 【STL源码剖析读书笔记】【第5章】关联式容器之set、map、multiset和multimap
- 5 关联式容器-set map multiset multimap
- STL容器:set/map/multiset/multimap 与hash_set/hash_map/hash_multiset/hash_multimap
- STL之红黑树容器:set,hash_set,multiset,hash_map,multimap
- 【第10章 关联容器】hashtable, hash_map, hash_set, hash_multiset, hash_multimap基于hashtable
- STL容器:set/map/multiset/multimap 与hash_set/hash_map/hash_multiset/hash_multimap
- STL之关联容器(set /map /multiset /multimap)
- STL关联容器MAP、SET与multimap、multiset与hashmap、hashset的区别
- 今日学习札记——STL常用容器:vector、list、set和multiset、map和multimap(11.17)
- 三 关联式容器(四)hash_set与hash_multiset
- C++:关联容器(set,multiset,map,multimap)
- STL概览-关联容器set,multiset,map,multimap(四)
- 三 关联式容器(五)hash_map与hash_multimap
- STL容器 set、 multiset、map、multimap
- STL学习——STL中的关联式容器总结(RB-tree、set、map、hashtable、hash_set、hash_map)
- list vector set map multimap multiset 容器大揭秘
- 16 STL集合和映射容器set/multiset_map/multimap