侯捷STL学习(十)--容器hashtable探索(unordered set/map)
layout: post
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学习(十)--容器hashtable探索(unordered set/map)的更多相关文章
- 侯捷STL学习(八)-- 深度探索deque
layout: post title: 侯捷STL学习(八) date: 2017-07-19 tag: 侯捷STL --- 第十八节 深度探索deque上 duque内存结构 分段连续,用户看起来是 ...
- 侯捷STL学习(七)--深度探索vector&&array
layout: post title: 侯捷STL学习(七) date: 2017-06-13 tag: 侯捷STL --- 第十六节 深度探索vector vector源码剖析 vector内存2倍 ...
- 侯捷STL学习(九)--关联式容器(Rb_tree,set,map)
layout: post title: 侯捷STL学习(九) date: 2017-07-21 tag: 侯捷STL --- 第十九节 容器rb_tree Red-Black tree是自平衡二叉搜索 ...
- 侯捷STL学习(12)--STL相关内容hash+tuple
layout: post title: 侯捷STL学习(12) date: 2017-08-01 tag: 侯捷STL --- 第四讲 STL相关的内容 Hash Function 将hash函数封装 ...
- 侯捷STL学习(11)--算仿+仿函数+适配器
layout: post title: 侯捷STL学习(十一) date: 2017-07-24 tag: 侯捷STL --- 第三讲 标准库内核分析-算法 标准库算法形式 iterator分类 不同 ...
- 侯捷STL学习(一)--顺序容器测试
开始跟着<STL源码剖析>的作者侯捷真人视频,学习STL,了解STL背后的真实故事! 视频链接:侯捷STL 还有很大其他视频需要的留言 第一节:STL版本和重要资源 STL和标准库的区别 ...
- 侯捷STL学习(一)
开始跟着<STL源码剖析>的作者侯捷真人视频,学习STL,了解STL背后的真实故事! 视频链接:侯捷STL 还有很大其他视频需要的留言 第一节:STL版本和重要资源 STL和标准库的区别 ...
- 侯捷STL学习(四)--allocator和容器时间的实现关系
第十一节 分配器 分配器的好坏影响到容器的性能 operator new()里面调用malloc D:\Program Files (x86)\Microsoft Visual Studio 12.0 ...
- 侯捷STL学习(五)--allocator和容器之间的实现关系
第十一节 分配器 STL源码学习----内存管理 分配器的好坏影响到容器的性能 operator new()里面调用malloc D:\Program Files (x86)\Microsoft Vi ...
随机推荐
- JS,Jquery获取屏幕的宽度和高度
Javascript: 网页可见区域宽: document.body.clientWidth网页可见区域高: document.body.clientHeight网页可见区域宽: document.b ...
- mysql基础(4)-数据导入
如何把数据导入(出)mysql 导出 sql语句 select * from 表名 into outfile "详细路径" fields terminated by ...
- ZooKeeper-安装和运行
ZooKeeper安装和运行 1. 下载安装包 zookeeper-3.4.9.tar.gz 2. 解压 tar -zxvf zookeeper-3.4.9.tar.gz ZooKeeper提供了几个 ...
- Vue v-on v-model 组合使用
v-on vue可以使用v-on指令来监听事件,方便与用户进行交互.我们不需要修改DOM中的数据,所有的操作都由Vue来实现,你编写的代码只需要关注底层逻辑.这也是Vue强大的地方之一 <!DO ...
- tyvj 1057 金明的预算方案 背包dp
P1057 金明的预算方案 时间: 1000ms / 空间: 131072KiB / Java类名: Main 背景 NOIP2006 提高组 第二道 描述 金明今天很开心,家里购置的新房就要领钥匙了 ...
- java:jsp: 一个简单的自定义标签 tld
java:jsp: 一个简单的自定义标签 tld 请注意,uri都是:http://www.tag.com/mytag,保持统一,要不然报错,不能访问 tld文件 <?xml version=& ...
- C语言基础二
C--顺序程序设计 赋值语句 赋值语句和赋值表达式的区别: if((a = b) > 0) t = 0; 字符数据的输入输出 putchar函数 该函数为字符输出函数,其作用是向终端数出一个字符 ...
- ebs R12 支持IE11
如果不考虑升级jdk到1.7的话,可以使用oracle推荐的方法. 1.兼容模式 2.Toolkit to Disable Automatic Delivery of Internet Explore ...
- Mybatis_总结_05_用_Java API
一.前言 使用 MyBatis 的主要 Java 接口就是 SqlSession.你可以通过这个接口来执行命令,获取映射器和管理事务. 二.主要类 (1)SqlSession 是由 SqlSessio ...
- Leetcode 904. Fruit Into Baskets
sliding window(滑动窗口)算法 class Solution(object): def totalFruit(self, tree): """ :type ...