13 #ifndef CXXUTILS_CONCURRENTSTRMAP_H
14 #define CXXUTILS_CONCURRENTSTRMAP_H
21 #include "boost/iterator/iterator_facade.hpp"
22 #include "boost/range/iterator_range.hpp"
23 #include <type_traits>
74 template <
class VALUE,
template <
class>
class UPDATER>
76 detail::IsUpdater<UPDATER>)
77 class ConcurrentStrMap
90 using key_type = std::string;
91 using mapped_type =
VALUE;
92 using size_type = size_t;
94 using Updater_t =
typename Impl_t::Updater_t;
96 using Context_t =
typename Updater_t::Context_t;
98 using Lock_t =
typename Impl_t::Lock_t;
101 static_assert(
sizeof(
typename Impl_t::val_t) >=
sizeof(mapped_type) );
112 ConcurrentStrMap (Updater_t&& updater,
113 size_type capacity = 64,
114 const Context_t& ctx = Updater_t::defaultContext());
126 ConcurrentStrMap (
const ConcurrentStrMap&
other,
128 size_t capacity = 64,
129 const Context_t& ctx = Updater_t::defaultContext());
144 template <
class InputIterator>
145 ConcurrentStrMap (InputIterator
f,
148 size_type capacity = 64,
149 const Context_t& ctx = Updater_t::defaultContext());
153 ConcurrentStrMap (
const ConcurrentStrMap&
other) =
delete;
154 ConcurrentStrMap (ConcurrentStrMap&&
other) =
delete;
155 ConcurrentStrMap& operator= (
const ConcurrentStrMap&
other) =
delete;
156 ConcurrentStrMap& operator= (ConcurrentStrMap&&
other) =
delete;
168 size_type
size()
const;
180 size_t capacity()
const;
195 using const_iterator_value = std::pair<const key_type&, mapped_type>;
208 :
public boost::iterator_facade<const_iterator,
209 const const_iterator_value,
210 std::bidirectional_iterator_tag,
211 const const_iterator_value>
218 const_iterator (
typename Impl_t::const_iterator
it);
231 friend class boost::iterator_core_access;
249 bool equal (
const const_iterator&
other)
const;
255 const const_iterator_value dereference()
const;
259 typename Impl_t::const_iterator m_impl;
264 typedef boost::iterator_range<const_iterator> const_iterator_range;
270 const_iterator_range
range()
const;
276 const_iterator
begin()
const;
282 const_iterator
end()
const;
288 const_iterator cbegin()
const;
294 const_iterator cend()
const;
310 size_type
count (
const key_type&
key)
const;
319 const_iterator
find (
const key_type&
key)
const;
329 mapped_type at (
const std::string&
key)
const;
339 std::pair<const_iterator, const_iterator>
340 equal_range (
const key_type&
key)
const;
365 std::pair<const_iterator, bool>
366 emplace (
const key_type&
key, mapped_type
val,
367 const Context_t& ctx = Updater_t::defaultContext());
382 std::pair<const_iterator, bool>
383 emplace (
const Lock_t& lock,
384 const key_type&
key, mapped_type
val,
385 const Context_t& ctx = Updater_t::defaultContext());
399 std::pair<const_iterator, bool>
400 emplace (key_type&&
key, mapped_type
val,
401 const Context_t& ctx = Updater_t::defaultContext());
416 std::pair<const_iterator, bool>
417 emplace (
const Lock_t& lock,
418 key_type&&
key, mapped_type
val,
419 const Context_t& ctx = Updater_t::defaultContext());
433 std::pair<const_iterator, bool>
434 insert_or_assign (
const key_type&
key, mapped_type
val,
435 const Context_t& ctx = Updater_t::defaultContext());
451 std::pair<const_iterator, bool>
452 insert_or_assign (
const Lock_t& lock,
453 const key_type&
key, mapped_type
val,
454 const Context_t& ctx = Updater_t::defaultContext());
468 std::pair<const_iterator, bool>
469 insert_or_assign (key_type&&
key, mapped_type
val,
470 const Context_t& ctx = Updater_t::defaultContext());
486 std::pair<const_iterator, bool>
487 insert_or_assign (
const Lock_t& lock,
488 key_type&&
key, mapped_type
val,
489 const Context_t& ctx = Updater_t::defaultContext());
506 template <
class PAIR>
507 std::pair<const_iterator, bool> insert (
const PAIR&
p,
508 const Context_t& ctx = Updater_t::defaultContext());
523 template <
class PAIR>
524 std::pair<const_iterator, bool> insert (PAIR&&
p,
525 const Context_t& ctx = Updater_t::defaultContext());
537 template <
class InputIterator>
538 void insert (InputIterator
first, InputIterator last,
539 const Context_t& ctx = Updater_t::defaultContext());
550 void reserve (size_type capacity,
551 const Context_t& ctx = Updater_t::defaultContext());
561 void rehash (size_type capacity);
569 void quiescent (
const Context_t& ctx);
588 Updater_t& updater();
596 static const std::string* keyAsString (val_t
val);
603 static val_t keyAsVal (
const std::string*
s);
610 static mapped_type mappedAsMapped (val_t
val);
617 static val_t mappedAsVal (mapped_type
val);
627 typename Impl_t::const_iterator
get (
const key_type&
key)
const;
641 std::pair<const_iterator, bool>
642 put (std::unique_ptr<key_type>
key,
644 bool overwrite =
true,
645 const Context_t& ctx = Updater_t::defaultContext());
659 std::pair<const_iterator, bool>
660 put (
const Lock_t& lock,
661 std::unique_ptr<key_type>
key,
663 bool overwrite =
true,
664 const Context_t& ctx = Updater_t::defaultContext());
676 size_t operator() (
const val_t
p)
const;
678 size_t operator() (
const std::string&
s)
const;
680 std::hash<std::string> m_hash;
690 bool operator() (
const val_t
a,
const val_t
b)
const;
705 #endif // not CXXUTILS_CONCURRENTSTRMAP_H