Engine → Core → flat_hash_map.h
detail::hash_table
| 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
Constructors
| Access | Signature | Description |
|---|---|---|
| public | hash_table() = default; | |
| public | explicit hash_table(
usize initialCapacity); | |
| public | hash_table(
const hash_table &other); | |
| public | hash_table(
hash_table &&other) noexcept; |
Destructors
| Access | Signature | Description |
|---|---|---|
| public | ~hash_table(); |
Variables
| Access | Name | Type | Default | Description |
|---|---|---|---|---|
| private | HASH_MASK | static constexpr u32 | 0x7FFFFFFFu | |
| private | mAnchor | usize | 0 | |
| public | MAX_CAPACITY | static constexpr usize | usize{1} << 31 | Largest number of buckets: the stored hash keeps 31 bits, so the home bucket is addressable for every capacity up to 2^31. |
| public | MAX_ | static constexpr f32 | 0.875f | |
| private | mCapacity | usize | 0 | |
| private | mEqual | Eq | {} | |
| private | mGrowAt | usize | 0 | |
| private | mHash | Hash | {} | |
| public | MIN_CAPACITY | static constexpr usize | 8 | |
| private | mMask | usize | 0 | |
| private | mMeta | u32 * | nullptr | |
| private | mSize | usize | 0 | |
| private | mValues | Value * | nullptr | |
| private | NO_SLOT | static constexpr usize | std:: | |
| private | OCCUPIED_BIT | static constexpr u32 | 0x80000000u |
Functions
Public
capacity
capacity[[nodiscard]] usize capacity() const noexcept;Buckets (a power of two, 0 before the first insertion).
contains
contains[[nodiscard]] bool contains(
const key_type &key) const noexcept;empty
empty[[nodiscard]] bool empty() const noexcept;erase
erasebool erase(
const key_type &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, which is the next element an iteration from begin() has not visited yet: deletion only shifts elements towards the start of their probe run and no run crosses the anchor the iteration order starts at.
find
find[[nodiscard]] const_iterator find(
const key_type &key) const noexcept;hash_function
hash_function[[nodiscard]] const Hash &hash_function() const noexcept;insert
insertstd::pair<iterator, bool> insert(
const value_type &value);std::pair<iterator, bool> insert(
value_type &&value);insert_with
insert_withtemplate <typename Builder> std::pair<iterator, bool> insert_with(
const key_type &key,
Builder &&build);Inserts when the key is absent. build receives the uninitialised slot and must construct the value there. Returns the element and whether it was inserted. Arguments captured by build must not refer to elements of this table.
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 table stays unallocated.
size
size[[nodiscard]] usize size() const noexcept;swap
swapvoid swap(
hash_table &other) noexcept;Private
allocate_table
allocate_tablevoid allocate_table(
usize capacity);capacity_for
capacity_forSmallest power-of-two capacity (at least MIN_CAPACITY) whose grow threshold admits count elements.
clone_from
clone_fromvoid clone_from(
const hash_table &other);Copies another table slot for slot, which keeps its iteration order.
deallocate_table
deallocate_tablevoid deallocate_table() noexcept;destroy_elements
destroy_elementsvoid destroy_elements() noexcept;erase_index
erase_indexvoid erase_index(
usize index) noexcept;Backward-shift deletion: later elements of the run whose home is at or before the hole move into it, so no tombstone is needed and lookups stay short after many erases. The anchor is empty and therefore never part of the run.
find_index
find_indexSlot of key or NO_SLOT. The probe stops at the first empty slot (there always is one: the load factor is below one); keys are only compared when the stored hash matches.
forget_table
forget_tablevoid forget_table() noexcept;insert_new
insert_newPlaces a value whose key is known to be absent in the first empty slot of its probe sequence. The caller has made sure the table is below its grow threshold.
is_occupied
is_occupied[[nodiscard]] bool is_occupied(
usize index) const noexcept;iterator_at
iterator_at[[nodiscard]] const_iterator iterator_at(
usize index) const noexcept;next_empty_after
next_empty_afterThe first empty slot after index in probe order. Exists because the table is never full.
rehash
rehashvoid rehash(
usize newCapacity);relocate
relocatestatic void relocate(
Value *source,
Value *destination) noexcept;tag_of
tag_ofWhat an occupied slot stores for hash. Its low bits are the home bucket, so erase can recompute homes without re-hashing keys.
Operator Overloads
Public
operator=
operator=hash_table &operator=(
const hash_table &other);hash_table &operator=(
hash_table &&other) noexcept;