C++11 unordered_set

来源:互联网 发布:ghost最新软件版本 编辑:程序博客网 时间:2024/06/05 11:19
template < class Key,                        // unordered_set::key_type/value_type           class Hash = hash<Key>,           // unordered_set::hasher           class Pred = equal_to<Key>,       // unordered_set::key_equal           class Alloc = allocator<Key>      // unordered_set::allocator_type           > class unordered_set;

C++ 11中对unordered_set描述大体如下:无序集合容器(unordered_set)是一个存储唯一(unique,即无重复)的关联容器(Associative container),容器中的元素无特别的秩序关系,该容器允许基于值的快速元素检索,同时也支持正向迭代。
在一个unordered_set内部,元素不会按任何顺序排序,而是通过元素值的hash值将元素分组放置到各个槽(Bucker,也可以译为“桶”),这样就能通过元素值快速访问各个对应的元素(均摊耗时为O(1))。
原型中的Key代表要存储的类型,而hash也就是你的hash函数,equal_to用来判断两个元素是否相等,allocator是内存的分配策略。一般情况下,我们只关心hash和equal_to参数,下面将介绍这两部分。
参考:
http://www.cplusplus.com/reference/unordered_set/unordered_set/
http://blog.csdn.net/dream_you_to_life/article/details/46785741

原创粉丝点击