Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ConcurrentPtrSet.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-2023 CERN for the benefit of the ATLAS collaboration.
4  */
14 #include "CxxUtils/IsUpdater.h"
15 #include "boost/iterator/iterator_facade.hpp"
16 #include "boost/range/iterator_range.hpp"
17 #include <type_traits>
18 
19 
20 #ifndef CXXUTILS_CONCURRENTPTRSET_H
21 #define CXXUTILS_CONCURRENTPTRSET_H
22 
23 
24 namespace CxxUtils {
25 
26 
73 template <class VALUE, template <class> class UPDATER>
74 requires (detail::IsUpdater<UPDATER>)
75 class ConcurrentPtrSet
76 {
77 private:
79  struct Hasher;
80  struct Matcher;
84 
85 
86 public:
88  using key_type = VALUE*;
89  using const_key_type = const VALUE*;
90  using size_type = size_t;
92  using Updater_t = typename Impl_t::Updater_t;
94  using Context_t = typename Updater_t::Context_t;
96  using Lock_t = typename Impl_t::Lock_t;
97 
98 
107  ConcurrentPtrSet (Updater_t&& updater,
108  size_type capacity = 64,
109  const Context_t& ctx = Updater_t::defaultContext());
110 
111 
122  ConcurrentPtrSet (const ConcurrentPtrSet& other,
123  Updater_t&& updater,
124  size_t capacity = 64,
125  const Context_t& ctx = Updater_t::defaultContext());
126 
127 
138  template <class InputIterator>
139  ConcurrentPtrSet (InputIterator f,
140  InputIterator l,
141  Updater_t&& updater,
142  size_type capacity = 64,
143  const Context_t& ctx = Updater_t::defaultContext());
144 
145 
147  ConcurrentPtrSet (const ConcurrentPtrSet& other) = delete;
148  ConcurrentPtrSet (ConcurrentPtrSet&& other) = delete;
149  ConcurrentPtrSet& operator= (const ConcurrentPtrSet& other) = delete;
150  ConcurrentPtrSet& operator= (ConcurrentPtrSet&& other) = delete;
151 
152 
156  ~ConcurrentPtrSet();
157 
158 
162  size_type size() const;
163 
164 
168  bool empty() const;
169 
170 
174  size_t capacity() const;
175 
176 
180  using const_iterator_value = const key_type;
181 
182 
192  class const_iterator
193  : public boost::iterator_facade<const_iterator,
194  const const_iterator_value,
195  std::bidirectional_iterator_tag,
196  const const_iterator_value>
197  {
198  public:
203  const_iterator (typename Impl_t::const_iterator it);
204 
205 
211  bool valid() const;
212 
213 
214  private:
216  friend class boost::iterator_core_access;
217 
218 
222  void increment();
223 
224 
228  void decrement();
229 
230 
234  bool equal (const const_iterator& other) const;
235 
236 
240  key_type dereference() const;
241 
242 
244  typename Impl_t::const_iterator m_impl;
245  };
246 
247 
249  typedef boost::iterator_range<const_iterator> const_iterator_range;
250 
251 
255  const_iterator_range range() const;
256 
257 
261  const_iterator begin() const;
262 
263 
267  const_iterator end() const;
268 
269 
273  const_iterator cbegin() const;
274 
275 
279  const_iterator cend() const;
280 
281 
286  bool contains (const const_key_type key) const;
287 
288 
295  size_type count (const const_key_type key) const;
296 
297 
304  const_iterator find (const const_key_type key) const;
305 
306 
314  std::pair<const_iterator, const_iterator>
315  equal_range (const const_key_type key) const;
316 
317 
326  Lock_t lock();
327 
328 
339  std::pair<const_iterator, bool>
340  emplace (const key_type key,
341  const Context_t& ctx = Updater_t::defaultContext());
342 
343 
355  std::pair<const_iterator, bool>
356  emplace (const Lock_t& lock,
357  const key_type key,
358  const Context_t& ctx = Updater_t::defaultContext());
359 
360 
372  std::pair<const_iterator, bool> insert (const key_type p);
373 
374 
380  template <class InputIterator>
381  void insert (InputIterator first, InputIterator last);
382 
383 
392  void reserve (size_type capacity,
393  const Context_t& ctx = Updater_t::defaultContext());
394 
395 
403  void rehash (size_type capacity);
404 
405 
411  void clear (size_t capacity,
412  const Context_t& ctx = Updater_t::defaultContext());
413 
414 
419  void clear (const Context_t& ctx = Updater_t::defaultContext());
420 
421 
427  void quiescent (const Context_t& ctx);
428 
429 
440  void swap (ConcurrentPtrSet& other);
441 
442 
446  Updater_t& updater();
447 
448 
449 private:
454  static key_type keyAsPtr (val_t val);
455 
456 
461  static val_t keyAsVal (const const_key_type p);
462 
463 
471  typename Impl_t::const_iterator get (const const_key_type key) const;
472 
473 
483  std::pair<const_iterator, bool>
484  put (const key_type key,
485  const Context_t& ctx = Updater_t::defaultContext());
486 
487 
498  std::pair<const_iterator, bool>
499  put (const Lock_t& lock,
500  const key_type key,
501  const Context_t& ctx = Updater_t::defaultContext());
502 
503 
510  struct Hasher
511  {
513  size_t operator() (const val_t p) const;
515  size_t operator() (const const_key_type p) const;
517  std::hash<const_key_type> m_hash;
518  };
519 
520 
524  struct Matcher
525  {
527  bool operator() (const val_t a, const val_t b) const;
528  };
529 
530 
532  Impl_t m_impl;
533 };
534 
535 
536 } // namespace CxxUtils
537 
538 
540 
541 
542 #endif // not CXXUTILS_CONCURRENTPTRSET_H
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
IsUpdater.h
Concept check for Updater class used by concurrent classes.
ConcurrentPtrSet.icc
skel.it
it
Definition: skel.GENtoEVGEN.py:407
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
columnar::operator=
AccessorTemplate & operator=(AccessorTemplate &&that)
Definition: VectorColumn.h:88
CxxUtils::detail::ConcurrentHashmapImpl
Hash table allowing concurrent, lockless reads.
Definition: ConcurrentHashmapImpl.h:200
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
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
VKalVrtAthena::varHolder_detail::clear
void clear(T &var)
Definition: NtupleVars.h:48
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.