122template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
141 using Value = std::pair<const Key, Mapped>;
211 const Hash& hasher_obj = {},
212 const Pred& pred = {});
235 const Hash& hasher_obj = {},
236 const Pred& pred = {});
673template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
675 const Hash& hasher_obj,
684template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
687 const Hash& hasher_obj,
690 m_value_list(values),
696 for (
auto value_list_it =
m_value_list.begin(); value_list_it != value_list_end_it; ++value_list_it)
703template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
710template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
714 operator=(std::move(src));
717template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
721 using Value_iter_set =
decltype(m_value_iter_set);
758 using Mutable_key_value_list = std::list<Value_movable>;
760 *(
reinterpret_cast<Mutable_key_value_list*
>(&m_value_list))
761 = *(
reinterpret_cast<const Mutable_key_value_list*
>(&src.
m_value_list));
767 m_value_iter_set = Value_iter_set{src_value_iter_set.bucket_count(),
768 src_value_iter_set.hash_function(),
769 src_value_iter_set.key_eq()};
771 const auto value_list_end_it = m_value_list.end();
772 for (
auto value_list_it = m_value_list.begin(); value_list_it != value_list_end_it; ++value_list_it)
775 m_value_iter_set.insert(value_list_it);
781template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
793template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
803template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
804std::pair<typename Linked_hash_map<Key_t, Mapped_t, Hash_t, Pred_t>::Iterator,
bool>
809 const auto set_it = m_value_iter_set.find(key_and_mapped.first);
810 return (set_it == m_value_iter_set.end())
811 ? pair<Iterator, bool>{insert_impl(key_and_mapped),
813 : pair<Iterator, bool>{set_it->iter(),
false};
816template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
817std::pair<typename Linked_hash_map<Key_t, Mapped_t, Hash_t, Pred_t>::Iterator,
bool>
822 const auto set_it = m_value_iter_set.find(key_and_mapped.first);
823 return (set_it == m_value_iter_set.end())
824 ? pair<Iterator, bool>{insert_impl_mv(std::move(key_and_mapped)),
826 : pair<Iterator, bool>{set_it->iter(),
false};
829template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
832 const auto set_it = m_value_iter_set.find(key);
833 return ((set_it == m_value_iter_set.end())
840template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
843 const auto set_it = m_value_iter_set.
find(key);
844 return ((set_it == m_value_iter_set.end())
852template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
853typename Linked_hash_map<Key_t, Mapped_t, Hash_t, Pred_t>::Iterator
858 m_value_list.emplace_front(key_and_mapped);
863 const auto list_it = m_value_list.
begin();
864 m_value_iter_set.insert(list_it);
868template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
874 m_value_list.emplace_front(std::move(key_and_mapped));
876 const auto list_it = m_value_list.
begin();
877 m_value_iter_set.insert(list_it);
881template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
885 const auto set_it = m_value_iter_set.
find(key);
886 return (set_it == m_value_iter_set.end()) ? m_value_list.end() : set_it->iter();
889template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
893 const auto set_it = m_value_iter_set.
find(key);
894 return (set_it == m_value_iter_set.cend()) ? m_value_list.cend() : set_it->iter();
897template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
901 return m_value_iter_set.
count(key);
904template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
907 m_value_list.splice(m_value_list.begin(), m_value_list, it);
910template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
913 const auto it = find(key);
924template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
928 m_value_iter_set.
erase(it->first);
931 return m_value_list.erase(it);
934template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
939 for (
auto it = it_newest; it != it_past_oldest; ++it)
941 m_value_iter_set.
erase(it->first);
944 return m_value_list.erase(it_newest, it_past_oldest);
947template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
951 const auto set_it = m_value_iter_set.
find(key);
952 if (set_it == m_value_iter_set.end())
958 const auto list_it = set_it->iter();
959 m_value_iter_set.erase(set_it);
960 m_value_list.erase(list_it);
965template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
968 m_value_iter_set.
clear();
969 m_value_list.clear();
972template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
976 return m_value_list.
begin();
979template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
986template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
990 return m_value_list.
end();
993template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
997 return past_oldest();
1000template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
1004 return m_value_list.
cbegin();
1007template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
1011 return const_newest();
1014template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
1018 return const_newest();
1021template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
1025 return m_value_list.
cend();
1028template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
1032 return const_past_oldest();
1035template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
1039 return const_past_oldest();
1042template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
1046 return m_value_list.
rbegin();
1049template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
1056template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
1060 return m_value_list.
rend();
1063template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
1067 return past_newest();
1070template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
1074 return m_value_list.
crbegin();
1077template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
1081 return const_oldest();
1084template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
1088 return m_value_list.
crend();
1091template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
1095 return const_past_newest();
1098template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
1102 return m_value_iter_set.
size();
1105template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
1108 return m_value_list.
empty();
1111template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
1115 return std::min(m_value_iter_set.max_size(), m_value_list.max_size());
1118template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
An object of this class is a map that combines the lookup speed of an unordered_flat_map<> and orderi...
size_type max_size() const
Returns max number of elements that can be stored.
Reverse_iterator past_newest()
Returns one past last, a/k/a "newest," element's reverse iterator.
Const_iterator cbegin() const
Synonym of const_newest().
typename Value_list::iterator Iterator
Type for iterator pointing into a mutable structure of this type.
std::size_t size_type
Expresses sizes/lengths of relevant things.
Const_reverse_iterator crend() const
Synonym of const_past_newest().
Value * pointer
For container compliance (hence the irregular capitalization): pointer to Key/Mapped pair type.
Iterator iterator
For container compliance (hence the irregular capitalization): Iterator type.
Mapped & operator[](const Key &key)
Either finds the Mapped value at the given key, or if not found inserts one with a default-constructe...
std::pair< Key, Mapped > Value_movable
Short-hand for key/mapped-value pair best-suited (perf-wise) as arg type for the moving insert() over...
Key_t Key
Convenience alias for template arg.
Mapped mapped_type
For container compliance (hence the irregular capitalization): Mapped type.
Const_iterator end() const
Synonym of cend().
Hash_t Hash
Convenience alias for template arg.
Const_iterator begin() const
Synonym of cbegin().
void touch(const Const_iterator &it)
Given a valid iterator into the structure, makes the pointed-to element "newest" by moving it from wh...
std::list< Value > Value_list
Short-hand for doubly linked list of (Key, Mapped) pairs.
Reverse_iterator rbegin()
Synonym of oldest().
Linked_hash_map(size_type n_buckets=size_type(-1), const Hash &hasher_obj={}, const Pred &pred={})
Constructs empty structure with some basic parameters.
Iterator insert_impl_mv(Value_movable &&key_and_mapped)
Similar to insert_impl(), except key_and_mapped components are move()d into *this instead of being co...
Linked_hash_map(std::initializer_list< Value > values, size_type n_buckets=size_type(-1), const Hash &hasher_obj={}, const Pred &pred={})
Constructs structure with some basic parameters, and values initialized from initializer list.
Reverse_iterator oldest()
Returns first, a/k/a "oldest," element's reverse iterator.
Pred key_equal
For container compliance (hence the irregular capitalization): Pred type.
Value value_type
For container compliance (hence the irregular capitalization): Key/Mapped pair type.
Iterator newest()
Returns first, a/k/a "newest," element's iterator; or past_oldest() if empty().
Linked_hash_key_set< Key, Iterator, Hash, Pred, true > m_value_iter_set
Data structure that allows the amortized-constant-time (as in the unordered_*set = Linked_hash_key_se...
typename Value_list::const_reverse_iterator Const_reverse_iterator
Type for reverse iterator pointing into an immutable structure of this type.
Const_iterator cend() const
Synonym of const_past_oldest().
Const_iterator find(const Key &key) const
Identical to the other overload but in a const context: the returned iterator is to immutable memory.
Iterator erase(const Const_iterator &it_newest, const Const_iterator &it_past_oldest)
Erases all elements in the range [it_newest, it_past_oldest).
Iterator begin()
Synonym of newest().
Iterator erase(const Const_iterator &it)
Erases the element pointed to by the given valid iterator.
Const_iterator const_iterator
For container compliance (hence the irregular capitalization): Const_iterator type.
std::pair< Iterator, bool > insert(Value_movable &&key_and_mapped)
Identical to the other overload, except that (if key not already present in *this) the key and mapped...
const Value & const_reference
For container compliance (hence the irregular capitalization): reference to const Key/Mapped pair typ...
Value & reference
For container compliance (hence the irregular capitalization): reference to Key/Mapped pair type.
std::pair< const Key, Mapped > Value
Short-hand for key/mapped-value pairs stored in the structure.
Mapped_t Mapped
Convenience alias for template arg.
Hash hasher
For container compliance (hence the irregular capitalization): Hash type.
Reverse_iterator rend()
Synonym of past_newest().
Const_reverse_iterator crbegin() const
Synonym of const_oldest().
size_type count(const Key &key) const
Returns the number of times a key equal to the given one is present (as-if via find()) in the map: ei...
std::ptrdiff_t difference_type
Type for difference of size_types.
Iterator past_oldest()
Returns special iterator indicating the position just past the iteration order; if not empty() this i...
Const_reverse_iterator const_past_newest() const
Returns special reverse iterator indicating the position just past the reverse-iteration order; if no...
size_type size() const
Returns number of elements stored.
Iterator find(const Key &key)
Attempts to find value at the given key in the map.
typename Value_list::const_iterator Const_iterator
Type for iterator pointing into an immutable structure of this type.
Iterator end()
Synonym of past_oldest().
Key key_type
For container compliance (hence the irregular capitalization): Key type.
const Value * const_pointer
For container compliance (hence the irregular capitalization): pointer to const Key/Mapped pair type.
Value_list m_value_list
The actual values – which, as in unordered_*map<K, M>, are instances of Value = pair<const Key,...
void swap(Linked_hash_map &other)
Swaps the contents of this structure and other.
std::pair< Iterator, bool > insert(const Value &key_and_mapped)
Attempts to insert (copying both key and mapped-value) the given key/mapped-value pair into the map; ...
void clear()
Makes it so that size() == 0.
typename Value_list::reverse_iterator Reverse_iterator
Type for reverse iterator pointing into a mutable structure of this type.
Linked_hash_map & operator=(Linked_hash_map &&src)
Overwrites this object making it identical to the given source, while the given source becomes as-if ...
Const_iterator const_newest() const
Same as newest() but operating on immutable *this.
Const_iterator const_past_oldest() const
Same as past_oldest() but operating on immutable *this.
size_type erase(const Key &key)
Erases the element with the given key, if it exists.
Linked_hash_map(Linked_hash_map &&src)
Constructs object by making it equal to the given source, while the given source becomes as-if defaul...
bool touch(const Key &key)
Given a key into the structure, makes the corresponding element "newest" by moving it from wherever i...
Linked_hash_map & operator=(const Linked_hash_map &src)
Overwrites this object with a copy of the given source.
Linked_hash_map(const Linked_hash_map &src)
Constructs object that is a copy of the given source.
Mapped & operator[](Key &&key)
Identical to the other overload, except that (if key not already present in *this) the key is moved,...
Pred_t Pred
Convenience alias for template arg.
Const_reverse_iterator const_oldest() const
Returns first, a/k/a "oldest," element's reverse iterator (to immutable element).
Iterator insert_impl(const Value &key_and_mapped)
Helper that modifies m_value_list and m_value_iter_set so that key_and_mapped's copy is inserted into...
bool empty() const
Returns true if and only if container is empty.
Flow module containing miscellaneous general-use facilities that don't fit into any other Flow module...
constexpr size_t LINKED_HASH_KEY_SET_DEFAULT_N_BUCKETS
Value used by alias-target type of Linked_hash_key_set as the default hash bucket count,...
void swap(Linked_hash_map< Key_t, Mapped_t, Hash_t, Pred_t > &val1, Linked_hash_map< Key_t, Mapped_t, Hash_t, Pred_t > &val2)
Equivalent to val1.swap(val2).
void swap(Basic_blob< Allocator_t, SHARING > &blob1, Basic_blob< Allocator_t, SHARING > &blob2, log::Logger *logger_ptr) noexcept
Equivalent to blob1.swap(blob2).