13 #ifndef CXXUTILS_CONCURRENTMAP_H
14 #define CXXUTILS_CONCURRENTMAP_H
21 #include "boost/iterator/iterator_facade.hpp"
22 #include "boost/range/iterator_range.hpp"
23 #include <type_traits>
89 template <
class KEY,
class VALUE,
template <
class>
class UPDATER,
90 class HASHER = std::hash<KEY>,
91 class MATCHER = std::equal_to<KEY>,
95 detail::IsConcurrentHashmapPayload<VALUE> &&
96 detail::IsUpdater<UPDATER> &&
97 detail::IsHash<HASHER, KEY> &&
98 detail::IsBinaryPredicate<MATCHER, KEY>)
110 size_t operator() (val_t
k)
const {
111 return m_h (keyAsKey (
k));
117 bool operator() (val_t
a, val_t
b)
const {
118 return m_m (keyAsKey (
a), keyAsKey (
b));
133 using key_type = KEY;
134 using mapped_type =
VALUE;
135 using size_type = size_t;
137 using Updater_t =
typename Impl_t::Updater_t;
139 using Context_t =
typename Updater_t::Context_t;
141 using Lock_t =
typename Impl_t::Lock_t;
144 static_assert(
sizeof(
typename Impl_t::val_t) >=
sizeof(key_type) );
145 static_assert(
sizeof(
typename Impl_t::val_t) >=
sizeof(mapped_type) );
156 ConcurrentMap (Updater_t&& updater,
157 size_type capacity = 64,
158 const Context_t& ctx = Updater_t::defaultContext());
170 ConcurrentMap (
const ConcurrentMap&
other,
172 size_t capacity = 64,
173 const Context_t& ctx = Updater_t::defaultContext());
188 template <
class InputIterator>
189 ConcurrentMap (InputIterator
f,
192 size_type capacity = 64,
193 const Context_t& ctx = Updater_t::defaultContext());
197 ConcurrentMap (
const ConcurrentMap&
other) =
delete;
198 ConcurrentMap (ConcurrentMap&&
other) =
delete;
199 ConcurrentMap& operator= (
const ConcurrentMap&
other) =
delete;
200 ConcurrentMap& operator= (ConcurrentMap&&
other) =
delete;
206 ~ConcurrentMap() =
default;
212 size_type
size()
const;
224 size_t capacity()
const;
230 size_t erased()
const;
236 using const_iterator_value = std::pair<const key_type, mapped_type>;
249 :
public boost::iterator_facade<const_iterator,
250 const const_iterator_value,
251 std::bidirectional_iterator_tag,
252 const const_iterator_value>
259 const_iterator (
typename Impl_t::const_iterator
it);
272 friend class boost::iterator_core_access;
290 bool equal (
const const_iterator&
other)
const;
296 const const_iterator_value dereference()
const;
300 typename Impl_t::const_iterator m_impl;
305 typedef boost::iterator_range<const_iterator> const_iterator_range;
311 const_iterator_range
range()
const;
317 const_iterator
begin()
const;
323 const_iterator
end()
const;
329 const_iterator cbegin()
const;
335 const_iterator cend()
const;
351 size_type
count (key_type
key)
const;
360 const_iterator
find (key_type
key)
const;
370 mapped_type at (key_type
key)
const;
380 std::pair<const_iterator, const_iterator>
381 equal_range (key_type
key)
const;
406 std::pair<const_iterator, bool>
407 emplace (key_type
key, mapped_type
val,
408 const Context_t& ctx = Updater_t::defaultContext());
423 std::pair<const_iterator, bool>
424 emplace (
const Lock_t& lock,
425 key_type
key, mapped_type
val,
426 const Context_t& ctx = Updater_t::defaultContext());
440 std::pair<const_iterator, bool>
441 insert_or_assign (key_type
key, mapped_type
val,
442 const Context_t& ctx = Updater_t::defaultContext());
458 std::pair<const_iterator, bool>
459 insert_or_assign (
const Lock_t& lock,
460 key_type
key, mapped_type
val,
461 const Context_t& ctx = Updater_t::defaultContext());
477 template <
class PAIR>
478 std::pair<const_iterator, bool> insert (
const PAIR&
p);
489 template <
class InputIterator>
490 void insert (InputIterator
first, InputIterator last);
505 bool erase (key_type
key);
521 bool erase (
const Lock_t& lock, key_type
key);
532 void reserve (size_type capacity,
533 const Context_t& ctx = Updater_t::defaultContext());
543 void rehash (size_type capacity);
551 void clear (
size_t capacity,
552 const Context_t& ctx = Updater_t::defaultContext());
559 void clear (
const Context_t& ctx = Updater_t::defaultContext());
578 void quiescent (
const Context_t& ctx);
598 Updater_t& updater();
606 static key_type keyAsKey (val_t
val);
613 static val_t keyAsVal (key_type
k);
620 static mapped_type mappedAsMapped (val_t
val);
627 static val_t mappedAsVal (mapped_type
val);
637 typename Impl_t::const_iterator
get (key_type
key)
const;
651 std::pair<const_iterator, bool>
654 bool overwrite =
true,
655 const Context_t& ctx = Updater_t::defaultContext());
670 std::pair<const_iterator, bool>
671 put (
const Lock_t& lock,
674 bool overwrite =
true,
675 const Context_t& ctx = Updater_t::defaultContext());
689 #endif // not CXXUTILS_CONCURRENTMAP_H