📜  C++库-

📅  最后修改于: 2020-12-15 04:36:27             🧑  作者: Mango


介绍

它是一个关联容器,不按特定顺序存储唯一元素,并且允许根据其值快速检索单个元素。

定义

以下是std :: unordered_set的定义

template < class Key,                        
           class Hash = hash,        
           class Pred = equal_to,    
           class Alloc = allocator   
           > class unordered_set;

参量

  • -它定义元素的类型。

  • 哈希-它是一元函数对象。

  • Pred-这是一个二进制谓词,它接受与元素相同类型的两个参数,并返回布尔值。

  • 的Alloc -它定义allowcater的类型。

会员类型

成员函数可以将以下成员类型用作参数或返回类型。

member type definition notes
key_type It is the first template parameter (Key)
value_type It is the first template parameter (Key) The same as key_type
hasher It is the second template parameter (Hash) defaults to: hash
key_equal It is the third template parameter (Pred) defaults to: equal_to
allocator_type It is the fourth template parameter (Alloc) defaults to: allocator
reference Alloc::reference
const_reference Alloc::const_reference
pointer Alloc::pointer for the default allocator: value_type*
const_pointer Alloc::const_pointer for the default allocator: const value_type*
iterator a forward iterator to const value_type * convertible to const_iterator
const_iterator a forward iterator to const value_type *
local_iterator a forward iterator to const value_type * convertible to const_local_iterator
const_local_iterator a forward iterator to const value_type *
size_type an unsigned integral type usually the same as size_t
difference_type a signed integral type usually the same as ptrdiff_t

会员职能

以下是成员函数列表

Sr.No. Method & Description
1 (constructor)

It constructs unordered_set.

2 (destructor)

It destroys unordered_set.

3 operator=

It is used to assign the content.

容量

Sr.No. Capacity & Description
1 empty

It is used to test whether container is empty.

2 size

It returns container size.

3 max_size

It returns maximum size.

迭代器

Sr.No. Iterators & Description
1 begin

It returns iterator to beginning.

2 end

It returns iterator to end.

3 cbegin

It returns const_iterator to beginning.

4 cend

It return const_iterator to end.

元素查询

Sr.No. Element lookup & Description
1 find

It is used to get iterator to element.

2 count

It is used to count elements with a specific key.

3 equal_range

It is used to get range of elements with a specific key.

修饰符

Sr.No. Modifiers & Description
1 emplace

It is used to construct and insert element.

2 emplace_hint

It is used to construct and insert element with hint.

3 insert

It is used to insert elements.

4 erase

It is used to erase elements.

5 clear

It is used to clear content.

6 swap

It is used to swap content.

水桶

Sr.No. Buckets & Description
1 bucket_count

It returns number of buckets.

2 max_bucket_count

It returns maximum number of buckets.

3 bucket_size

It returns bucket size.

4 bucket

It locates element’s bucket.

哈希策略

Sr.No. Hash policy & Description
1 load_factor

It returns load factor.

2 max_load_factor

It is used to get or set maximum load factor.

3 rehash

It is used to set number of buckets.

4 reserve

It gives a request to capacity chage of backets

观察者

Sr.No. Observers & Description
1 hash_function

It is used to get hash function.

2 key_eq

It is used to get key equivalence predicate.

3 get_allocator

It is used to get allocator.

Sr.No. Non-member function overloads & Description
1 operators (unordered_set)

It is used to get hash function.

2 swap (unordered_set)

It exchanges contents of two unordered_set containers.

预定义的迭代器

Sr.No. Non-member function overloads & Description
1 operators (unordered_set)

It is used to get hash function.

2 swap (unordered_set)

It exchanges contents of two unordered_set containers.