14 #ifndef CXXUTILS_CONCURRENTTOVALMAP_H
15 #define CXXUTILS_CONCURRENTTOVALMAP_H
22 #include "boost/iterator/iterator_facade.hpp"
23 #include "boost/range/iterator_range.hpp"
25 #include <type_traits>
94 template <
class KEY,
class VALUE,
template <
class>
class UPDATER,
95 class HASHER = std::hash<KEY>,
96 class MATCHER = std::equal_to<KEY>,
99 detail::IsUpdater<UPDATER> &&
100 detail::IsHash<HASHER, KEY> &&
101 detail::IsBinaryPredicate<MATCHER, KEY>)
102 class ConcurrentToValMap
113 size_t operator() (val_t
k)
const {
114 return m_h (keyAsKey (
k));
120 bool operator() (val_t
a, val_t
b)
const {
121 return m_m (keyAsKey (
a), keyAsKey (
b));
135 using key_type = KEY;
136 using mapped_type =
VALUE;
137 using size_type = size_t;
139 using Updater_t =
typename Impl_t::Updater_t;
141 using Context_t =
typename Updater_t::Context_t;
152 ConcurrentToValMap (Updater_t&& updater,
153 size_type capacity = 64,
154 const Context_t& ctx = Updater_t::defaultContext());
167 ConcurrentToValMap (
const ConcurrentToValMap&
other,
169 size_t capacity = 64,
170 const Context_t& ctx = Updater_t::defaultContext());
185 template <
class InputIterator>
186 ConcurrentToValMap (InputIterator
f,
189 size_type capacity = 64,
190 const Context_t& ctx = Updater_t::defaultContext());
194 ConcurrentToValMap (
const ConcurrentToValMap&
other) =
delete;
195 ConcurrentToValMap (ConcurrentToValMap&&
other) =
delete;
196 ConcurrentToValMap& operator= (
const ConcurrentToValMap&
other) =
delete;
197 ConcurrentToValMap& operator= (ConcurrentToValMap&&
other) =
delete;
203 ~ConcurrentToValMap();
209 size_type
size()
const;
221 size_t capacity()
const;
236 using const_iterator_value = std::pair<const key_type, const mapped_type&>;
237 using iterator_value = std::pair<const key_type, mapped_type&>;
239 class const_iterator;
253 :
public boost::iterator_facade<const_iterator,
254 const const_iterator_value,
255 std::bidirectional_iterator_tag,
256 const const_iterator_value>
263 const_iterator (
typename Impl_t::const_iterator
it);
283 friend class boost::iterator_core_access;
302 bool equal (
const const_iterator&
other)
const;
314 const const_iterator_value dereference()
const;
318 typename Impl_t::const_iterator m_impl;
336 :
public boost::iterator_facade<iterator,
337 const iterator_value,
338 std::bidirectional_iterator_tag,
339 const iterator_value>
346 iterator (
typename Impl_t::const_iterator
it);
359 friend class boost::iterator_core_access;
360 friend class const_iterator;
384 bool equal (
const const_iterator&
other)
const;
390 const iterator_value dereference()
const;
394 typename Impl_t::const_iterator m_impl;
399 typedef boost::iterator_range<const_iterator> const_iterator_range;
400 typedef boost::iterator_range<iterator> iterator_range;
406 const_iterator_range
range()
const;
415 iterator_range
range();
421 const_iterator
begin()
const;
427 const_iterator
end()
const;
451 const_iterator cbegin()
const;
457 const_iterator cend()
const;
473 size_type
count (
const key_type
key)
const;
482 const_iterator
find (
const key_type
key)
const;
504 const mapped_type& at (
const key_type
key)
const;
518 mapped_type& at (
const key_type
key);
528 std::pair<const_iterator, const_iterator>
529 equal_range (
const key_type
key)
const;
542 std::pair<iterator, iterator>
543 equal_range (
const key_type
key);
557 std::pair<const_iterator, bool>
558 emplace (key_type
key,
const mapped_type&
val,
559 const Context_t& ctx = Updater_t::defaultContext());
573 std::pair<const_iterator, bool>
574 emplace (key_type
key, mapped_type&&
val,
575 const Context_t& ctx = Updater_t::defaultContext());
589 std::pair<const_iterator, bool>
590 emplace (key_type
key, std::unique_ptr<mapped_type>
val,
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());
650 void reserve (size_type capacity,
651 const Context_t& ctx = Updater_t::defaultContext());
661 void rehash (size_type capacity);
669 void quiescent (
const Context_t& ctx);
688 Updater_t& updater();
696 static key_type keyAsKey (val_t
val);
703 static val_t keyAsVal (key_type
k);
711 static mapped_type* mappedAsMapped (val_t
val);
718 static val_t mappedAsVal (mapped_type*
val);
728 typename Impl_t::const_iterator
get (
const key_type
key)
const;
741 std::pair<const_iterator, bool>
742 put (
const key_type
key,
743 std::unique_ptr<mapped_type>
val,
744 const Context_t& ctx = Updater_t::defaultContext());
758 #endif // not CXXUTILS_CONCURRENTTOVALMAP_H