Loading [MathJax]/jax/input/TeX/config.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ConcurrentStrMap.h
Go to the documentation of this file.
1 // This file's extension implies that it's C, but it's really -*- C++ -*-.
2 /*
3  * Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration.
4  */
13 #ifndef CXXUTILS_CONCURRENTSTRMAP_H
14 #define CXXUTILS_CONCURRENTSTRMAP_H
15 
16 
18 #include "CxxUtils/UIntConv.h"
19 #include "CxxUtils/IsUpdater.h"
20 #include "boost/iterator/iterator_facade.hpp"
21 #include "boost/range/iterator_range.hpp"
22 #include <type_traits>
23 #include <stdexcept>
24 
25 
26 namespace CxxUtils {
27 
28 
73 template <class VALUE, template <class> class UPDATER>
74 requires (detail::IsConcurrentHashmapPayload<VALUE> &&
75  detail::IsUpdater<UPDATER>)
76 class ConcurrentStrMap
77 {
78 private:
80  struct Hasher;
81  struct Matcher;
85 
86 
87 public:
89  using key_type = std::string;
90  using mapped_type = VALUE;
91  using size_type = size_t;
93  using Updater_t = typename Impl_t::Updater_t;
95  using Context_t = typename Updater_t::Context_t;
97  using Lock_t = typename Impl_t::Lock_t;
98 
100  static_assert( sizeof(typename Impl_t::val_t) >= sizeof(mapped_type) );
101 
102 
111  ConcurrentStrMap (Updater_t&& updater,
112  size_type capacity = 64,
113  const Context_t& ctx = Updater_t::defaultContext());
114 
125  ConcurrentStrMap (const ConcurrentStrMap& other,
126  Updater_t&& updater,
127  size_t capacity = 64,
128  const Context_t& ctx = Updater_t::defaultContext());
129 
130 
143  template <class InputIterator>
144  ConcurrentStrMap (InputIterator f,
145  InputIterator l,
146  Updater_t&& updater,
147  size_type capacity = 64,
148  const Context_t& ctx = Updater_t::defaultContext());
149 
150 
152  ConcurrentStrMap (const ConcurrentStrMap& other) = delete;
153  ConcurrentStrMap (ConcurrentStrMap&& other) = delete;
154  ConcurrentStrMap& operator= (const ConcurrentStrMap& other) = delete;
155  ConcurrentStrMap& operator= (ConcurrentStrMap&& other) = delete;
156 
157 
161  ~ConcurrentStrMap();
162 
163 
167  size_type size() const;
168 
169 
173  bool empty() const;
174 
175 
179  size_t capacity() const;
180 
181 
194  using const_iterator_value = std::pair<const key_type&, mapped_type>;
195 
196 
206  class const_iterator
207  : public boost::iterator_facade<const_iterator,
208  const const_iterator_value,
209  std::bidirectional_iterator_tag,
210  const const_iterator_value>
211  {
212  public:
217  const_iterator (typename Impl_t::const_iterator it);
218 
219 
225  bool valid() const;
226 
227 
228  private:
230  friend class boost::iterator_core_access;
231 
232 
236  void increment();
237 
238 
242  void decrement();
243 
244 
248  bool equal (const const_iterator& other) const;
249 
250 
254  const const_iterator_value dereference() const;
255 
256 
258  typename Impl_t::const_iterator m_impl;
259  };
260 
261 
263  typedef boost::iterator_range<const_iterator> const_iterator_range;
264 
265 
269  const_iterator_range range() const;
270 
271 
275  const_iterator begin() const;
276 
277 
281  const_iterator end() const;
282 
283 
287  const_iterator cbegin() const;
288 
289 
293  const_iterator cend() const;
294 
295 
300  bool contains (const key_type& key) const;
301 
302 
309  size_type count (const key_type& key) const;
310 
311 
318  const_iterator find (const key_type& key) const;
319 
320 
328  mapped_type at (const std::string& key) const;
329 
330 
338  std::pair<const_iterator, const_iterator>
339  equal_range (const key_type& key) const;
340 
341 
350  Lock_t lock();
351 
352 
364  std::pair<const_iterator, bool>
365  emplace (const key_type& key, mapped_type val,
366  const Context_t& ctx = Updater_t::defaultContext());
367 
368 
381  std::pair<const_iterator, bool>
382  emplace (const Lock_t& lock,
383  const key_type& key, mapped_type val,
384  const Context_t& ctx = Updater_t::defaultContext());
385 
386 
398  std::pair<const_iterator, bool>
399  emplace (key_type&& key, mapped_type val,
400  const Context_t& ctx = Updater_t::defaultContext());
401 
402 
415  std::pair<const_iterator, bool>
416  emplace (const Lock_t& lock,
417  key_type&& key, mapped_type val,
418  const Context_t& ctx = Updater_t::defaultContext());
419 
420 
432  std::pair<const_iterator, bool>
433  insert_or_assign (const key_type& key, mapped_type val,
434  const Context_t& ctx = Updater_t::defaultContext());
435 
436 
450  std::pair<const_iterator, bool>
451  insert_or_assign (const Lock_t& lock,
452  const key_type& key, mapped_type val,
453  const Context_t& ctx = Updater_t::defaultContext());
454 
455 
467  std::pair<const_iterator, bool>
468  insert_or_assign (key_type&& key, mapped_type val,
469  const Context_t& ctx = Updater_t::defaultContext());
470 
471 
485  std::pair<const_iterator, bool>
486  insert_or_assign (const Lock_t& lock,
487  key_type&& key, mapped_type val,
488  const Context_t& ctx = Updater_t::defaultContext());
489 
490 
505  template <class PAIR>
506  std::pair<const_iterator, bool> insert (const PAIR& p,
507  const Context_t& ctx = Updater_t::defaultContext());
508 
509 
522  template <class PAIR>
523  std::pair<const_iterator, bool> insert (PAIR&& p,
524  const Context_t& ctx = Updater_t::defaultContext());
525 
526 
536  template <class InputIterator>
537  void insert (InputIterator first, InputIterator last,
538  const Context_t& ctx = Updater_t::defaultContext());
539 
540 
549  void reserve (size_type capacity,
550  const Context_t& ctx = Updater_t::defaultContext());
551 
552 
560  void rehash (size_type capacity);
561 
562 
568  void quiescent (const Context_t& ctx);
569 
570 
581  void swap (ConcurrentStrMap& other);
582 
583 
587  Updater_t& updater();
588 
589 
590 private:
595  static const std::string* keyAsString (val_t val);
596 
597 
602  static val_t keyAsVal (const std::string* s);
603 
604 
609  static mapped_type mappedAsMapped (val_t val);
610 
611 
616  static val_t mappedAsVal (mapped_type val);
617 
618 
626  typename Impl_t::const_iterator get (const key_type& key) const;
627 
628 
640  std::pair<const_iterator, bool>
641  put (std::unique_ptr<key_type> key,
642  mapped_type val,
643  bool overwrite = true,
644  const Context_t& ctx = Updater_t::defaultContext());
645 
646 
658  std::pair<const_iterator, bool>
659  put (const Lock_t& lock,
660  std::unique_ptr<key_type> key,
661  mapped_type val,
662  bool overwrite = true,
663  const Context_t& ctx = Updater_t::defaultContext());
664 
665 
672  struct Hasher
673  {
675  size_t operator() (const val_t p) const;
677  size_t operator() (const std::string& s) const;
679  std::hash<std::string> m_hash;
680  };
681 
682 
686  struct Matcher
687  {
689  bool operator() (const val_t a, const val_t b) const;
690  };
691 
692 
694  Impl_t m_impl;
695 };
696 
697 
698 } // namespace CxxUtils
699 
700 
702 
703 
704 #endif // not CXXUTILS_CONCURRENTSTRMAP_H
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
CxxUtils::detail::ConcurrentHashmapVal_t
uintptr_t ConcurrentHashmapVal_t
Type used for keys and values — an unsigned big enough to hold a pointer.
Definition: ConcurrentHashmapImpl.h:40
columnar::operator=
AccessorTemplate & operator=(AccessorTemplate &&that)
Definition: VectorColumn.h:88
IsUpdater.h
Concept check for Updater class used by concurrent classes.
skel.it
it
Definition: skel.GENtoEVGEN.py:407
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
CxxUtils::detail::ConcurrentHashmapImpl
Hash table allowing concurrent, lockless reads.
Definition: ConcurrentHashmapImpl.h:200
ConcurrentStrMap.icc
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
CxxUtils::fpcompare::equal
bool equal(double a, double b)
Compare two FP numbers, working around x87 precision issues.
Definition: fpcompare.h:114
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
calibdata.valid
list valid
Definition: calibdata.py:45
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
CxxUtils
Definition: aligned_vector.h:29
contains
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition: hcg.cxx:111
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
VALUE
#define VALUE(TESTED)
Definition: expect.h:59
hist_file_dump.f
f
Definition: hist_file_dump.py:141
UIntConv.h
Helpers for converting between uintptr_t and a pointer or integer.
CxxUtils::requires
requires(detail::IsConcurrentHashmapPayload< KEY > &&detail::IsConcurrentHashmapPayload< VALUE > &&detail::IsUpdater< UPDATER > &&detail::IsHash< HASHER, KEY > &&detail::IsBinaryPredicate< MATCHER, KEY >) class ConcurrentMap
Hash map from integers/pointers allowing concurrent, lockless reads.
Definition: ConcurrentMap.h:94
WriteCalibToCool.swap
swap
Definition: WriteCalibToCool.py:94
CxxUtils::end
auto end(range_with_at< T > &s)
Definition: range_with_at.h:68
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
columnar::operator()
decltype(auto) operator()(ObjectId< OT, CM > id) const noexcept
Definition: ColumnAccessor.h:175
a
TList * a
Definition: liststreamerinfos.cxx:10
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
DeMoScan.first
bool first
Definition: DeMoScan.py:536
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
CxxUtils::begin
auto begin(range_with_at< T > &s)
Definition: range_with_at.h:64
ConcurrentHashmapImpl.h
Hash table allowing concurrent, lockless reads.