Namespaces
Variants
Views
Actions

std::unordered_map<Key,T,Hash,KeyEqual,Allocator>::reserve

From cppreference.com
 
 
Containers library
Sequence
(C++11)
Associative
Unordered associative
Adaptors
Views
(C++20)
 
 
void reserve( size_type count );
(since C++11)

Sets the number of buckets to the number needed to accomodate at least count elements without exceeding maximum load factor and rehashes the container, i.e. puts the elements into appropriate buckets considering that total number of buckets has changed. Effectively calls rehash(std::ceil(count / max_load_factor())).

Contents

[edit] Parameters

count - new capacity of the container

[edit] Return value

(none)

[edit] Complexity

Average case linear in the size of the container, worst case quadratic.

[edit] See also

(C++11)
reserves at least the specified number of buckets and regenerates the hash table
(public member function) [edit]