首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::unordered_set

Defined in header <unordered_set>

?

?

template< class Key, class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class Allocator = std::allocator<Key> > class unordered_set;

(1)

(since C++11)

namespace pmr { template <class Key, class Hash = std::hash<Key>, class Pred = std::equal_to<Key>> using unordered_set = std::unordered_set<Key, Hash, Pred, std::pmr::polymorphic_allocator<Key>>; }

(2)

(since C++17)

无序集是一个关联容器,它包含一组类型为键的唯一对象。搜索、插入和删除具有平均恒定时间复杂度.

在内部,元素不是按任何特定的顺序排序,而是组织成桶。将元素放入哪个桶完全取决于其值的散列。这允许快速访问单个元素,因为一旦计算了散列,它就会引用该元素被放置到的确切桶。

即使非Const迭代器%29也不能修改容器元素%28,因为修改可能会更改元素%27s哈希并损坏容器。

std::unordered_set满足…的要求Container,,,AllocatorAwareContainer,,,UnorderedAssociativeContainer...

成员类型

Member type

Definition

key_type

Key

value_type

Key

size_type

Unsigned integer type (usually std::size_t)

difference_type

Signed integer type (usually std::ptrdiff_t)

hasher

Hash

key_equal

KeyEqual

allocator_type

Allocator

reference

value_type&

const_reference

const value_type&

pointer

std::allocator_traits<Allocator>::pointer

const_pointer

std::allocator_traits<Allocator>::const_pointer

iterator

Constant ForwardIterator

const_iterator

Constant forward iterator

local_iterator

An iterator type whose category, value, difference, pointer and reference types are the same as iterator. This iterator can be used to iterate through a single bucket but not across buckets

const_local_iterator

An iterator type whose category, value, difference, pointer and reference types are the same as const_iterator. This iterator can be used to iterate through a single bucket but not across buckets

node_type

a specialization of node handle representing a container node (since C++17)

insert_return_type

type describing the result of inserting a node_type, a specialization of template <class Iterator, class NodeType> struct /*unspecified*/ { Iterator position; bool inserted; NodeType node; }; instantiated with template arguments iterator and node_type. (since C++17)

成员函数

(constructor)

constructs the unordered_set (public member function)

(destructor)

destructs the unordered_set (public member function)

operator=

assigns values to the container (public member function)

get_allocator

returns the associated allocator (public member function)

迭代器

BEGINCBEGIN将迭代器返回到开头%28的公共成员函数%29

End cend将迭代器返回到End%28公共成员函数%29

容量

空检查容器是否为空%28公共成员函数%29

Size返回元素数%28公共成员函数%29

马克斯[医]Size返回元素的最大可能数%28公共成员函数%29

修饰符

清除内容%28公共成员功能%29

插入元素或节点%28,因为C++17%29%28公共成员函数%29

嵌入构造元素就地%28公共成员函数%29

座落[医]提示使用提示%28公共成员函数%29就地构造元素。

擦除元素%28公共成员函数%29

交换交换内容%28公共成员函数%29

提取%28C++17%29从容器中提取节点%28公共成员函数%29

从另一个容器合并%28C++17%29个连接节点%28公共成员函数%29

查找

Count返回匹配特定键的元素数%28公共成员函数%29

查找具有特定密钥%28公共成员函数%29的查找元素

平等[医]范围返回匹配特定键%28公共成员函数%29的元素的范围

桶接口

开始%28 int%29 cBEGIN%28 int%29返回一个迭代器到指定桶%28公共成员函数%29的开头

End%28 int%29 cend%28 int%29返回一个迭代器到指定桶%28公共成员函数%29的末尾

斗[医]Count返回桶数%28公共成员函数%29

马克斯[医]斗[医]COUNT返回最大桶数%28公共成员函数%29

斗[医]Size返回特定桶%28公共成员函数中的元素数%29

桶返回特定键%28公共成员函数%29的桶

散列策略

负载[医]因子返回每个桶的平均元素数%28公共成员函数%29

马克斯[医]负载[医]因子管理每个桶的最大平均元素数%28公共成员函数%29

重新哈希至少保留指定数量的桶。这将重新生成哈希表。28%公共成员职能%29

储备空间至少保留指定数量的元素。这将重新生成哈希表。28%公共成员职能%29

观察员

散列[医]函数返回函数用于散列键%28公共成员函数%29

键[医]Eq返回用于比较相等性%28公共成员函数%29的键的函数。

非会员职能

operator==operator!=

compares the values in the unordered_set (function template)

std::swap(std::unordered_set) (C++11)

specializes the std::swap algorithm (function template)

注记

成员类型iteratorconst_iterator可能是同一类型的别名。自iterator可转换为const_iterator,,,const_iterator应在函数参数列表中使用,以避免违反“一个定义规则”。

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com