侯捷STL学习(十)--容器hashtable探索(unordered set/map)
2017-07-24 23:53
495 查看
layout: post
title: 侯捷STL学习(十)
date: 2017-07-23
tag: 侯捷STL
---
rehash时,篮子扩充两倍,找到其附近的质数,重新计算元素位置
内部扩充的数据已经预定好,53->97->....
hashtable实现
iterator要实现当当前node链表结束,要能进入到下一个buckets
hashtable使用
模板参数的形式
容器hashtable中hashfunction
hash{}的偏特化实现
hashtable使用
test unordered_set
title: 侯捷STL学习(十)
date: 2017-07-23
tag: 侯捷STL
---
第二十三节 容器hashtable探索
hashtable冲突(碰撞)处理rehash时,篮子扩充两倍,找到其附近的质数,重新计算元素位置
内部扩充的数据已经预定好,53->97->....
hashtable实现
iterator要实现当当前node链表结束,要能进入到下一个buckets
hashtable使用
模板参数的形式
容器hashtable中hashfunction
hash{}的偏特化实现
hashtable使用
C++11--unordered容器
结构test unordered_set
#include <unordered_set> #include <stdexcept> #include <string> #include <cstdlib> //abort() #include <cstdio> //snprintf() #include <iostream> #include <ctime> namespace jj15 { void test_unordered_set(long& value) { cout << "\ntest_unordered_set().......... \n"; unordered_set<string> c; char buf[10]; clock_t timeStart = clock(); for(long i=0; i< value; ++i) { try { snprintf(buf, 10, "%d", rand()); c.insert(string(buf)); } catch(exception& p) { cout << "i=" << i << " " << p.what() << endl; abort(); } } cout << "milli-seconds : " << (clock()-timeStart) << endl; cout << "unordered_set.size()= " << c.size() << endl; cout << "unordered_set.max_size()= " << c.max_size() << endl; //357913941 cout << "unordered_set.bucket_count()= " << c.bucket_count() << endl; cout << "unordered_set.load_factor()= " << c.load_factor() << endl; cout << "unordered_set.max_load_factor()= " << c.max_load_factor() << endl; cout << "unordered_set.max_bucket_count()= " << c.max_bucket_count() << endl; for (unsigned i=0; i< 20; ++i) { cout << "bucket #" << i << " has " << c.bucket_size(i) << " elements.\n"; } string target = get_a_target_string(); { timeStart = clock(); auto pItem = find(c.begin(), c.end(), target); //比 c.find(...) 慢很多 cout << "std::find(), milli-seconds : " << (clock()-timeStart) << endl; if (pItem != c.end()) cout << "found, " << *pItem << endl; else cout << "not found! " << endl; } { timeStart = clock(); auto pItem = c.find(target); //比 std::find(...) 快很多 cout << "c.find(), milli-seconds : " << (clock()-timeStart) << endl; if (pItem != c.end()) cout << "found, " << *pItem << endl; else cout << "not found! " << endl; } } }
相关文章推荐
- STL学习——STL中的关联式容器总结(RB-tree、set、map、hashtable、hash_set、hash_map)
- c++ 标准库的各种容器(vector,deque,map,set,unordered_map,unordered_set,list)的性能考虑
- boost.unordered 基于hash table的四种容器(即hash_map,unordered_mutimap,hash_set,hash_multiset)
- C++关联容器(unordered_map,vector,unordered_set)
- Java 容器类学习笔记1--了解Java提供的容器类List、ArrayList、Vector及map、HashTable、HashMap
- 侯捷STL学习(九)--关联式容器(Rb_tree,set,map)
- C++ Primer学习笔记(11)——(转)c++ 标准库的各种容器(vector,deque,map,set,unordered_map,unordered_set,list)的性能考虑
- C++学习_关联容器(map,set)
- 黑马程序员_学习笔记:10) 集合框架2:Set(HashSet、TreeSet)、Map(Hashtable、HashMap、TreeMap)、Collections、Arrays
- c++ 标准库的各种容器(vector,deque,map,set,unordered_map,unordered_set,list)的性能考虑
- stl之关联容器——set,map,hashtable
- C++ Primer 学习笔记:关联容器入门 set && map
- C++ STL容器的学习使用(vector、queue、list、set、map)
- C++标准库:关联容器(set、map、unordered、multi)
- 20,21,22-Hibernate容器映射技术(Set、List、Map) -mldn学习笔记 -hxzon
- 关联容器(map、set、multimap、multiset、pair、unordered_map)
- 23 hashtable&unordered_set&unordered_map深度探索
- java学习个人笔记---容器之Map与Set关系
- c++ 标准库的各种容器(vector,deque,map,set,unordered_map,unordered_set,list)的性能考虑
- c++ 标准库的各种容器(vector,deque,map,set,unordered_map,unordered_set,list)的性能考虑