STL:unordered_set/unordered_multiset(c++11)
unordered_set:容器内的元素无序排列,基于值进行获取单个元素速度非常快。内部根据它们的 hash value 被组织成 buckets(slot)。
unordered_multiset: 操作和 unordered_set 相同,只是 key 可以重复。
Iterators
begin: 有两个类型:container iterator(1); bucket iterator。
end: 同上面的 begin
cbegin:
cend:
Element lookup
find:
count:
equal_range:返回 pair<iterator,iterator>, 其中的迭代器都是 const_iterator,不能修改容器内的值。
Modifiers
emplace:
emplace_hint:
insert:
erase:
clear:
swap:
Buckets
bucket_count: 返回哈希表中槽的个数(a bucket is a slot in the container's internal hash table)
max_bucket_count: 最大槽的个数
bucket_size: 返回在槽 n 中元素的个数(传入参数 n)
bucket: 给定 val ,定位该值所在的槽(槽被编号为 0 to (bucket_count-1))
Hash policy
load_factor: 负载因子,公式为:size / bucket_size。这个因素影响冲突率,当负载因子超过一个指定阈值(通常是:max_load_factor),需要进行槽的动态扩充。这将导致 rehash。
max_load_factor: 默认的 最大负载因子是 1.0(float 类型),也可以通过这个函数进行修改阈值。
rehash: 设置槽的数量。如果比当前的槽多,则强制进行哈希表的重建,并且自动对已有的数据进行 rehash。如果比当前的槽少,则什么都不会发生。注意:rehash(size_type& n) 也许并不把槽号刚好设置为 n 个槽,而是最少是 n 个槽,这样可以防止多次 rehash 造成的性能下降。
reserve: 同 rehash 一样,可以设置当前的槽数,事先设置好 hash table 的最佳大小,避免多次进行 rehash.
Observers
hash_function: 获取 hash 函数(hasher 类型),用法如例:
// unordered_set::hash_function
#include <iostream>
#include <string>
#include <unordered_set> typedef std::unordered_set<std::string> stringset; int main ()
{
stringset myset; stringset::hasher fn = myset.hash_function(); std::cout << "that: " << fn ("that") << std::endl;
std::cout << "than: " << fn ("than") << std::endl; return ;
}
key_eq:返回一个在 unordered_set 的容器中判断是否相等的一个函数,返回 bool 值。用法如例:
// unordered_set::key_eq
#include <iostream>
#include <string>
#include <unordered_set> int main ()
{
std::unordered_set<std::string> myset; bool case_insensitive = myset.key_eq()("checking","CHECKING"); std::cout << "myset.key_eq() is ";
std::cout << ( case_insensitive ? "case insensitive" : "case sensitive" );
std::cout << std::endl; return ;
}
最新文章
- js运动框架之一条乱跑的虫子
- CRM 403错误
- 30.赋值运算符重载函数[Assign copy constructor]
- Using RestTemplate, how to send the request to a proxy first so I can use my junits with JMeter?
- 从github上面拷贝源码
- JAVA取随机数,石头剪刀布实例
- FVDI Commander products be replaced SVDI tools,really?
- poj1724ROADS(BFS)
- IOS设备设计完整指南(转载)
- Swing系列之控件一
- Java 控制台输入数字 输出乘法表(代码练习)
- ORACLE时间日期格式使用总结(参考网上资料汇总)
- Unity编辑器扩展
- Java核心技术及面试指南面试题,基本数据类型、封装类和运算操作的面试题
- JMeter 提供了六种定时器
- nodejs从http升级到https(阿里云证书的使用)
- python异步编程--回调模型(selectors模块)
- Python 最佳实践指南 2018 学习笔记
- Java 汇编代码
- super()方法