Engine → Core → flat_hash_map.h
flat_hash_map
| Type | Class |
| Namespace | conjure::core |
| Include File Path | engine/include/conjure/core/containers/flat_hash_map.h |
| Source File Path | N/A |
| API ↗ | Containers |
Syntax
template <typename K, typename V, typename Hash = std::hash<K>, typename Eq = std::equal_to<K>> class flat_hash_map
Constructors
| Access | Signature | Description |
|---|---|---|
| public | flat_hash_map() = default; | |
| public | explicit flat_hash_map(
usize initialCapacity); | Pre-sizes the table for initialCapacity elements; 0 allocates nothing. |
| public | flat_hash_map(
std::initializer_list<value_type> values); | Builds the map from pairs; for duplicate keys the first one wins. |
| public | flat_hash_map(
const flat_hash_map &) = default; | |
| public | flat_hash_map(
flat_hash_map &&) noexcept = default; |
Destructors
| Access | Signature | Description |
|---|---|---|
| public | ~flat_hash_map() = default; |
Variables
| Access | Name | Type | Default | Description |
|---|---|---|---|---|
| public | MAX_CAPACITY | static constexpr usize | table_ | |
| public | MAX_ | static constexpr f32 | table_ | |
| private | mTable | table_type | {} |
Functions
Public
at
at[[nodiscard]] V &at(
const K &key) noexcept;The value for key. The key must be present: a missing key is a fatal programmer error (asserts, then terminates), never an exception.
[[nodiscard]] const V &at(
const K &key) const noexcept;capacity
capacity[[nodiscard]] usize capacity() const noexcept;Buckets (a power of two, 0 before the first insertion). The table rehashes only when size() would exceed capacity() * MAX_LOAD_FACTOR.
cbegin
cbegin[[nodiscard]] const_iterator cbegin() const noexcept;cend
cend[[nodiscard]] const_iterator cend() const noexcept;contains
contains[[nodiscard]] bool contains(
const K &key) const noexcept;emplace
emplacetemplate <typename... Args> std::pair<iterator, bool> emplace(
Args &&...args);Constructs a pair from the arguments and inserts it when its key is absent.
empty
empty[[nodiscard]] bool empty() const noexcept;erase
erasebool erase(
const K &key) noexcept;Removes the element with key. Returns false when absent. Never rehashes.
iterator erase(
const_iterator position) noexcept;Removes the element at position. Returns the iterator following it.
find
find[[nodiscard]] iterator find(
const K &key) noexcept;The element with key key, or end().
[[nodiscard]] const_iterator find(
const K &key) const noexcept;hash_function
hash_function[[nodiscard]] const Hash &hash_function() const noexcept;insert
insertstd::pair<iterator, bool> insert(
const value_type &value);Inserts when the key is absent. Returns the element and whether it was inserted.
std::pair<iterator, bool> insert(
value_type &&value);template <std::input_iterator Iterator> void insert(
Iterator first,
Iterator last);Inserts every element of the range that is not already present.
insert_or_assign
insert_or_assigntemplate <typename M> std::pair<iterator, bool> insert_or_assign(
const K &key,
M &&value);Inserts or overwrites. Returns the element and true when it was newly inserted.
template <typename M> std::pair<iterator, bool> insert_or_assign(
K &&key,
M &&value);key_eq
key_eq[[nodiscard]] const Eq &key_eq() const noexcept;load_factor
load_factor[[nodiscard]] f32 load_factor() const noexcept;reserve
reservevoid reserve(
usize count);Makes room for count elements without a rehash during the next insertions. reserve(0) does nothing, so an empty map stays unallocated.
size
size[[nodiscard]] usize size() const noexcept;swap
swapvoid swap(
flat_hash_map &other) noexcept;try_emplace
try_emplacetemplate <typename... Args> std::pair<iterator, bool> try_emplace(
const K &key,
Args &&...args);Inserts {key, V(args...)} when key is absent; the value is only constructed in that case. Returns the element and whether it was inserted.
template <typename... Args> std::pair<iterator, bool> try_emplace(
K &&key,
Args &&...args);Operator Overloads
Public
operator=
operator=flat_hash_map &operator=(
const flat_hash_map &) = default;flat_hash_map &operator=(
flat_hash_map &&) noexcept = default;operator==
operator==[[nodiscard]] bool operator==(
const flat_hash_map &other) const;Same keys with equal values, regardless of slot order.
operator[]
operator[][[nodiscard]] V &operator[](
const K &key);The value for key, default-constructed and inserted when absent.
[[nodiscard]] V &operator[](
K &&key);