14#ifndef CXXUTILS_CONCURRENTSTRTOVALMAP_H
15#define CXXUTILS_CONCURRENTSTRTOVALMAP_H
22#include "boost/iterator/iterator_facade.hpp"
83template <
class VALUE,
template <
class>
class UPDATER>
117 const Context_t& ctx = Updater_t::defaultContext());
133 const Context_t& ctx = Updater_t::defaultContext());
148 template <
class InputIterator>
153 const Context_t& ctx = Updater_t::defaultContext());
202 class const_iterator;
216 :
public boost::iterator_facade<const_iterator,
217 const const_iterator_value,
218 std::bidirectional_iterator_tag,
219 const const_iterator_value>
246 friend class boost::iterator_core_access;
299 :
public boost::iterator_facade<iterator,
300 const iterator_value,
301 std::bidirectional_iterator_tag,
302 const iterator_value>
322 friend class boost::iterator_core_access;
390 const_iterator
end()
const;
491 std::pair<const_iterator, const_iterator>
505 std::pair<iterator, iterator>
520 std::pair<const_iterator, bool>
522 const Context_t& ctx = Updater_t::defaultContext());
536 std::pair<const_iterator, bool>
538 const Context_t& ctx = Updater_t::defaultContext());
552 std::pair<const_iterator, bool>
554 const Context_t& ctx = Updater_t::defaultContext());
568 std::pair<const_iterator, bool>
570 const Context_t& ctx = Updater_t::defaultContext());
584 std::pair<const_iterator, bool>
586 const Context_t& ctx = Updater_t::defaultContext());
600 std::pair<const_iterator, bool>
602 const Context_t& ctx = Updater_t::defaultContext());
617 template <
class PAIR>
618 std::pair<const_iterator, bool>
insert (
const PAIR& p,
619 const Context_t& ctx = Updater_t::defaultContext());
634 template <
class PAIR>
635 std::pair<const_iterator, bool>
insert (PAIR&& p,
636 const Context_t& ctx = Updater_t::defaultContext());
648 template <
class InputIterator>
649 void insert (InputIterator first, InputIterator last,
650 const Context_t& ctx = Updater_t::defaultContext());
662 const Context_t& ctx = Updater_t::defaultContext());
752 std::pair<const_iterator, bool>
753 put (std::unique_ptr<key_type> key,
754 std::unique_ptr<mapped_type> val,
755 const Context_t& ctx = Updater_t::defaultContext());
767 size_t operator() (
const val_t p)
const;
769 size_t operator() (
const std::string& s)
const;
Hash table allowing concurrent, lockless reads.
Concept check for Updater class used by concurrent classes.
Helpers for converting between uintptr_t and a pointer or integer.
const_iterator(const iterator &other)
Conversion from non-const iterator (for interoperability).
void increment()
iterator_facade requirement: Increment the iterator.
Impl_t::const_iterator m_impl
The iterator on the underlying table.
bool equal(const iterator &other) const
iterator_facade requirement: Equality test.
bool equal(const const_iterator &other) const
iterator_facade requirement: Equality test.
void decrement()
iterator_facade requirement: Decrement the iterator.
const_iterator(typename Impl_t::const_iterator it)
Constructor.
bool valid() const
Test if this iterator is valid.
const const_iterator_value dereference() const
iterator_facade requirement: Dereference the iterator.
void decrement()
iterator_facade requirement: Decrement the iterator.
bool equal(const iterator &other) const
iterator_facade requirement: Equality test.
const iterator_value dereference() const
iterator_facade requirement: Dereference the iterator.
void increment()
iterator_facade requirement: Increment the iterator.
iterator(typename Impl_t::const_iterator it)
Constructor.
friend class const_iterator
bool valid() const
Test if this iterator is valid.
bool equal(const const_iterator &other) const
iterator_facade requirement: Equality test.
Impl_t::const_iterator m_impl
The iterator on the underlying table.
CxxUtils::iterator_range< iterator > iterator_range
iterator begin()
Iterator at the start of the map.
bool empty() const
Test if the map is currently empty.
ConcurrentStrToValMap(const ConcurrentStrToValMap &other, Updater_t &&updater, size_t capacity=64, const Context_t &ctx=Updater_t::defaultContext())
Constructor from another map.
void rehash(size_type capacity)
Increase the table capacity.
ConcurrentStrToValMap(const ConcurrentStrToValMap &other)=delete
Copy / move / assign not supported.
mapped_type & at(const key_type &key)
Look up an element in the map.
std::pair< const_iterator, const_iterator > equal_range(const key_type &key) const
Return a range of iterators with entries matching key.
const_iterator end() const
Iterator at the end of the map.
std::pair< const_iterator, bool > emplace(const key_type &key, const mapped_type &val, const Context_t &ctx=Updater_t::defaultContext())
Add an element to the map.
const_iterator_range range() const
Return an iterator range covering the entire map.
std::pair< const key_type, mapped_type & > iterator_value
std::pair< const_iterator, bool > insert(PAIR &&p, const Context_t &ctx=Updater_t::defaultContext())
Add an element to the map.
ConcurrentStrToValMap(Updater_t &&updater, size_type capacity=64, const Context_t &ctx=Updater_t::defaultContext())
Constructor.
std::pair< const_iterator, bool > emplace(const key_type &key, mapped_type &&val, const Context_t &ctx=Updater_t::defaultContext())
Add an element to the map.
CxxUtils::detail::ConcurrentHashmapVal_t val_t
ConcurrentStrToValMap(InputIterator f, InputIterator l, Updater_t &&updater, size_type capacity=64, const Context_t &ctx=Updater_t::defaultContext())
Constructor from a range.
typename Impl_t::Updater_t Updater_t
std::pair< const_iterator, bool > emplace(key_type &&key, mapped_type &&val, const Context_t &ctx=Updater_t::defaultContext())
Add an element to the map.
std::pair< const_iterator, bool > emplace(const key_type &key, std::unique_ptr< mapped_type > val, const Context_t &ctx=Updater_t::defaultContext())
Add an element to the map.
const_iterator cend() const
Iterator at the end of the map.
size_type count(const key_type &key) const
Return the number of times a given key is in the container.
CxxUtils::iterator_range< const_iterator > const_iterator_range
static val_t keyAsVal(const std::string *s)
Convert a string pointer to an underlying key value.
const_iterator find(const key_type &key) const
Look up an element in the map.
iterator end()
Iterator at the end of the map.
void quiescent(const Context_t &ctx)
Called when this thread is no longer referencing anything from this container.
void swap(ConcurrentStrToValMap &other)
Swap this container with another.
std::pair< const key_type &, const mapped_type & > const_iterator_value
const_iterator begin() const
Iterator at the start of the map.
std::pair< const_iterator, bool > emplace(key_type &&key, const mapped_type &val, const Context_t &ctx=Updater_t::defaultContext())
Add an element to the map.
static mapped_type * mappedAsMapped(val_t val)
Convert an underlying mapped value a pointer to this type's mapped value.
static val_t mappedAsVal(mapped_type *val)
Convert this type's mapped value to an underlying mapped value.
bool contains(const key_type &key) const
Test if a key is in the container.
std::pair< const_iterator, bool > emplace(key_type &&key, std::unique_ptr< mapped_type > val, const Context_t &ctx=Updater_t::defaultContext())
Add an element to the map.
static const std::string * keyAsString(val_t val)
Convert an underlying key value to a string pointer.
Impl_t::const_iterator get(const key_type &key) const
Do a lookup in the table.
const mapped_type & at(const key_type &key) const
Look up an element in the map.
size_type size() const
Return the number of items currently in the map.
void insert(InputIterator first, InputIterator last, const Context_t &ctx=Updater_t::defaultContext())
Insert a range of elements to the map.
std::vector< std::shared_ptr< Monitored::HistogramFiller > > mapped_type
void reserve(size_type capacity, const Context_t &ctx=Updater_t::defaultContext())
Increase the table capacity.
std::pair< const_iterator, bool > insert(const PAIR &p, const Context_t &ctx=Updater_t::defaultContext())
Add an element to the map.
std::pair< const_iterator, bool > put(std::unique_ptr< key_type > key, std::unique_ptr< mapped_type > val, const Context_t &ctx=Updater_t::defaultContext())
Insert an entry in the table.
iterator_range range()
Return an iterator range covering the entire map.
std::pair< iterator, iterator > equal_range(const key_type &key)
Return a range of iterators with entries matching key.
typename Updater_t::Context_t Context_t
~ConcurrentStrToValMap()
Destructor.
iterator find(const key_type &key)
Look up an element in the map.
typename detail::ConcurrentHashmapImpl< CxxUtils::SimpleUpdater, Hasher, Matcher > Impl_t
ConcurrentStrToValMap(ConcurrentStrToValMap &&other)=delete
const_iterator cbegin() const
Iterator at the start of the map.
Hash table allowing concurrent, lockless reads.
Simple range from a pair of iterators.
Concept check for Updater class used by concurrent classes.
Simple range from a pair of iterators.
uintptr_t ConcurrentHashmapVal_t
Type used for keys and values — an unsigned big enough to hold a pointer.
Hash functional for keys.
std::hash< std::string > m_hash
Hash functional.
Matching functional for keys.