23#include <boost/unordered_set.hpp>
24#include <boost/move/unique_ptr.hpp>
46template<
typename Key,
typename Hash,
typename Pred>
124 Hash
const & hasher_instance = Hash(),
125 Pred
const & key_equal_instance = Pred());
148 Hash
const & hasher_instance = Hash(),
149 Pred
const & key_equal_instance = Pred());
485template<
typename Key,
typename Hash,
typename Pred>
487 hasher const & hasher_instance,
494template<
typename Key,
typename Hash,
typename Pred>
497 hasher const & hasher_instance,
502 using boost::unordered_set;
508 unordered_set<Key, Hash, Pred> dummy;
509 n_buckets = dummy.bucket_count();
520 (*m_keys_into_list_map)[*value_list_it] = value_list_it;
524template<
typename Key,
typename Hash,
typename Pred>
531template<
typename Key,
typename Hash,
typename Pred>
538template<
typename Key,
typename Hash,
typename Pred>
554 using Mutable_key_list = list<Key>;
556 Mutable_key_list*
const dst_list_ptr
557 =
reinterpret_cast<Mutable_key_list*
>(&m_value_list);
558 const Mutable_key_list*
const src_list_ptr
559 =
reinterpret_cast<const Mutable_key_list*
>(&src.
m_value_list);
561 *dst_list_ptr = *src_list_ptr;
567 for (
Value_list_iter value_list_it = m_value_list.begin(); value_list_it != m_value_list.end();
571 (*m_keys_into_list_map)[*value_list_it] = value_list_it;
577template<
typename Key,
typename Hash,
typename Pred>
589template<
typename Key,
typename Hash,
typename Pred>
590std::pair<typename Linked_hash_set<Key, Hash, Pred>::Iterator,
bool>
597 typename Key_to_value_iter_map::iterator
const map_it = m_keys_into_list_map->find(key);
598 if (map_it != m_keys_into_list_map->end())
600 return pair<Iterator, bool>(map_it->second,
false);
602 return pair<Iterator, bool>(insert_impl(key),
true);
605template<
typename Key,
typename Hash,
typename Pred>
611 m_value_list.push_front(key);
612 Iterator const new_elem_it = m_value_list.begin();
613 (*m_keys_into_list_map)[key] = new_elem_it;
618template<
typename Key,
typename Hash,
typename Pred>
622 typename Key_to_value_iter_map::const_iterator
const map_it = m_keys_into_list_map->find(key);
623 return (map_it == m_keys_into_list_map->cend()) ? m_value_list.cend() : map_it->second;
626template<
typename Key,
typename Hash,
typename Pred>
630 return m_keys_into_list_map->count(key);
633template<
typename Key,
typename Hash,
typename Pred>
638 return *(const_newest());
641template<
typename Key,
typename Hash,
typename Pred>
646 return *(--const_past_oldest());
649template<
typename Key,
typename Hash,
typename Pred>
652 m_value_list.splice(m_value_list.begin(), m_value_list, it);
655template<
typename Key,
typename Hash,
typename Pred>
669template<
typename Key,
typename Hash,
typename Pred>
673 m_keys_into_list_map->erase(m_keys_into_list_map->find(*it));
674 return m_value_list.erase(it);
677template<
typename Key,
typename Hash,
typename Pred>
684 m_keys_into_list_map->erase(it->first);
687 return m_value_list.erase(it_newest, it_past_oldest);
690template<
typename Key,
typename Hash,
typename Pred>
694 typename Key_to_value_iter_map::iterator
const map_it = m_keys_into_list_map->find(key);
695 if (map_it == m_keys_into_list_map->end())
701 m_value_list.erase(map_it->second);
702 m_keys_into_list_map->erase(map_it);
707template<
typename Key,
typename Hash,
typename Pred>
711 erase(const_newest());
714template<
typename Key,
typename Hash,
typename Pred>
718 erase(--const_past_oldest());
721template<
typename Key,
typename Hash,
typename Pred>
724 m_keys_into_list_map->clear();
725 m_value_list.clear();
728template<
typename Key,
typename Hash,
typename Pred>
738template<
typename Key,
typename Hash,
typename Pred>
742 return m_value_list.cbegin();
745template<
typename Key,
typename Hash,
typename Pred>
752template<
typename Key,
typename Hash,
typename Pred>
759template<
typename Key,
typename Hash,
typename Pred>
766template<
typename Key,
typename Hash,
typename Pred>
770 return m_value_list.cend();
773template<
typename Key,
typename Hash,
typename Pred>
777 return past_oldest();
780template<
typename Key,
typename Hash,
typename Pred>
784 return past_oldest();
787template<
typename Key,
typename Hash,
typename Pred>
794template<
typename Key,
typename Hash,
typename Pred>
798 return m_value_list.crbegin();
801template<
typename Key,
typename Hash,
typename Pred>
808template<
typename Key,
typename Hash,
typename Pred>
815template<
typename Key,
typename Hash,
typename Pred>
822template<
typename Key,
typename Hash,
typename Pred>
826 return m_value_list.crend();
829template<
typename Key,
typename Hash,
typename Pred>
833 return past_newest();
836template<
typename Key,
typename Hash,
typename Pred>
840 return past_newest();
843template<
typename Key,
typename Hash,
typename Pred>
847 return m_value_list.rend();
850template<
typename Key,
typename Hash,
typename Pred>
854 return m_keys_into_list_map->size();
857template<
typename Key,
typename Hash,
typename Pred>
860 return m_keys_into_list_map->empty();
863template<
typename Key,
typename Hash,
typename Pred>
867 return std::min(m_keys_into_list_map->max_size(), m_value_list.max_size());
870template<
typename Key,
typename Hash,
typename Pred>
An object of this class is a set that combines the lookup speed of an unordered_set<> and ordering an...
bool empty() const
Returns true if and only if container is empty.
Const_iterator const_past_oldest() const
Returns one past last, a/k/a "oldest," element's iterator (to immutable element).
Const_iterator const_iterator
For container compliance (hence the irregular capitalization): Const_iterator type.
Iterator insert_impl(Value const &key)
Helper that modifies m_value_list and m_keys_into_list_map so that key's copy is inserted into the st...
Key key_type
For container compliance (hence the irregular capitalization): Key type.
Iterator begin() const
Synonym of newest().
Const_reverse_iterator const_past_newest() const
Returns one past last, a/k/a "newest," element's reverse iterator (to immutable element).
std::ptrdiff_t difference_type
Type for difference of size_types.
Const_iterator cend() const
Synonym of const_past_oldest().
Linked_hash_set(Linked_hash_set const &src)
Constructs object that is a copy of the given source.
Iterator erase(Const_iterator const &it_newest, Const_iterator const &it_past_oldest)
Erases all elements in the range [it_newest, it_past_oldest).
Const_iterator Iterator
Type for iterator pointing into a mutable structure of this type but actually that is not possible; s...
Iterator Value_list_iter
Short-hand for iterator into doubly linked list of Key elements.
Value const & const_reference
For container compliance (hence the irregular capitalization): reference to const Key type.
Const_iterator Value_list_const_iter
Short-hand for const iterator into doubly linked list of Key elements.
Pred key_equal
For container compliance (hence the irregular capitalization): Pred type.
void swap(Linked_hash_set &other)
Swaps the contents of this structure and other.
Value value_type
For container compliance (hence the irregular capitalization): Value type.
Iterator erase(Const_iterator const &it)
Erases the element pointed to by the given valid iterator.
Value_list m_value_list
See Linked_hash_map::m_value_list. Essentially all of that applies here.
std::pair< Iterator, bool > insert(Value const &key)
Attempts to insert the given key into the set.
Hash hasher
For container compliance (hence the irregular capitalization): Hash type.
typename Value_list::const_iterator Const_iterator
Type for iterator pointing into an immutable structure of this type.
Key Value
Short-hand for values, which in this case are simply the keys.
std::size_t size_type
Type for index into array of items, where items are all applicable objects including Values and Keys.
Reverse_iterator oldest() const
Returns first, a/k/a "oldest," element's reverse iterator (to immutable element, due to nature of thi...
void touch(Const_iterator const &it)
Given a valid iterator into the structure, makes the pointed to element "newest" by moving it from wh...
Value & reference
For container compliance (hence the irregular capitalization): reference to Key type.
Value * pointer
For container compliance (hence the irregular capitalization): pointer to Key type.
Iterator end() const
Synonym of past_oldest().
Value const & const_back() const
Returns reference to immutable back ("oldest") element in the structure; formally equivalent to *(--t...
Reverse_iterator past_newest() const
Returns one past last, a/k/a "newest," element's reverse iterator (to immutable element,...
Linked_hash_set(std::initializer_list< Value > values, size_type n_buckets=size_type(-1), Hash const &hasher_instance=Hash(), Pred const &key_equal_instance=Pred())
Constructs structure with some basic parameters, and values initialized from initializer list.
Const_reverse_iterator Reverse_iterator
Type for reverse iterator pointing into a mutable structure of this type but actually that is not pos...
void clear()
Makes it so that size() == 0.
void pop_front()
Queue-style pop (erase) of the front – a/k/a newest – element. Behavior undefined if empty().
Linked_hash_set & operator=(Linked_hash_set const &src)
Overwrites this object with a copy of the given source.
Const_iterator const_newest() const
Returns first, a/k/a "newest," element's iterator (to immutable element).
Reverse_iterator rend() const
Synonym of past_newest().
Value const & const_front() const
Returns reference to immutable front ("newest") element in the structure; formally equivalent to *(th...
Const_iterator find(Key const &key) const
Attempts to find the given key in the set.
size_type count(Key const &key) const
Returns the number of times a key is equivalent to the given one is present in the hash: either 1 or ...
Value const * const_pointer
For container compliance (hence the irregular capitalization): pointer to const Key type.
Const_reverse_iterator crbegin() const
Synonym of const_oldest().
typename Value_list::const_reverse_iterator Const_reverse_iterator
Type for reverse iterator pointing into an immutable structure of this type.
boost::movelib::unique_ptr< Key_to_value_iter_map > m_keys_into_list_map
See Linked_hash_map::m_keys_into_list_map. Essentially all of that applies here.
Const_iterator cbegin() const
Synonym of const_newest().
size_type erase(Key const &key)
Erases the element with the given key, if it exists.
Reverse_iterator rbegin() const
Synonym of oldest().
boost::unordered_map< Key, Value_list_iter, Hash, Pred > Key_to_value_iter_map
Short-hand for a hash map that maps Key to iterator into doubly linked list of Key elements.
void pop_back()
Queue-style pop (erase) of the back – a/k/a oldest – element. Behavior undefined if empty().
Iterator past_oldest() const
Returns one past last, a/k/a "oldest," element's iterator (to immutable element, due to nature of thi...
size_type max_size() const
Returns max number of elements that can be stored.
Iterator newest() const
Returns first, a/k/a "newest," element's iterator (to immutable element, due to nature of this type).
size_type size() const
Returns number of elements stored.
std::list< Value > Value_list
Short-hand for doubly linked list of Keys.
Iterator iterator
For container compliance (hence the irregular capitalization): Iterator type.
Const_reverse_iterator crend() const
Synonym of const_past_newest().
Linked_hash_set & operator=(Linked_hash_set &&src)
Overwrites this object making it equal to the given source, while the given source becomes as-if defa...
bool touch(Key const &key)
Given a key into the structure, makes the corresponding element "newest" by moving it from wherever i...
Const_reverse_iterator const_oldest() const
Returns first, a/k/a "oldest," element's reverse iterator (to immutable element).
Linked_hash_set(Linked_hash_set &&src)
Constructs object by making it equal to the given source, while the given source becomes as-if defaul...
Linked_hash_set(size_type n_buckets=size_type(-1), Hash const &hasher_instance=Hash(), Pred const &key_equal_instance=Pred())
Constructs empty structure with some basic parameters.
Flow module containing miscellaneous general-use facilities that don't fit into any other Flow module...
void swap(Basic_blob< Allocator, S_SHARING_ALLOWED > &blob1, Basic_blob< Allocator, S_SHARING_ALLOWED > &blob2, log::Logger *logger_ptr)
Equivalent to blob1.swap(blob2).
void swap(Linked_hash_set< Key, Hash, Pred > &val1, Linked_hash_set< Key, Hash, Pred > &val2)
Equivalent to val1.swap(val2).