ATLAS Offline Software
ConcurrentStrToValMap.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 #ifndef CXXUTILS_CONCURRENTSTRTOVALMAP_H
15 #define CXXUTILS_CONCURRENTSTRTOVALMAP_H
16 
17 
19 #include "CxxUtils/UIntConv.h"
20 #include "CxxUtils/concepts.h"
21 #include "CxxUtils/IsUpdater.h"
22 #include "boost/iterator/iterator_facade.hpp"
23 #include "boost/range/iterator_range.hpp"
24 #include <memory>
25 #include <type_traits>
26 #include <stdexcept>
27 
28 
29 namespace CxxUtils {
30 
31 
84 template <class VALUE, template <class> class UPDATER>
85 ATH_REQUIRES (detail::IsUpdater<UPDATER>)
87 {
88 private:
90  struct Hasher;
91  struct Matcher;
95 
96 
97 public:
99  using key_type = std::string;
101  using size_type = size_t;
103  using Updater_t = typename Impl_t::Updater_t;
105  using Context_t = typename Updater_t::Context_t;
106 
107 
117  size_type capacity = 64,
118  const Context_t& ctx = Updater_t::defaultContext());
119 
120 
132  Updater_t&& updater,
133  size_t capacity = 64,
134  const Context_t& ctx = Updater_t::defaultContext());
135 
136 
149  template <class InputIterator>
150  ConcurrentStrToValMap (InputIterator f,
151  InputIterator l,
152  Updater_t&& updater,
153  size_type capacity = 64,
154  const Context_t& ctx = Updater_t::defaultContext());
155 
156 
160  ConcurrentStrToValMap& operator= (const ConcurrentStrToValMap& other) = delete;
162 
163 
168 
169 
173  size_type size() const;
174 
175 
179  bool empty() const;
180 
181 
185  size_t capacity() const;
186 
187 
200  using const_iterator_value = std::pair<const key_type&, const mapped_type&>;
201  using iterator_value = std::pair<const key_type, mapped_type&>;
202 
203  class const_iterator;
204  class iterator;
205 
206 
217  : public boost::iterator_facade<const_iterator,
218  const const_iterator_value,
219  std::bidirectional_iterator_tag,
220  const const_iterator_value>
221  {
222  public:
227  const_iterator (typename Impl_t::const_iterator it);
228 
229 
235 
236 
242  bool valid() const;
243 
244 
245  private:
247  friend class boost::iterator_core_access;
248  friend class iterator;
249 
250 
254  void increment();
255 
256 
260  void decrement();
261 
262 
266  bool equal (const const_iterator& other) const;
267 
268 
272  bool equal (const iterator& other) const;
273 
274 
279 
280 
282  typename Impl_t::const_iterator m_impl;
283  };
284 
285 
299  class iterator
300  : public boost::iterator_facade<iterator,
301  const iterator_value,
302  std::bidirectional_iterator_tag,
303  const iterator_value>
304  {
305  public:
310  iterator (typename Impl_t::const_iterator it);
311 
312 
318  bool valid() const;
319 
320 
321  private:
323  friend class boost::iterator_core_access;
324  friend class const_iterator;
325 
326 
330  void increment();
331 
332 
336  void decrement();
337 
338 
342  bool equal (const iterator& other) const;
343 
344 
348  bool equal (const const_iterator& other) const;
349 
350 
355 
356 
358  typename Impl_t::const_iterator m_impl;
359  };
360 
361 
363  typedef boost::iterator_range<const_iterator> const_iterator_range;
364  typedef boost::iterator_range<iterator> iterator_range;
365 
366 
371 
372 
380 
381 
385  const_iterator begin() const;
386 
387 
391  const_iterator end() const;
392 
393 
401 
402 
410 
411 
415  const_iterator cbegin() const;
416 
417 
421  const_iterator cend() const;
422 
423 
428  bool contains (const key_type& key) const;
429 
430 
437  size_type count (const key_type& key) const;
438 
439 
446  const_iterator find (const key_type& key) const;
447 
448 
459 
460 
468  const mapped_type& at (const key_type& key) const;
469 
470 
483 
484 
492  std::pair<const_iterator, const_iterator>
493  equal_range (const key_type& key) const;
494 
495 
506  std::pair<iterator, iterator>
508 
509 
521  std::pair<const_iterator, bool>
522  emplace (const key_type& key, const mapped_type& val,
523  const Context_t& ctx = Updater_t::defaultContext());
524 
525 
537  std::pair<const_iterator, bool>
539  const Context_t& ctx = Updater_t::defaultContext());
540 
541 
553  std::pair<const_iterator, bool>
555  const Context_t& ctx = Updater_t::defaultContext());
556 
557 
569  std::pair<const_iterator, bool>
571  const Context_t& ctx = Updater_t::defaultContext());
572 
573 
585  std::pair<const_iterator, bool>
586  emplace (const key_type& key, std::unique_ptr<mapped_type> val,
587  const Context_t& ctx = Updater_t::defaultContext());
588 
589 
601  std::pair<const_iterator, bool>
602  emplace (key_type&& key, std::unique_ptr<mapped_type> val,
603  const Context_t& ctx = Updater_t::defaultContext());
604 
605 
618  template <class PAIR>
619  std::pair<const_iterator, bool> insert (const PAIR& p,
620  const Context_t& ctx = Updater_t::defaultContext());
621 
622 
635  template <class PAIR>
636  std::pair<const_iterator, bool> insert (PAIR&& p,
637  const Context_t& ctx = Updater_t::defaultContext());
638 
639 
649  template <class InputIterator>
650  void insert (InputIterator first, InputIterator last,
651  const Context_t& ctx = Updater_t::defaultContext());
652 
653 
662  void reserve (size_type capacity,
663  const Context_t& ctx = Updater_t::defaultContext());
664 
665 
673  void rehash (size_type capacity);
674 
675 
681  void quiescent (const Context_t& ctx);
682 
683 
695 
696 
701 
702 
703 private:
708  static const std::string* keyAsString (val_t val);
709 
710 
715  static val_t keyAsVal (const std::string* s);
716 
717 
724 
725 
731 
732 
740  typename Impl_t::const_iterator get (const key_type& key) const;
741 
742 
753  std::pair<const_iterator, bool>
754  put (std::unique_ptr<key_type> key,
755  std::unique_ptr<mapped_type> val,
756  const Context_t& ctx = Updater_t::defaultContext());
757 
758 
765  struct Hasher
766  {
768  size_t operator() (const val_t p) const;
770  size_t operator() (const std::string& s) const;
772  std::hash<std::string> m_hash;
773  };
774 
775 
779  struct Matcher
780  {
782  bool operator() (const val_t a, const val_t b) const;
783  };
784 
785 
788 };
789 
790 
791 } // namespace CxxUtils
792 
793 
795 
796 
797 #endif // not CXXUTILS_CONCURRENTSTRTOVALMAP_H
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
CxxUtils::ConcurrentStrToValMap::equal_range
std::pair< const_iterator, const_iterator > equal_range(const key_type &key) const
Return a range of iterators with entries matching key.
CxxUtils::ConcurrentStrToValMap::iterator::increment
void increment()
iterator_facade requirement: Increment the iterator.
CxxUtils::ConcurrentStrToValMap::iterator
Iterator class.
Definition: ConcurrentStrToValMap.h:304
CxxUtils::ConcurrentStrToValMap::at
const mapped_type & at(const key_type &key) const
Look up an element in the map.
python.CaloRecoConfig.f
f
Definition: CaloRecoConfig.py:127
CxxUtils::ConcurrentStrToValMap::ConcurrentStrToValMap
ConcurrentStrToValMap(ConcurrentStrToValMap &&other)=delete
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
CxxUtils::ConcurrentStrToValMap::const_iterator::equal
bool equal(const iterator &other) const
iterator_facade requirement: Equality test.
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
CxxUtils::ConcurrentStrToValMap::cend
const_iterator cend() const
Iterator at the end of the map.
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:41
CxxUtils::ConcurrentStrToValMap::iterator::iterator
iterator(typename Impl_t::const_iterator it)
Constructor.
CxxUtils::ConcurrentStrToValMap::m_impl
Impl_t m_impl
The underlying hash table.
Definition: ConcurrentStrToValMap.h:787
CxxUtils::ConcurrentStrToValMap::swap
void swap(ConcurrentStrToValMap &other)
Swap this container with another.
CxxUtils::ConcurrentStrToValMap::find
const_iterator find(const key_type &key) const
Look up an element in the map.
IsUpdater.h
Concept check for Updater class used by concurrent classes.
CxxUtils::ConcurrentStrToValMap::const_iterator::m_impl
Impl_t::const_iterator m_impl
The iterator on the underlying table.
Definition: ConcurrentStrToValMap.h:282
CxxUtils::ConcurrentStrToValMap::const_iterator::const_iterator
const_iterator(const iterator &other)
Conversion from non-const iterator (for interoperability).
CxxUtils::ConcurrentStrToValMap::ConcurrentStrToValMap
ConcurrentStrToValMap(Updater_t &&updater, size_type capacity=64, const Context_t &ctx=Updater_t::defaultContext())
Constructor.
CxxUtils::ConcurrentStrToValMap::iterator::dereference
const iterator_value dereference() const
iterator_facade requirement: Dereference the iterator.
CxxUtils::ConcurrentStrToValMap::emplace
std::pair< const_iterator, bool > emplace(const key_type &key, mapped_type &&val, const Context_t &ctx=Updater_t::defaultContext())
Add an element to the map.
skel.it
it
Definition: skel.GENtoEVGEN.py:423
CxxUtils::ConcurrentStrToValMap< HashMap, CxxUtils::SimpleUpdater >::key_type
std::string key_type
Standard STL types.
Definition: ConcurrentStrToValMap.h:99
CxxUtils::ConcurrentStrToValMap::emplace
std::pair< const_iterator, bool > emplace(key_type &&key, mapped_type &&val, const Context_t &ctx=Updater_t::defaultContext())
Add an element to the map.
CxxUtils::ConcurrentStrToValMap< HashMap, CxxUtils::SimpleUpdater >::Updater_t
typename Impl_t::Updater_t Updater_t
Updater object.
Definition: ConcurrentStrToValMap.h:103
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
CxxUtils::ConcurrentStrToValMap::const_iterator::decrement
void decrement()
iterator_facade requirement: Decrement the iterator.
CxxUtils::ConcurrentStrToValMap::contains
bool contains(const key_type &key) const
Test if a key is in the container.
ConcurrentStrToValMap.icc
CxxUtils::ConcurrentStrToValMap::Hasher
Hash functional for keys.
Definition: ConcurrentStrToValMap.h:766
CxxUtils::ConcurrentStrToValMap::rehash
void rehash(size_type capacity)
Increase the table capacity.
CxxUtils::ConcurrentStrToValMap::keyAsString
static const std::string * keyAsString(val_t val)
Convert an underlying key value to a string pointer.
CxxUtils::detail::ConcurrentHashmapImpl< UPDATER, Hasher, Matcher >
CxxUtils::ConcurrentStrToValMap::end
iterator end()
Iterator at the end of the map.
CxxUtils::ConcurrentStrToValMap::at
mapped_type & at(const key_type &key)
Look up an element in the map.
CxxUtils::ConcurrentStrToValMap::get
Impl_t::const_iterator get(const key_type &key) const
Do a lookup in the table.
CxxUtils::ConcurrentStrToValMap::begin
const_iterator begin() const
Iterator at the start of the map.
CxxUtils::ConcurrentStrToValMap::const_iterator::increment
void increment()
iterator_facade requirement: Increment the iterator.
CxxUtils::ConcurrentStrToValMap::emplace
std::pair< const_iterator, bool > emplace(key_type &&key, const mapped_type &val, const Context_t &ctx=Updater_t::defaultContext())
Add an element to the map.
CxxUtils::ConcurrentStrToValMap::const_iterator::valid
bool valid() const
Test if this iterator is valid.
CxxUtils::ConcurrentStrToValMap< HashMap, CxxUtils::SimpleUpdater >::val_t
CxxUtils::detail::ConcurrentHashmapVal_t val_t
Representation type in the underlying map.
Definition: ConcurrentStrToValMap.h:94
CxxUtils::ConcurrentStrToValMap::const_iterator::const_iterator
const_iterator(typename Impl_t::const_iterator it)
Constructor.
CxxUtils::ConcurrentStrToValMap< HashMap, CxxUtils::SimpleUpdater >::const_iterator_value
std::pair< const key_type &, const mapped_type & > const_iterator_value
Value structures for iterators.
Definition: ConcurrentStrToValMap.h:200
CxxUtils::ConcurrentStrToValMap::empty
bool empty() const
Test if the map is currently empty.
CxxUtils::ConcurrentStrToValMap::end
const_iterator end() const
Iterator at the end of the map.
CxxUtils::ConcurrentStrToValMap::mappedAsMapped
static mapped_type * mappedAsMapped(val_t val)
Convert an underlying mapped value a pointer to this type's mapped value.
CxxUtils::ConcurrentStrToValMap< HashMap, CxxUtils::SimpleUpdater >::size_type
size_t size_type
Definition: ConcurrentStrToValMap.h:101
CxxUtils::ConcurrentStrToValMap::updater
Updater_t & updater()
Access the Updater instance.
CxxUtils::ConcurrentStrToValMap::iterator::decrement
void decrement()
iterator_facade requirement: Decrement the iterator.
CxxUtils::ConcurrentStrToValMap::cbegin
const_iterator cbegin() const
Iterator at the start of the map.
CxxUtils
Definition: aligned_vector.h:29
CxxUtils::ConcurrentStrToValMap::Matcher
Matching functional for keys.
Definition: ConcurrentStrToValMap.h:780
CxxUtils::ConcurrentStrToValMap::mappedAsVal
static val_t mappedAsVal(mapped_type *val)
Convert this type's mapped value to an underlying mapped value.
VALUE
#define VALUE(TESTED)
Definition: expect.h:59
CxxUtils::ConcurrentStrToValMap::~ConcurrentStrToValMap
~ConcurrentStrToValMap()
Destructor.
CxxUtils::ConcurrentStrToValMap::ConcurrentStrToValMap
ConcurrentStrToValMap(InputIterator f, InputIterator l, Updater_t &&updater, size_type capacity=64, const Context_t &ctx=Updater_t::defaultContext())
Constructor from a range.
UIntConv.h
Helpers for converting between uintptr_t and a pointer or integer.
CxxUtils::ConcurrentStrToValMap::const_iterator_range
boost::iterator_range< const_iterator > const_iterator_range
A range defined by two iterators.
Definition: ConcurrentStrToValMap.h:363
CxxUtils::ConcurrentStrToValMap::iterator::equal
bool equal(const iterator &other) const
iterator_facade requirement: Equality test.
CxxUtils::ConcurrentStrToValMap< HashMap, CxxUtils::SimpleUpdater >::iterator_value
std::pair< const key_type, mapped_type & > iterator_value
Definition: ConcurrentStrToValMap.h:201
CxxUtils::ConcurrentStrToValMap
Hash map from strings to arbitrary objects allowing concurrent, lockless reads.
Definition: ConcurrentStrToValMap.h:87
CxxUtils::ConcurrentStrToValMap::count
size_type count(const key_type &key) const
Return the number of times a given key is in the container.
CxxUtils::ConcurrentStrToValMap::range
iterator_range range()
Return an iterator range covering the entire map.
CxxUtils::ConcurrentStrToValMap::iterator::equal
bool equal(const const_iterator &other) const
iterator_facade requirement: Equality test.
CxxUtils::ConcurrentStrToValMap::ConcurrentStrToValMap
ConcurrentStrToValMap(const ConcurrentStrToValMap &other, Updater_t &&updater, size_t capacity=64, const Context_t &ctx=Updater_t::defaultContext())
Constructor from another map.
CxxUtils::ConcurrentStrToValMap::capacity
size_t capacity() const
Return the current size (capacity) of the hash table.
CxxUtils::ConcurrentStrToValMap::equal_range
std::pair< iterator, iterator > equal_range(const key_type &key)
Return a range of iterators with entries matching key.
CxxUtils::ConcurrentStrToValMap::iterator::m_impl
Impl_t::const_iterator m_impl
The iterator on the underlying table.
Definition: ConcurrentStrToValMap.h:358
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
CxxUtils::ConcurrentStrToValMap::emplace
std::pair< const_iterator, bool > emplace(const key_type &key, std::unique_ptr< mapped_type > val, const Context_t &ctx=Updater_t::defaultContext())
Add an element to the map.
CxxUtils::ConcurrentStrToValMap< HashMap, CxxUtils::SimpleUpdater >::mapped_type
HashMap mapped_type
Definition: ConcurrentStrToValMap.h:100
CxxUtils::ConcurrentStrToValMap::iterator::valid
bool valid() const
Test if this iterator is valid.
CxxUtils::ConcurrentStrToValMap::emplace
std::pair< const_iterator, bool > emplace(const key_type &key, const mapped_type &val, const Context_t &ctx=Updater_t::defaultContext())
Add an element to the map.
CxxUtils::ConcurrentStrToValMap::put
std::pair< const_iterator, bool > put(std::unique_ptr< key_type > key, std::unique_ptr< mapped_type > val, const Context_t &ctx=Updater_t::defaultContext())
Insert an entry in the table.
CxxUtils::ConcurrentStrToValMap::find
iterator find(const key_type &key)
Look up an element in the map.
concepts.h
Compatibility helpers for using some pieces of C++20 concepts with older compilers.
CxxUtils::ConcurrentStrToValMap::begin
iterator begin()
Iterator at the start of the map.
a
TList * a
Definition: liststreamerinfos.cxx:10
CxxUtils::ConcurrentStrToValMap::quiescent
void quiescent(const Context_t &ctx)
Called when this thread is no longer referencing anything from this container.
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
CxxUtils::ConcurrentStrToValMap::insert
void insert(InputIterator first, InputIterator last, const Context_t &ctx=Updater_t::defaultContext())
Insert a range of elements to the map.
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
CxxUtils::ConcurrentStrToValMap::reserve
void reserve(size_type capacity, const Context_t &ctx=Updater_t::defaultContext())
Increase the table capacity.
DeMoScan.first
bool first
Definition: DeMoScan.py:534
CxxUtils::ConcurrentStrToValMap::const_iterator::equal
bool equal(const const_iterator &other) const
iterator_facade requirement: Equality test.
CxxUtils::ATH_REQUIRES
ATH_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
CxxUtils::ConcurrentStrToValMap::const_iterator::dereference
const const_iterator_value dereference() const
iterator_facade requirement: Dereference the iterator.
CxxUtils::ConcurrentStrToValMap::keyAsVal
static val_t keyAsVal(const std::string *s)
Convert a string pointer to an underlying key value.
CxxUtils::ConcurrentStrToValMap::emplace
std::pair< const_iterator, bool > emplace(key_type &&key, std::unique_ptr< mapped_type > val, const Context_t &ctx=Updater_t::defaultContext())
Add an element to the map.
CxxUtils::ConcurrentStrToValMap::Hasher::m_hash
std::hash< std::string > m_hash
Hash functional.
Definition: ConcurrentStrToValMap.h:772
CxxUtils::ConcurrentStrToValMap::const_iterator
Const iterator class.
Definition: ConcurrentStrToValMap.h:221
CxxUtils::ConcurrentStrToValMap< HashMap, CxxUtils::SimpleUpdater >::Impl_t
typename detail::ConcurrentHashmapImpl< CxxUtils::SimpleUpdater, Hasher, Matcher > Impl_t
Definition: ConcurrentStrToValMap.h:92
CxxUtils::ConcurrentStrToValMap::size
size_type size() const
Return the number of items currently in the map.
CxxUtils::ConcurrentStrToValMap< HashMap, CxxUtils::SimpleUpdater >::Context_t
typename Updater_t::Context_t Context_t
Context type.
Definition: ConcurrentStrToValMap.h:105
CxxUtils::ConcurrentStrToValMap::iterator_range
boost::iterator_range< iterator > iterator_range
Definition: ConcurrentStrToValMap.h:364
CxxUtils::ConcurrentStrToValMap::range
const_iterator_range range() const
Return an iterator range covering the entire map.
CxxUtils::ConcurrentStrToValMap::insert
std::pair< const_iterator, bool > insert(PAIR &&p, const Context_t &ctx=Updater_t::defaultContext())
Add an element to the map.
CxxUtils::ConcurrentStrToValMap::ConcurrentStrToValMap
ConcurrentStrToValMap(const ConcurrentStrToValMap &other)=delete
Copy / move / assign not supported.
CxxUtils::ConcurrentStrToValMap::insert
std::pair< const_iterator, bool > insert(const PAIR &p, const Context_t &ctx=Updater_t::defaultContext())
Add an element to the map.
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
ConcurrentHashmapImpl.h
Hash table allowing concurrent, lockless reads.