116template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
135 using Value = std::pair<Key const, Mapped>;
665template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
667 const Hash& hasher_obj,
674template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
677 const Hash& hasher_obj,
680 m_value_list(values),
683 m_value_iter_set((n_buckets ==
size_type(-1))
684 ? boost::unordered::detail::default_bucket_count
690 for (
auto value_list_it =
m_value_list.begin(); value_list_it != value_list_end_it; ++value_list_it)
697template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
704template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
708 operator=(std::move(src));
711template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
715 using Value_iter_set =
decltype(m_value_iter_set);
753 using Mutable_key_value_list = std::list<Value_movable>;
755 *(
reinterpret_cast<Mutable_key_value_list*
>(&m_value_list))
756 = *(
reinterpret_cast<const Mutable_key_value_list*
>(&src.
m_value_list));
762 m_value_iter_set = Value_iter_set{src_value_iter_set.bucket_count(),
763 src_value_iter_set.hash_function(),
764 src_value_iter_set.key_eq()};
766 const auto value_list_end_it = m_value_list.end();
767 for (
auto value_list_it = m_value_list.begin(); value_list_it != value_list_end_it; ++value_list_it)
770 m_value_iter_set.insert(value_list_it);
776template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
788template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
798template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
799std::pair<typename Linked_hash_map<Key_t, Mapped_t, Hash_t, Pred_t>::Iterator,
bool>
804 const auto set_it = m_value_iter_set.find(key_and_mapped.first);
805 return (set_it == m_value_iter_set.end())
806 ? pair<Iterator, bool>{insert_impl(key_and_mapped),
808 : pair<Iterator, bool>{set_it->iter(),
false};
811template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
812std::pair<typename Linked_hash_map<Key_t, Mapped_t, Hash_t, Pred_t>::Iterator,
bool>
817 const auto set_it = m_value_iter_set.find(key_and_mapped.first);
818 return (set_it == m_value_iter_set.end())
819 ? pair<Iterator, bool>{insert_impl_mv(std::move(key_and_mapped)),
821 : pair<Iterator, bool>{set_it->iter(),
false};
824template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
827 const auto set_it = m_value_iter_set.find(key);
828 return ((set_it == m_value_iter_set.end())
835template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
838 const auto set_it = m_value_iter_set.
find(key);
839 return ((set_it == m_value_iter_set.end())
847template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
848typename Linked_hash_map<Key_t, Mapped_t, Hash_t, Pred_t>::Iterator
853 m_value_list.emplace_front(key_and_mapped);
858 const auto list_it = m_value_list.
begin();
859 m_value_iter_set.insert(list_it);
863template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
869 m_value_list.emplace_front(std::move(key_and_mapped));
871 const auto list_it = m_value_list.
begin();
872 m_value_iter_set.insert(list_it);
876template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
880 const auto set_it = m_value_iter_set.
find(key);
881 return (set_it == m_value_iter_set.end()) ? m_value_list.end() : set_it->iter();
884template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
888 const auto set_it = m_value_iter_set.
find(key);
889 return (set_it == m_value_iter_set.cend()) ? m_value_list.cend() : set_it->iter();
892template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
896 return m_value_iter_set.
count(key);
899template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
902 m_value_list.splice(m_value_list.begin(), m_value_list, it);
905template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
908 const auto it = find(key);
919template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
923 m_value_iter_set.
erase(it->first);
926 return m_value_list.erase(it);
929template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
934 for (
auto it = it_newest; it != it_past_oldest; ++it)
936 m_value_iter_set.
erase(it->first);
939 return m_value_list.erase(it_newest, it_past_oldest);
942template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
946 const auto set_it = m_value_iter_set.
find(key);
947 if (set_it == m_value_iter_set.end())
953 const auto list_it = set_it->iter();
954 m_value_iter_set.erase(set_it);
955 m_value_list.erase(list_it);
960template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
963 m_value_iter_set.
clear();
964 m_value_list.clear();
967template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
971 return m_value_list.
begin();
974template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
981template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
985 return m_value_list.
end();
988template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
992 return past_oldest();
995template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
999 return m_value_list.
cbegin();
1002template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
1006 return const_newest();
1009template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
1013 return const_newest();
1016template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
1020 return m_value_list.
cend();
1023template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
1027 return const_past_oldest();
1030template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
1034 return const_past_oldest();
1037template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
1041 return m_value_list.
rbegin();
1044template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
1051template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
1055 return m_value_list.
rend();
1058template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
1062 return past_newest();
1065template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
1069 return m_value_list.
crbegin();
1072template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
1076 return const_oldest();
1079template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
1083 return m_value_list.
crend();
1086template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
1090 return const_past_newest();
1093template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
1097 return m_value_iter_set.
size();
1100template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
1103 return m_value_list.
empty();
1106template<
typename Key_t,
typename Mapped_t,
typename Hash_t,
typename Pred_t>
1110 return std::min(m_value_iter_set.max_size(), m_value_list.max_size());
1113template<
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_map<> and ordering an...
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...
std::pair< Key const, Mapped > Value
Short-hand for key/mapped-value pairs stored in the structure.
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().
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...
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 unordered_set) implementation of this->...
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.
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.
Linked_hash_map(std::initializer_list< Value > values, size_type n_buckets=size_type(-1), const Hash &hasher_obj=Hash{}, const Pred &pred=Pred{})
Constructs structure with some basic parameters, and values initialized from initializer list.
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.
Linked_hash_map(size_type n_buckets=size_type(-1), const Hash &hasher_obj=Hash{}, const Pred &pred=Pred{})
Constructs empty structure with some basic parameters.
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...
void swap(Basic_blob< Allocator, SHARING > &blob1, Basic_blob< Allocator, SHARING > &blob2, log::Logger *logger_ptr) noexcept
Equivalent to blob1.swap(blob2).
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).