std::unordered_map

From Cppreference

Jump to: navigation, search
Defined in header <unordered_map>

template<

    class Key,
    class T,
    class Hash = std::hash<Key>,
    class KeyEqual = std::equal_to<Key>,
    class Allocator = std::allocator< std::pair<const Key, T> >

> class unordered_map;
(C++11 feature)

Unordered map is an associative container that contains key-value pairs with unique keys. Search, insertion, and removal have average constant-time complexity.

Contents

[edit] Member types

Member type Definition
key_type Key
mapped_type T
value_type std::pair<const Key, T>
size_type Unsigned integral type (usually size_t)
difference_type Signed integer type (usually 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 Forward iterator
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


[edit] Member functions

(constructor)
constructs the unordered_map
(public member function)
(destructor)
destructs the unordered_map
(public member function)
operator=
assigns values to the container
(public member function)
get_allocator
returns the associated allocator
(public member function)
Iterators
begin
cbegin

returns an iterator to the beginning
(public member function)
end
cend

returns an iterator to the end
(public member function)
Capacity
empty
checks whether the container is empty
(public member function)
size
returns the number of elements
(public member function)
max_size
returns the maximum possible number of elements
(public member function)
Modifiers
clear
clears the contents
(public member function)
insert
inserts elements
(public member function)
emplace
constructs element in-place
(public member function)
emplace_hint
constructs elements in-place using a hint
(public member function)
erase
erases elements
(public member function)
swap
swaps the contents
(public member function)
Lookup
at
access specified element with bounds checking
(public member function)
operator[]
access specified element
(public member function)
count
returns the number of elements matching specific key
(public member function)
find
finds element with specific key
(public member function)
equal_range
returns range of elements matching a specific key
(public member function)
Bucket interface
begin(int)
cbegin(int)
returns an iterator to the beginning of the specified bucket
(public member function)
end(int)
cend(int)
returns an iterator to the end of the specified bucket
(public member function)
bucket_count
returns the number of buckets
(public member function)
max_bucket_count
returns the maximum number of buckets
(public member function)
bucket_size
returns the number of elements in specific bucket
(public member function)
bucket
returns the bucket for specific key
(public member function)
Hash policy
load_factor
returns average number of elements per bucket
(public member function)
max_load_factor
manages maximum average number of elements per bucket
(public member function)
rehash
reserves at least the specified number of buckets.
This regenerates the hash table.
(public member function)
reserve
reserves space for at least the specified number of elements.
This regenerates the hash table.
(public member function)
Observers
hash_function
returns function used to hash the keys
(public member function)
key_eq
returns the function used to compare keys for equality
(public member function)

[edit] Non-member functions

operator=
operator!=
compares the values in the container
(function)
std::swap(std::unordered_map)
specializes the std::swap() algorithm
(function template)