14#ifndef CXXUTILS_CONCURRENTTOVALMAP_H
15#define CXXUTILS_CONCURRENTTOVALMAP_H
23#include "boost/iterator/iterator_facade.hpp"
94template <
class KEY,
class VALUE,
template <
class>
class UPDATER,
95 class HASHER = std::hash<KEY>,
96 class MATCHER = std::equal_to<KEY>,
154 const Context_t& ctx = Updater_t::defaultContext());
170 const Context_t& ctx = Updater_t::defaultContext());
185 template <
class InputIterator>
190 const Context_t& ctx = Updater_t::defaultContext());
253 :
public boost::iterator_facade<const_iterator,
254 const const_iterator_value,
255 std::bidirectional_iterator_tag,
256 const const_iterator_value>
283 friend class boost::iterator_core_access;
336 :
public boost::iterator_facade<iterator,
337 const iterator_value,
338 std::bidirectional_iterator_tag,
339 const iterator_value>
359 friend class boost::iterator_core_access;
427 const_iterator
end()
const;
528 std::pair<const_iterator, const_iterator>
542 std::pair<iterator, iterator>
557 std::pair<const_iterator, bool>
559 const Context_t& ctx = Updater_t::defaultContext());
573 std::pair<const_iterator, bool>
575 const Context_t& ctx = Updater_t::defaultContext());
589 std::pair<const_iterator, bool>
591 const Context_t& ctx = Updater_t::defaultContext());
606 template <
class PAIR>
607 std::pair<const_iterator, bool>
insert (
const PAIR& p,
608 const Context_t& ctx = Updater_t::defaultContext());
623 template <
class PAIR>
624 std::pair<const_iterator, bool>
insert (PAIR&& p,
625 const Context_t& ctx = Updater_t::defaultContext());
637 template <
class InputIterator>
638 void insert (InputIterator first, InputIterator last,
639 const Context_t& ctx = Updater_t::defaultContext());
651 const Context_t& ctx = Updater_t::defaultContext());
741 std::pair<const_iterator, bool>
743 std::unique_ptr<mapped_type> val,
744 const Context_t& ctx = Updater_t::defaultContext());
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 const_iterator_value dereference() const
iterator_facade requirement: Dereference the iterator.
Impl_t::const_iterator m_impl
The iterator on the underlying table.
void increment()
iterator_facade requirement: Increment the iterator.
bool equal(const const_iterator &other) const
iterator_facade requirement: Equality test.
bool valid() const
Test if this iterator is valid.
void decrement()
iterator_facade requirement: Decrement the iterator.
const_iterator(typename Impl_t::const_iterator it)
Constructor.
const_iterator(const iterator &other)
Conversion from non-const iterator (for interoperability).
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.
bool equal(const const_iterator &other) const
iterator_facade requirement: Equality test.
bool equal(const iterator &other) const
iterator_facade requirement: Equality test.
bool valid() const
Test if this iterator is valid.
friend class const_iterator
void decrement()
iterator_facade requirement: Decrement the iterator.
Impl_t::const_iterator m_impl
The iterator on the underlying table.
iterator(typename Impl_t::const_iterator it)
Constructor.
ConcurrentToValMap(InputIterator f, InputIterator l, Updater_t &&updater, size_type capacity=64, const Context_t &ctx=Updater_t::defaultContext())
Constructor from a range.
iterator begin()
Iterator at the start of the map.
Impl_t::const_iterator get(const key_type key) const
Do a lookup in the table.
const_iterator begin() const
Iterator at the start of the map.
ConcurrentToValMap(ConcurrentToValMap &&other)=delete
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< iterator, iterator > equal_range(const key_type key)
Return a range of iterators with entries matching key.
const mapped_type & at(const key_type key) const
Look up an element in the map.
const_iterator cend() const
Iterator at the end of the map.
iterator find(const key_type key)
Look up an element in the map.
iterator end()
Iterator at the end of the map.
const_iterator_range range() const
Return an iterator range covering the entire map.
CxxUtils::iterator_range< const_iterator > const_iterator_range
A range defined by two iterators.
size_type size() const
Return the number of items currently in the map.
void quiescent(const Context_t &ctx)
Called when this thread is no longer referencing anything from this container.
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 key_type, const mapped_type & > const_iterator_value
Value structures for iterators.
typename detail::ConcurrentHashmapImpl< UPDATER, Hasher, Matcher, NULLVAL > Impl_t
The underlying uint->uint hash table.
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.
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.
void reserve(size_type capacity, const Context_t &ctx=Updater_t::defaultContext())
Increase the table capacity.
ConcurrentToValMap(Updater_t &&updater, size_type capacity=64, const Context_t &ctx=Updater_t::defaultContext())
Constructor.
iterator_range range()
Return an iterator range covering the entire map.
std::pair< const_iterator, bool > insert(PAIR &&p, const Context_t &ctx=Updater_t::defaultContext())
Add an element to the map.
CxxUtils::iterator_range< iterator > iterator_range
const_iterator find(const key_type key) const
Look up an element in the map.
std::pair< const key_type, mapped_type & > iterator_value
const_iterator end() const
Iterator at the end of the map.
std::pair< const_iterator, const_iterator > equal_range(const key_type key) const
Return a range of iterators with entries matching key.
void swap(ConcurrentToValMap &other)
Swap this container with another.
~ConcurrentToValMap()
Destructor.
static val_t mappedAsVal(mapped_type *val)
Convert this type's mapped value to an underlying mapped value.
ConcurrentToValMap(const ConcurrentToValMap &other, Updater_t &&updater, size_t capacity=64, const Context_t &ctx=Updater_t::defaultContext())
Constructor from another map.
static val_t keyAsVal(key_type k)
Convert this type's key value to an underlying key value.
ConcurrentToValMap(const ConcurrentToValMap &other)=delete
Copy / move / assign not supported.
typename Impl_t::Updater_t Updater_t
Updater object.
static key_type keyAsKey(val_t val)
Convert an underlying key value to this type's key value.
bool empty() const
Test if the map is currently empty.
static mapped_type * mappedAsMapped(val_t val)
Convert an underlying mapped value a pointer to this type's mapped value.
typename Updater_t::Context_t Context_t
Context type.
CxxUtils::detail::ConcurrentHashmapVal_t val_t
Representation type in the underlying map.
bool contains(const key_type key) const
Test if a key is in the container.
const_iterator cbegin() const
Iterator at the start of the map.
void rehash(size_type capacity)
Increase the table capacity.
size_type count(const key_type key) const
Return the number of times a given key is in the container.
std::pair< const_iterator, bool > put(const key_type key, std::unique_ptr< mapped_type > val, const Context_t &ctx=Updater_t::defaultContext())
Insert an entry in the table.
mapped_type & at(const key_type key)
Look up an element in the map.
KEY key_type
Standard STL types.
void insert(InputIterator first, InputIterator last, const Context_t &ctx=Updater_t::defaultContext())
Insert a range of elements to the map.
Hash table allowing concurrent, lockless reads.
Simple range from a pair of iterators.
Concept for a value that can be saved in a concurrent hash map.
Concept check for Updater class used by concurrent classes.
A couple standard-library related concepts.
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.