cptr::detail::basic_unordered_map

The class behind cptr::unordered_map; use that alias. Its members behave like those of std::unordered_map; the alias lists the differences.

Synopsis

Declared in <cptr/unordered_map.hpp>

template<
    class K,
    class V,
    class Hash,
    class KeyEqual,
    class Cage,
    bool Compressed>
class basic_unordered_map;

Description

The map behind cptr::unordered_map. Compressed = false gives the same table with raw 8-byte links, which the benchmarks compare against.

Each node holds its next link and the low 32 bits of its hash, so a node of two 4-byte values is 16 bytes. The bucket array holds one link per bucket and is allocated in the cage too, so the map can live in a mapped_cage. Bucket counts are powers of two, and a bucket is chosen by Fibonacci hashing of the stored hash, so identity hashes of integers spread well.

Types

NameDescription
basic_iterator A forward iterator: the node, and the bucket array and its size, so that it can move on to the next bucket. It does not refer to the map object, so like std's iterators it stays valid when the map is moved or swapped; a rehash invalidates it. With compressed links it is 16 bytes.

Type Aliases

Name
const_iterator
const_reference
difference_type
hasher
iterator
key_equal
key_type
mapped_type
reference
size_type
value_type

Member Functions

NameDescription
basic_unordered_map [constructor]Constructors
~basic_unordered_map [destructor]Destructor
operator= Assignment operators
at
begin The first element. Constant time on average: the map keeps a lower bound on its first non-empty bucket, which insertion lowers and erase(iterator) raises, so while (!m.empty()) m.erase(m.begin()); is linear. begin() itself writes nothing, so concurrent calls are safe.
bucket_count
cbegin
cend
clear
contains
count
emplace Build the element from args, then insert it unless its key is present; returns the element with that key and whether it was inserted. As for std::unordered_map, the element is built first, even when the key turns out to be present (try_emplace avoids that). If the hash, the key comparison or a rehash throws, the element is destroyed and the map is unchanged.
emplace_hint As emplace(). The hint is accepted for compatibility with std::unordered_map and generic code, but not used.
empty
end
equal_range Heterogeneous equal_range(), as in C++20.
erase erase overloads
find
hash_function
insert insert overloads
insert_or_assign insert_or_assign overloads
key_eq
load_factor
max_load_factor Set the maximum load factor, ignoring values that are not positive, and rehash if the map is now over it. If that rehash throws, the old maximum is kept.
max_size
operator[] Subscript operators
rehash Use at least n buckets, and enough for max_load_factor(). The count is rounded up to a power of two. Throws std::length_error if that is more than max_bucket_count(); iterators are invalidated unless the count stays the same.
reserve Make room for n elements without exceeding max_load_factor(). Throws std::length_error if that needs more than max_bucket_count() buckets.
size
swap
try_emplace try_emplace overloads

Static Member Functions

NameDescription
max_bucket_count The most buckets the map can have: a power of two, limited by the cage's size and by the 32-bit hashes the nodes keep.

Static Data Members

NameDescription
node_size Bytes per element, including the link and the hash.

Friends

NameDescription
cptr::detail::operator==Equal if both hold the same keys with equal values.
cptr::detail::swap