Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

RegisteredArray.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/Math.h>
35 #include <ogdf/basic/basic.h>
37 #include <ogdf/basic/memory.h>
38 
39 #include <algorithm>
40 #include <cstddef>
41 #include <iterator>
42 #include <list>
43 #include <memory> // IWYU pragma: keep
44 #include <type_traits>
45 #include <utility>
46 #include <vector>
47 
48 #ifndef OGDF_MEMORY_POOL_NTS
49 
50 # include <mutex>
51 
52 #endif
53 
54 namespace ogdf {
55 namespace internal {
56 template<typename Registry>
58 }
59 
61 static constexpr int MIN_TABLE_SIZE = (1 << 4);
62 
64 
67 inline int calculateTableSize(int actualCount) {
68  return Math::nextPower2(MIN_TABLE_SIZE, actualCount);
69 }
70 
72 
103 template<typename Key, typename Registry, typename Iterator = void>
105 public:
107  using key_type = Key;
108  using registry_type = Registry;
109  using iterator_type = Iterator;
110  using registration_list_type =
111  std::list<registered_array_type*, OGDFAllocator<registered_array_type*>>;
112  using registration_iterator_type = typename registration_list_type::iterator;
113 
114 private:
116  bool m_autoShrink = false;
117  int m_size = 0;
118 
119 #ifndef OGDF_MEMORY_POOL_NTS
120  mutable std::mutex m_mutexRegArrays;
121 #endif
122 
123 protected:
124  RegistryBase() = default;
125 
126 public:
128  virtual ~RegistryBase() noexcept { unregisterArrays(); }
129 
130  RegistryBase(const RegistryBase& copy) = delete;
131 
132  RegistryBase(RegistryBase&& move) noexcept = delete;
133 
134  RegistryBase& operator=(const RegistryBase& other) = delete;
135 
136  RegistryBase& operator=(RegistryBase&& other) noexcept = delete;
137 
139 
145 #ifndef OGDF_MEMORY_POOL_NTS
146  std::lock_guard<std::mutex> guard(m_mutexRegArrays);
147 #endif
148  return m_registeredArrays.emplace(m_registeredArrays.end(), pArray);
149  }
150 
152 
155  void unregisterArray(registration_iterator_type it) const noexcept {
156 #ifndef OGDF_MEMORY_POOL_NTS
157  std::lock_guard<std::mutex> guard(m_mutexRegArrays);
158 #endif
159  m_registeredArrays.erase(it);
160  }
161 
164 #ifndef OGDF_MEMORY_POOL_NTS
165  std::lock_guard<std::mutex> guard(m_mutexRegArrays);
166 #endif
167  *it = pArray;
168  }
169 
171  void keyAdded(Key key) {
172  if (static_cast<Registry*>(this)->keyToIndex(key) >= m_size) {
173  resizeArrays();
174  }
175  }
176 
178  void keyRemoved(Key key) {
179  if (m_autoShrink) {
180  resizeArrays();
181  }
182  }
183 
185  void keysCleared() { resizeArrays(0); }
186 
189  void resizeArrays() { resizeArrays(static_cast<Registry*>(this)->calculateArraySize(0)); }
190 
192  void resizeArrays(int size) { resizeArrays(size, m_autoShrink); }
193 
195  void resizeArrays(int size, bool shrink) {
196  if (size == m_size) {
197  return;
198  }
199  m_size = size = max(size, 0);
201  ab->resize(size, shrink);
202  }
203  }
204 
206  void reserveSpace(int new_keys) {
207  resizeArrays(static_cast<Registry*>(this)->calculateArraySize(new_keys));
208  }
209 
211  void swapArrayEntries(int index1, int index2) {
213  ab->swapEntries(index1, index2);
214  }
215  }
216 
218  void copyArrayEntries(int toIndex, int fromIndex) {
220  ab->copyEntry(toIndex, fromIndex);
221  }
222  }
223 
225  void unregisterArrays() noexcept {
226  while (!m_registeredArrays.empty()) {
227 #ifdef OGDF_DEBUG
228  auto size = m_registeredArrays.size();
229 #endif
230  m_registeredArrays.front()->unregister();
231  OGDF_ASSERT(m_registeredArrays.size() < size);
232  }
233  }
234 
237 
239  bool isAutoShrink() const { return m_autoShrink; }
240 
242  void setAutoShrink(bool mAutoShrink) { m_autoShrink = mAutoShrink; }
243 
245  int getArraySize() const { return m_size; }
246 };
247 
248 namespace internal {
250 
256 template<class Registry>
257 class RegisteredArrayBase {
258  using registry_type = Registry;
259  using registration_iterator_type = typename Registry::registration_iterator_type;
260 
262  const Registry* m_pRegistry = nullptr;
263 
264 public:
266  RegisteredArrayBase() = default;
267 
270 
273  moveRegister(move_from);
274  }
275 
278  reregister(copy.m_pRegistry);
279  return *this;
280  }
281 
284  moveRegister(move_from);
285  return *this;
286  }
287 
289  virtual ~RegisteredArrayBase() noexcept {
290  if (m_pRegistry) {
291  m_pRegistry->unregisterArray(m_registration);
292  }
293  }
294 
296  virtual void resize(int size, bool shrink) = 0;
297 
299  virtual void swapEntries(int index1, int index2) = 0;
300 
302  virtual void copyEntry(int newIndex, int oldIndex) = 0;
303 
305  void unregister() noexcept {
306  resize(0, true);
307  reregister(nullptr);
308  }
309 
310 protected:
312  void reregister(const Registry* registry) {
313  if (m_pRegistry) {
314  m_pRegistry->unregisterArray(m_registration);
315  }
316  m_pRegistry = registry;
317  if (m_pRegistry != nullptr) {
318  m_registration = m_pRegistry->registerArray(this);
319  } else {
321  }
322  }
323 
326  if (m_pRegistry) {
327  m_pRegistry->unregisterArray(m_registration);
328  }
329  m_pRegistry = move_from.m_pRegistry;
330  m_registration = move_from.m_registration;
331  move_from.m_pRegistry = nullptr;
332  move_from.m_registration = registration_iterator_type();
333  if (m_pRegistry != nullptr) {
334  m_pRegistry->moveRegisterArray(m_registration, this);
335  }
336  }
337 
338 public:
340  const Registry* registeredAt() const { return m_pRegistry; }
341 };
342 }
343 
345 
352 template<class ArrayType, class KeyIterator, bool isConst = false>
354 public:
355  using registry_type = typename ArrayType::registry_type;
356  using key_type = typename ArrayType::key_type;
357  using value_type = typename std::conditional<isConst, const typename ArrayType::value_type,
358  typename ArrayType::value_type>::type;
360 
361 private:
362  KeyIterator m_it;
364 
365 public:
368 
370 
375  : m_it(mIt), m_array(mArray) { }
376 
378  key_type key() const { return *m_it; }
379 
381  value_type& value() const { return (*m_array)[*m_it]; }
382 
384  value_type& operator*() const { return (*m_array)[*m_it]; }
385 
388  return m_it == iter.m_it && m_array == iter.m_array;
389  }
390 
393  return !operator==(iter);
394  }
395 
398  ++m_it;
399  return *this;
400  }
401 
405  ++m_it;
406  return iter;
407  }
408 
411  --m_it;
412  return *this;
413  }
414 
418  --m_it;
419  return iter;
420  }
421 };
422 
423 namespace internal {
425 
436 template<class Registry, class Value>
438 protected:
439  using key_iterator = typename Registry::iterator_type;
442 
443 public:
444  using registry_type = Registry;
445  using key_type = typename Registry::key_type;
446  using vector_type = std::vector<Value, OGDFAllocator<Value>>;
447  using value_type = typename vector_type::value_type;
448  using value_ref_type = typename vector_type::reference;
449  using value_const_ref_type = typename vector_type::const_reference;
450 
453 
454 protected:
456 
457 public:
460 
462  explicit RegisteredArrayWithoutDefaultOrIndexAccess(const Registry* registry) {
463  // during base class initialization, no part of the derived class exists, so this will always call our base init
464  // so base classes should call their own init themselves
465  registered_array::init(registry);
466  }
467 
469  void init(const Registry* registry = nullptr) {
470  if (registry == nullptr) {
471  resize(0, true);
472  } else {
473  OGDF_ASSERT(registry->maxKeyIndex() < registry->getArraySize());
474  resize(0, false);
475  resize(registry->getArraySize(), true);
476  }
478  }
479 
481  void fill(value_const_ref_type x) { m_data.assign(m_data.size(), x); }
482 
485  OGDF_ASSERT(getRegistry().isKeyAssociated(key));
486 #ifdef OGDF_DEBUG
487  return m_data.at(registeredAt()->keyToIndex(key));
488 #else
489  return m_data[registeredAt()->keyToIndex(key)];
490 #endif
491  }
492 
495  OGDF_ASSERT(getRegistry().isKeyAssociated(key));
496 #ifdef OGDF_DEBUG
497  return m_data.at(registeredAt()->keyToIndex(key));
498 #else
499  return m_data[registeredAt()->keyToIndex(key)];
500 #endif
501  }
502 
505  OGDF_ASSERT(getRegistry().isKeyAssociated(key));
506 #ifdef OGDF_DEBUG
507  return m_data.at(registeredAt()->keyToIndex(key));
508 #else
509  return m_data[registeredAt()->keyToIndex(key)];
510 #endif
511  }
512 
515  OGDF_ASSERT(getRegistry().isKeyAssociated(key));
516 #ifdef OGDF_DEBUG
517  return m_data.at(registeredAt()->keyToIndex(key));
518 #else
519  return m_data[registeredAt()->keyToIndex(key)];
520 #endif
521  }
522 
525  using std::begin;
526  return iterator(begin(getRegistry()), this);
527  }
528 
531  using std::begin;
532  return const_iterator(begin(getRegistry()), this);
533  }
534 
537  using std::begin;
538  return const_iterator(begin(getRegistry()), this);
539  }
540 
543  using std::end;
544  return iterator(end(getRegistry()), this);
545  }
546 
548  const_iterator end() const {
549  using std::end;
550  return const_iterator(end(getRegistry()), this);
551  }
552 
555  using std::end;
556  return const_iterator(end(getRegistry()), this);
557  }
558 
560 
562  bool valid() const {
563  OGDF_ASSERT(registeredAt() == nullptr || registeredAt()->maxKeyIndex() < 0
564  || ((size_t)registeredAt()->maxKeyIndex()) < m_data.size());
565  return registeredAt();
566  }
567 
568 protected:
570  inline const Registry& getRegistry() const {
572  OGDF_ASSERT(valid());
573  return *registeredAt();
574  }
575 
576  void resize(int size, bool shrink) override {
577  m_data.resize(size);
578  if (shrink) {
579  m_data.shrink_to_fit();
580  }
581  }
582 
583  void swapEntries(int index1, int index2) override {
584  std::swap(m_data.at(index1), m_data.at(index2));
585  }
586 
588  void copyEntry(int toIndex, int fromIndex) override {
589  // silently ignored
590  }
591 };
592 
594 template<class Registry, class Value>
596  : public RegisteredArrayWithoutDefaultOrIndexAccess<Registry, Value> {
598 
599 public:
601 
602  explicit RegisteredArrayWithoutDefaultWithIndexAccess(const Registry* registry)
603  : RA(registry) { }
604 
605  using RA::operator[];
606 
608  typename RA::value_const_ref_type operator[](int idx) const {
609 #ifdef OGDF_DEBUG
610  return RA::m_data.at(idx);
611 #else
612  return RA::m_data[idx];
613 #endif
614  }
615 
617  typename RA::value_ref_type operator[](int idx) {
618 #ifdef OGDF_DEBUG
619  return RA::m_data.at(idx);
620 #else
621  return RA::m_data[idx];
622 #endif
623  }
624 };
625 
627 template<class Registry, class Value>
629  typename std::conditional_t<std::is_integral_v<typename Registry::key_type>,
630  RegisteredArrayWithoutDefaultOrIndexAccess<Registry, Value>,
632 
634 
646 template<class Registry, class Value>
649  Value m_default;
650 
651  static_assert(std::is_copy_constructible_v<Value>,
652  "This RegisteredArrayWithDefault<Value> instantiation (e.g. NodeArray<Graph>) is "
653  "invalid because Value is not copy-constructible! "
654  "Use, e.g., NodeArrayP<Graph> or NodeArray<unique_ptr<Graph>, false> instead.");
655 
656 public:
659 
661  explicit RegisteredArrayWithDefault(const Registry* registry) : RA(), m_default() {
662  // call init from here, as our virtual override of init is not available during initialization of the base class
663  RA::init(registry);
664  };
665 
667  explicit RegisteredArrayWithDefault(const Value& def) : RA(), m_default(def) {};
668 
670  explicit RegisteredArrayWithDefault(const Registry* registry, const Value& def)
671  : RA(), m_default(def) {
672  // call init from here, as our virtual override of init is not available during initialization of the base class
673  RA::init(registry);
674  };
675 
677  explicit RegisteredArrayWithDefault(Value&& def) : RA(), m_default(std::forward<Value>(def)) {};
678 
680  explicit RegisteredArrayWithDefault(const Registry* registry, Value&& def)
681  : RA(), m_default(std::forward<Value>(def)) {
682  // call init from here, as our virtual override of init is not available during initialization of the base class
683  RA::init(registry);
684  };
685 
687  void setDefault(Value&& def) { m_default = std::forward<Value>(def); }
688 
690  void setDefault(const Value& def) { m_default = def; }
691 
693  const Value& getDefault() const { return m_default; }
694 
696  Value& getDefault() { return m_default; }
697 
699  void fillWithDefault() { RA::m_data.assign(RA::getRegistry().getArraySize(), m_default); }
700 
701 protected:
703  void copyEntry(int toIndex, int fromIndex) override {
704  RA::m_data.at(toIndex) = RA::m_data.at(fromIndex);
705  }
706 
707  void resize(int size, bool shrink) override {
708  RA::m_data.resize(size, m_default);
709  if (shrink) {
710  RA::m_data.shrink_to_fit();
711  }
712  }
713 };
714 }
715 
717 
816 template<class Registry, class Value, bool WithDefault = true, class Base = Registry>
818  : public std::conditional<WithDefault, internal::RegisteredArrayWithDefault<Registry, Value>,
819  internal::RegisteredArrayWithoutDefault<Registry, Value>>::type {
820  using RA =
821  typename std::conditional<WithDefault, internal::RegisteredArrayWithDefault<Registry, Value>,
823 
824  static inline const Registry* cast(const Base* base) {
825  if (base != nullptr) {
826  // unpack the pointer to invoke the conversion operator
827  return &((const Registry&)*base);
828  } else {
829  return nullptr;
830  }
831  }
832 
833 public:
835  RegisteredArray() : RA() {};
836 
838  explicit RegisteredArray(const Base& base) : RA(cast(&base)) {};
839 
845  RegisteredArray(const Base& base, const Value& def) : RA(cast(&base), def) {};
846 
848  explicit RegisteredArray(const Base* base) : RA(cast(base)) {};
849 
855  RegisteredArray(const Base* base, const Value& def) : RA(cast(base), def) {};
856 
858  void init(const Base* base = nullptr) { RA::init(cast(base)); }
859 
861  void init(const Base& base) { RA::init(cast(&base)); }
862 
868  void init(const Base& base, const Value& new_default) {
869  RA::setDefault(new_default);
870  RA::init(cast(&base));
871  }
872 
873  void init(const Base* base, const Value& new_default) {
874  RA::setDefault(new_default);
875  RA::init(cast(base));
876  }
877 };
878 
880 template<class Registry, bool WithDefault, class Base>
881 class RegisteredArray<Registry, bool, WithDefault, Base>
882  : public RegisteredArray<Registry, unsigned char, WithDefault, Base> {
885 
886 public:
887  using RA::RA;
888 
889  using key_type = typename RA::key_type;
890  using value_type = bool;
891  using value_const_ref_type = const bool&;
892  using value_ref_type = bool&;
895 
897  return reinterpret_cast<value_const_ref_type>(RA::operator[](key));
898  }
899 
901  return reinterpret_cast<value_ref_type>(RA::operator[](key));
902  }
903 
905  return reinterpret_cast<value_const_ref_type>(RA::operator()(key));
906  }
907 
909  return reinterpret_cast<value_ref_type>(RA::operator()(key));
910  }
911 
913  return reinterpret_cast<value_const_ref_type>(RA::operator[](idx));
914  }
915 
917  return reinterpret_cast<value_ref_type>(RA::operator[](idx));
918  }
919 
920  value_ref_type getDefault() { return reinterpret_cast<value_ref_type>(RA::getDefault()); }
921 
923  return reinterpret_cast<value_const_ref_type>(RA::getDefault());
924  }
925 
927  using std::begin;
928  return iterator(begin(RA::getRegistry()), this);
929  }
930 
932  using std::begin;
933  return const_iterator(begin(RA::getRegistry()), this);
934  }
935 
937  using std::begin;
938  return const_iterator(begin(RA::getRegistry()), this);
939  }
940 
942  using std::end;
943  return iterator(end(RA::getRegistry()), this);
944  }
945 
946  const_iterator end() const {
947  using std::end;
948  return const_iterator(end(RA::getRegistry()), this);
949  }
950 
952  using std::end;
953  return const_iterator(end(RA::getRegistry()), this);
954  }
955 };
956 }
957 
958 template<typename RA1, typename RA2>
960 inline void invertRegisteredArray(const RA1& from, RA2& to) {
961  OGDF_ASSERT(from.registeredAt() != nullptr);
962  for (const auto& key : *from.registeredAt()) {
963  to[from[key]] = key;
964  }
965 }
966 
967 /* The following macro will be expanded in the docs, see doc/ogdf-doxygen.cfg:EXPAND_AS_DEFINED */
968 
969 #define OGDF_DECL_REG_ARRAY(NAME) \
970  template<typename Value, bool WithDefault = true> \
971  using NAME = OGDF_DECL_REG_ARRAY_TYPE(Value, WithDefault); \
972  \
976  template<typename Value> \
977  using NAME##P = NAME<std::unique_ptr<Value>, false>;
ogdf::RegisteredArrayIterator::key_type
typename ArrayType::key_type key_type
Definition: RegisteredArray.h:356
ogdf::RegistryBase
Abstract base class for registries.
Definition: RegisteredArray.h:104
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::internal::RegisteredArrayWithoutDefaultOrIndexAccess::RegisteredArrayWithoutDefaultOrIndexAccess
RegisteredArrayWithoutDefaultOrIndexAccess(const Registry *registry)
Creates a new registered array associated with registry.
Definition: RegisteredArray.h:462
ogdf::internal::RegisteredArrayWithoutDefaultOrIndexAccess::key_type
typename Registry::key_type key_type
Definition: RegisteredArray.h:445
ogdf::RegisteredArray
Dynamic arrays indexed with arbitrary keys.
Definition: RegisteredArray.h:817
ogdf::RegisteredArrayIterator::operator!=
bool operator!=(const RegisteredArrayIterator< ArrayType, KeyIterator, isConst > &iter) const
Inequality operator.
Definition: RegisteredArray.h:392
ogdf::RegistryBase::copyArrayEntries
void copyArrayEntries(int toIndex, int fromIndex)
Copies the entry from fromIndex to toIndex in all registered arrays.
Definition: RegisteredArray.h:218
ogdf::MIN_TABLE_SIZE
static constexpr int MIN_TABLE_SIZE
The default minimum table size for registered arrays.
Definition: RegisteredArray.h:61
ogdf::RegisteredArrayIterator::RegisteredArrayIterator
RegisteredArrayIterator()
Creates a new iterator associated with no array.
Definition: RegisteredArray.h:367
ogdf::internal::RegisteredArrayWithoutDefaultOrIndexAccess::value_ref_type
typename vector_type::reference value_ref_type
Definition: RegisteredArray.h:448
ogdf::RegistryBase::~RegistryBase
virtual ~RegistryBase() noexcept
Destructor. Unregisters all associated arrays.
Definition: RegisteredArray.h:128
ogdf::internal::RegisteredArrayWithDefault::m_default
Value m_default
Definition: RegisteredArray.h:649
ogdf::internal::RegisteredArrayWithoutDefaultOrIndexAccess::swapEntries
void swapEntries(int index1, int index2) override
Swaps the entries stored at index1 and index2.
Definition: RegisteredArray.h:583
ogdf::internal::RegisteredArrayBase::reregister
void reregister(const Registry *registry)
Associates the array with a new registry.
Definition: RegisteredArray.h:312
ogdf::RegistryBase::resizeArrays
void resizeArrays(int size)
Resizes all arrays to size. Only shrinks the arrays if auto shrink is enabled.
Definition: RegisteredArray.h:192
ogdf::RegisteredArray::RegisteredArray
RegisteredArray(const Base &base)
Creates a new registered array associated with the matching registry of base.
Definition: RegisteredArray.h:838
ogdf::RegisteredArray< Registry, bool, WithDefault, Base >::end
iterator end()
Definition: RegisteredArray.h:941
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:66
ogdf::RegisteredArrayIterator::operator==
bool operator==(const RegisteredArrayIterator< ArrayType, KeyIterator, isConst > &iter) const
Equality operator.
Definition: RegisteredArray.h:387
ogdf::RegistryBase::m_mutexRegArrays
std::mutex m_mutexRegArrays
Definition: RegisteredArray.h:120
ogdf::RegisteredArrayIterator::operator++
RegisteredArrayIterator< ArrayType, KeyIterator, isConst > & operator++()
Increment operator (prefix).
Definition: RegisteredArray.h:397
ogdf::RegisteredArray< Registry, bool, WithDefault, Base >::operator[]
value_const_ref_type operator[](int idx) const
Definition: RegisteredArray.h:912
ogdf::RegistryBase::keyRemoved
void keyRemoved(Key key)
Records the deletion of a key and resizes all registered arrays if auto shrink is enabled.
Definition: RegisteredArray.h:178
ogdf::RegisteredArray::RA
typename std::conditional< WithDefault, internal::RegisteredArrayWithDefault< Registry, Value >, internal::RegisteredArrayWithoutDefault< Registry, Value > >::type RA
Definition: RegisteredArray.h:822
ogdf::begin
HypergraphRegistry< HypernodeElement >::iterator begin(const HypergraphRegistry< HypernodeElement > &self)
ogdf::internal::RegisteredArrayWithoutDefaultOrIndexAccess::operator[]
value_ref_type operator[](key_type key)
Returns a reference to the element associated with key.
Definition: RegisteredArray.h:494
ogdf::RegistryBase::resizeArrays
void resizeArrays(int size, bool shrink)
Resizes all arrays to size. If shrink is true, the arrays may also shrink.
Definition: RegisteredArray.h:195
ogdf::RegistryBase::registerArray
OGDF_NODISCARD registration_iterator_type registerArray(registered_array_type *pArray) const
Registers a new array with this registry.
Definition: RegisteredArray.h:144
ogdf::RegisteredArrayIterator::value
value_type & value() const
Returns the value of key() in the registered array.
Definition: RegisteredArray.h:381
ogdf::RegisteredArrayIterator::operator--
RegisteredArrayIterator< ArrayType, KeyIterator, isConst > & operator--()
Decrement operator (prefix).
Definition: RegisteredArray.h:410
ogdf::RegisteredArray< Registry, bool, WithDefault, Base >::operator()
value_const_ref_type operator()(key_type key) const
Definition: RegisteredArray.h:904
ogdf::RegistryBase< Key *, GraphRegistry< Key, GraphObjectContainer< Key >, 1 >, GraphObjectContainer< Key > ::iterator >::registration_list_type
std::list< registered_array_type *, OGDFAllocator< registered_array_type * > > registration_list_type
Definition: RegisteredArray.h:111
ogdf::internal::RegisteredArrayBase::~RegisteredArrayBase
virtual ~RegisteredArrayBase() noexcept
Destructor.
Definition: RegisteredArray.h:289
ogdf::internal::RegisteredArrayWithoutDefaultWithIndexAccess
RegisteredArrayWithoutDefaultOrIndexAccess that also allows accessing its values directly by their in...
Definition: RegisteredArray.h:595
ogdf::internal::RegisteredArrayBase::operator=
RegisteredArrayBase & operator=(RegisteredArrayBase< Registry > &&move_from) noexcept
Assignment operator (move semantics).
Definition: RegisteredArray.h:283
ogdf::internal::RegisteredArrayWithDefault::RegisteredArrayWithDefault
RegisteredArrayWithDefault(const Value &def)
Creates a new registered array associated with no registry and default value def.
Definition: RegisteredArray.h:667
ogdf::internal::RegisteredArrayWithDefault::RA
RegisteredArrayWithoutDefault< Registry, Value > RA
Definition: RegisteredArray.h:648
ogdf::internal::RegisteredArrayBase
Abstract base class for registered arrays.
Definition: RegisteredArray.h:57
ogdf::internal::RegisteredArrayWithDefault::RegisteredArrayWithDefault
RegisteredArrayWithDefault(const Registry *registry, Value &&def)
Creates a new registered array associated with registry and default value def.
Definition: RegisteredArray.h:680
ogdf::RegistryBase::isAutoShrink
bool isAutoShrink() const
Returns whether the registry allows arrays to shrink when keys are removed.
Definition: RegisteredArray.h:239
ogdf::RegistryBase::moveRegisterArray
void moveRegisterArray(registration_iterator_type it, registered_array_type *pArray) const
Stores array pArray at position it in the list of registered arrays.
Definition: RegisteredArray.h:163
ogdf::internal::RegisteredArrayWithDefault::resize
void resize(int size, bool shrink) override
Definition: RegisteredArray.h:707
ogdf::internal::RegisteredArrayWithoutDefaultOrIndexAccess::vector_type
std::vector< Value, OGDFAllocator< Value > > vector_type
Definition: RegisteredArray.h:446
ogdf::RegisteredArray< Registry, bool, WithDefault, Base >::operator[]
value_ref_type operator[](int idx)
Definition: RegisteredArray.h:916
ogdf::internal::RegisteredArrayWithoutDefaultOrIndexAccess::iterator
RegisteredArrayIterator< registered_array, key_iterator, false > iterator
Definition: RegisteredArray.h:451
ogdf::RegisteredArrayIterator::operator++
RegisteredArrayIterator< ArrayType, KeyIterator, isConst > operator++(int)
Increment operator (postfix).
Definition: RegisteredArray.h:403
ogdf::RegistryBase::getRegisteredArrays
const registration_list_type & getRegisteredArrays() const
Returns a reference to the list of all registered arrays.
Definition: RegisteredArray.h:236
ogdf::RegisteredArray< Registry, bool, WithDefault, Base >::cend
const_iterator cend() const
Definition: RegisteredArray.h:951
ogdf::internal::RegisteredArrayBase::swapEntries
virtual void swapEntries(int index1, int index2)=0
Swaps the entries stored at index1 and index2.
ogdf::internal::RegisteredArrayWithDefault::RegisteredArrayWithDefault
RegisteredArrayWithDefault(const Registry *registry)
Creates a new registered array associated with registry and a default-constructed default value.
Definition: RegisteredArray.h:661
ogdf::RegistryBase::setAutoShrink
void setAutoShrink(bool mAutoShrink)
Specifies whether the registry allows arrays to shrink when keys are removed.
Definition: RegisteredArray.h:242
ogdf::internal::RegisteredArrayWithoutDefaultOrIndexAccess::fill
void fill(value_const_ref_type x)
Fills all entries with value x.
Definition: RegisteredArray.h:481
ogdf::RegisteredArray< Registry, bool, WithDefault, Base >::value_ref_type
bool & value_ref_type
Definition: RegisteredArray.h:892
ogdf::internal::RegisteredArrayBase::m_registration
registration_iterator_type m_registration
Definition: RegisteredArray.h:261
ogdf::internal::RegisteredArrayWithoutDefaultOrIndexAccess::operator()
value_ref_type operator()(key_type key)
Returns a reference to the element associated with key.
Definition: RegisteredArray.h:514
ogdf::RegisteredArrayIterator::value_type
typename std::conditional< isConst, const typename ArrayType::value_type, typename ArrayType::value_type >::type value_type
Definition: RegisteredArray.h:358
ogdf::internal::RegisteredArrayBase::registry_type
Registry registry_type
Definition: RegisteredArray.h:258
ogdf::RegisteredArray< Registry, bool, WithDefault, Base >
Specialization to work around vector<bool>.
Definition: RegisteredArray.h:881
ogdf::internal::RegisteredArrayWithoutDefaultWithIndexAccess::RegisteredArrayWithoutDefaultWithIndexAccess
RegisteredArrayWithoutDefaultWithIndexAccess(const Registry *registry)
Definition: RegisteredArray.h:602
ogdf::internal::RegisteredArrayWithoutDefaultOrIndexAccess::getRegistry
const Registry & getRegistry() const
Returns a reference to the associated registry.
Definition: RegisteredArray.h:570
ogdf::RegisteredArray< Registry, bool, WithDefault, Base >::begin
iterator begin()
Definition: RegisteredArray.h:926
ogdf::RegisteredArrayIterator::registry_type
typename ArrayType::registry_type registry_type
Definition: RegisteredArray.h:355
ogdf::internal::RegisteredArrayWithoutDefaultOrIndexAccess::operator[]
value_const_ref_type operator[](key_type key) const
Returns a const reference to the element associated with key.
Definition: RegisteredArray.h:484
ogdf::RegistryBase::m_size
int m_size
Definition: RegisteredArray.h:117
Minisat::Internal::copy
static void copy(const T &from, T &to)
Definition: Alg.h:61
ogdf::internal::RegisteredArrayWithDefault::setDefault
void setDefault(const Value &def)
Sets a new default value for new keys.
Definition: RegisteredArray.h:690
ogdf::internal::RegisteredArrayBase::RegisteredArrayBase
RegisteredArrayBase()=default
Creates a registered array associated with no registry.
ogdf::RegisteredArrayIterator::operator*
value_type & operator*() const
Returns the value of key() in the registered array.
Definition: RegisteredArray.h:384
invertRegisteredArray
void invertRegisteredArray(const RA1 &from, RA2 &to)
Copy data from a ABCArray<XYZ> to an XYZArray<ABC>
Definition: RegisteredArray.h:960
backward::Color::type
type
Definition: backward.hpp:1716
ogdf::RegistryBase::unregisterArray
void unregisterArray(registration_iterator_type it) const noexcept
Unregisters an array associated with this registry.
Definition: RegisteredArray.h:155
OGDF_NODISCARD
#define OGDF_NODISCARD
Indicate that the result of a function call should not be discarded.
Definition: config.h:203
ogdf::internal::RegisteredArrayWithoutDefaultWithIndexAccess::operator[]
RA::value_const_ref_type operator[](int idx) const
Returns a const reference to the element with index idx.
Definition: RegisteredArray.h:608
backward::details::move
const T & move(const T &v)
Definition: backward.hpp:243
ogdf::internal::RegisteredArrayWithDefault::RegisteredArrayWithDefault
RegisteredArrayWithDefault(const Registry *registry, const Value &def)
Creates a new registered array associated with registry and default value def.
Definition: RegisteredArray.h:670
ogdf::internal::RegisteredArrayWithDefault::getDefault
const Value & getDefault() const
Returns the current default value for new keys.
Definition: RegisteredArray.h:693
ogdf::RegisteredArray< Registry, bool, WithDefault, Base >::end
const_iterator end() const
Definition: RegisteredArray.h:946
ogdf::internal::RegisteredArrayWithoutDefaultOrIndexAccess::cbegin
const_iterator cbegin() const
Returns a const iterator to the first key-value pair in the array.
Definition: RegisteredArray.h:536
ogdf::internal::RegisteredArrayWithoutDefaultWithIndexAccess::RegisteredArrayWithoutDefaultWithIndexAccess
RegisteredArrayWithoutDefaultWithIndexAccess()=default
ogdf::internal::RegisteredArrayBase::unregister
void unregister() noexcept
Clears the array and associates it with no registry.
Definition: RegisteredArray.h:305
ogdf::calculateTableSize
int calculateTableSize(int actualCount)
The default growth function for registered arrays.
Definition: RegisteredArray.h:67
ogdf::internal::RegisteredArrayWithoutDefaultOrIndexAccess::RegisteredArrayWithoutDefaultOrIndexAccess
RegisteredArrayWithoutDefaultOrIndexAccess()=default
Creates a new registered array associated with no registry.
ogdf::internal::RegisteredArrayBase::moveRegister
void moveRegister(RegisteredArrayBase< Registry > &move_from)
Moves array registration from move_from to this array.
Definition: RegisteredArray.h:325
ogdf::RegisteredArrayIterator::key
key_type key() const
Returns the current key.
Definition: RegisteredArray.h:378
ogdf::internal::RegisteredArrayWithDefault::fillWithDefault
void fillWithDefault()
Overwrites all values with the current default value.
Definition: RegisteredArray.h:699
ogdf::internal::RegisteredArrayBase::operator=
RegisteredArrayBase & operator=(const RegisteredArrayBase< Registry > &copy)
Assignment operator.
Definition: RegisteredArray.h:277
ogdf::internal::RegisteredArrayWithoutDefaultOrIndexAccess::copyEntry
void copyEntry(int toIndex, int fromIndex) override
This operation is not supported for registered arrays without default.
Definition: RegisteredArray.h:588
ogdf::internal::RegisteredArrayWithDefault
Registered arrays with default values.
Definition: RegisteredArray.h:647
ogdf::RegisteredArray< Registry, bool, WithDefault, Base >::getDefault
value_const_ref_type getDefault() const
Definition: RegisteredArray.h:922
ogdf::internal::RegisteredArrayWithoutDefaultOrIndexAccess::cend
const_iterator cend() const
Returns the const past-the-end iterator of the array.
Definition: RegisteredArray.h:554
config_autogen.h
ogdf::RegistryBase< Key *, GraphRegistry< Key, GraphObjectContainer< Key >, 1 >, GraphObjectContainer< Key > ::iterator >::registry_type
GraphRegistry< Key, GraphObjectContainer< Key >, 1 > registry_type
Definition: RegisteredArray.h:108
ogdf::RegistryBase::keyAdded
void keyAdded(Key key)
Records the addition of a new key and resizes all registered arrays if necessary.
Definition: RegisteredArray.h:171
ogdf::RegistryBase< Key *, GraphRegistry< Key, GraphObjectContainer< Key >, 1 >, GraphObjectContainer< Key > ::iterator >::key_type
Key * key_type
Definition: RegisteredArray.h:107
ogdf::RegistryBase::swapArrayEntries
void swapArrayEntries(int index1, int index2)
Swaps the entries at index1 and index2 in all registered arrays.
Definition: RegisteredArray.h:211
ogdf::internal::RegisteredArrayWithoutDefaultOrIndexAccess::begin
iterator begin()
Returns an iterator to the first key-value pair in the array.
Definition: RegisteredArray.h:524
ogdf::RegisteredArray< Registry, bool, WithDefault, Base >::key_type
typename RA::key_type key_type
Definition: RegisteredArray.h:889
ogdf::RegisteredArray::init
void init(const Base &base)
Reinitializes the array. Associates the array with the matching registry of base.
Definition: RegisteredArray.h:861
ogdf::internal::RegisteredArrayWithoutDefaultOrIndexAccess::resize
void resize(int size, bool shrink) override
Resizes the registered array to size. The array will only shrink if shrink is true.
Definition: RegisteredArray.h:576
ogdf::RegisteredArray< Registry, bool, WithDefault, Base >::operator[]
value_ref_type operator[](key_type key)
Definition: RegisteredArray.h:900
ogdf::internal::RegisteredArrayWithoutDefaultOrIndexAccess::m_data
vector_type m_data
Definition: RegisteredArray.h:455
ogdf::internal::RegisteredArrayWithoutDefaultOrIndexAccess::begin
const_iterator begin() const
Returns a const iterator to the first key-value pair in the array.
Definition: RegisteredArray.h:530
ogdf::RegisteredArrayIterator::operator--
RegisteredArrayIterator< ArrayType, KeyIterator, isConst > operator--(int)
Decrement operator (postfix).
Definition: RegisteredArray.h:416
ogdf::internal::RegisteredArrayBase::m_pRegistry
const Registry * m_pRegistry
Definition: RegisteredArray.h:262
ogdf::RegisteredArray< Registry, bool, WithDefault, Base >::value_const_ref_type
const bool & value_const_ref_type
Definition: RegisteredArray.h:891
ogdf::internal::RegisteredArrayBase::RegisteredArrayBase
RegisteredArrayBase(RegisteredArrayBase< Registry > &&move_from) noexcept
Moves the registration of move_from to this registered array.
Definition: RegisteredArray.h:272
ogdf::internal::RegisteredArrayWithoutDefaultOrIndexAccess::key_iterator
typename Registry::iterator_type key_iterator
Definition: RegisteredArray.h:439
Math.h
Mathematical Helpers.
ogdf::RegistryBase::RegistryBase
RegistryBase()=default
ogdf::internal::RegisteredArrayWithoutDefault
typename std::conditional_t< std::is_integral_v< typename Registry::key_type >, RegisteredArrayWithoutDefaultOrIndexAccess< Registry, Value >, RegisteredArrayWithoutDefaultWithIndexAccess< Registry, Value > > RegisteredArrayWithoutDefault
Registered arrays without default values that automatically allows by-index access to values if Regis...
Definition: RegisteredArray.h:631
ogdf::internal::RegisteredArrayWithDefault::getDefault
Value & getDefault()
Returns the current default value for new keys.
Definition: RegisteredArray.h:696
ogdf::internal::RegisteredArrayWithDefault::copyEntry
void copyEntry(int toIndex, int fromIndex) override
Copies the entry stored at oldIndex to newIndex.
Definition: RegisteredArray.h:703
ogdf::RegistryBase::operator=
RegistryBase & operator=(const RegistryBase &other)=delete
ogdf::graphics::init
void init()
Definition: graphics.h:450
ogdf::internal::RegisteredArrayWithoutDefaultOrIndexAccess
Registered arrays without default values or by-index access to values.
Definition: RegisteredArray.h:437
ogdf::RegisteredArray< Registry, bool, WithDefault, Base >::operator[]
value_const_ref_type operator[](key_type key) const
Definition: RegisteredArray.h:896
ogdf::internal::RegisteredArrayBase::RegisteredArrayBase
RegisteredArrayBase(const RegisteredArrayBase< Registry > &copy)
Creates a registered array associated with the same registry as copy.
Definition: RegisteredArray.h:269
ogdf::internal::RegisteredArrayWithoutDefaultOrIndexAccess::operator()
value_const_ref_type operator()(key_type key) const
Returns a const reference to the element associated with key.
Definition: RegisteredArray.h:504
ogdf::RegisteredArrayIterator::m_it
KeyIterator m_it
Definition: RegisteredArray.h:362
ogdf::internal::RegisteredArrayWithoutDefaultOrIndexAccess::value_type
typename vector_type::value_type value_type
Definition: RegisteredArray.h:447
ogdf::RegisteredArray::RegisteredArray
RegisteredArray(const Base *base, const Value &def)
Creates a new registered array associated with the matching registry of base and initializes all valu...
Definition: RegisteredArray.h:855
ogdf::RegisteredArrayIterator::m_array
array_pointer_type m_array
Definition: RegisteredArray.h:363
basic.h
Basic declarations, included by all source files.
ogdf::RegisteredArrayIterator::RegisteredArrayIterator
RegisteredArrayIterator(KeyIterator mIt, array_pointer_type mArray)
Creates a new iterator.
Definition: RegisteredArray.h:374
std
Definition: GML.h:111
ogdf::end
HypergraphRegistry< HypernodeElement >::iterator end(const HypergraphRegistry< HypernodeElement > &self)
ogdf::RegisteredArray::cast
static const Registry * cast(const Base *base)
Definition: RegisteredArray.h:824
ogdf::internal::RegisteredArrayBase::copyEntry
virtual void copyEntry(int newIndex, int oldIndex)=0
Copies the entry stored at oldIndex to newIndex.
ogdf::internal::RegisteredArrayWithoutDefaultOrIndexAccess::end
const_iterator end() const
Returns the const past-the-end iterator of the array.
Definition: RegisteredArray.h:548
ogdf::internal::RegisteredArrayBase::registeredAt
const Registry * registeredAt() const
Returns a pointer to the associated registry.
Definition: RegisteredArray.h:340
ogdf::RegisteredArrayIterator
Iterator for registered arrays.
Definition: RegisteredArray.h:353
ogdf::internal::RegisteredArrayWithoutDefaultOrIndexAccess::value_const_ref_type
typename vector_type::const_reference value_const_ref_type
Definition: RegisteredArray.h:449
ogdf::RegisteredArray::RegisteredArray
RegisteredArray(const Base *base)
Creates a new registered array associated with the matching registry of base.
Definition: RegisteredArray.h:848
ogdf::RegistryBase< Key *, GraphRegistry< Key, GraphObjectContainer< Key >, 1 >, GraphObjectContainer< Key > ::iterator >::iterator_type
GraphObjectContainer< Key > ::iterator iterator_type
Definition: RegisteredArray.h:109
ogdf::RegisteredArray< Registry, bool, WithDefault, Base >::operator()
value_ref_type operator()(key_type key)
Definition: RegisteredArray.h:908
ogdf::RegistryBase::resizeArrays
void resizeArrays()
Resizes all arrays to the size requested by calculateArraySize(). Only shrinks the arrays if auto shr...
Definition: RegisteredArray.h:189
ogdf::internal::RegisteredArrayWithDefault::setDefault
void setDefault(Value &&def)
Sets a new default value for new keys.
Definition: RegisteredArray.h:687
ogdf::Math::nextPower2
T nextPower2(T x)
Returns the smallest power of 2 that is no less than the given (integral) argument.
Definition: Math.h:82
ogdf::RegisteredArray::init
void init(const Base *base=nullptr)
Reinitializes the array. Associates the array with the matching registry of base.
Definition: RegisteredArray.h:858
ogdf::RegistryBase< Key *, GraphRegistry< Key, GraphObjectContainer< Key >, 1 >, GraphObjectContainer< Key > ::iterator >::registration_iterator_type
typename registration_list_type::iterator registration_iterator_type
Definition: RegisteredArray.h:112
ogdf::RegistryBase::keysCleared
void keysCleared()
Records that all keys have been cleared. If auto shrink is enabled, all arrays are cleared and resize...
Definition: RegisteredArray.h:185
ogdf::internal::RegisteredArrayBase::registration_iterator_type
typename Registry::registration_iterator_type registration_iterator_type
Definition: RegisteredArray.h:259
ogdf::RegisteredArray< Registry, bool, WithDefault, Base >::cbegin
const_iterator cbegin() const
Definition: RegisteredArray.h:936
ogdf::RegisteredArray< Registry, bool, WithDefault, Base >::begin
const_iterator begin() const
Definition: RegisteredArray.h:931
ogdf::RegistryBase::getArraySize
int getArraySize() const
Returns the current size of all registered arrays.
Definition: RegisteredArray.h:245
ogdf::RegisteredArray::RegisteredArray
RegisteredArray()
Creates a new registered array associated with no registry.
Definition: RegisteredArray.h:835
ogdf::RegistryBase::m_registeredArrays
registration_list_type m_registeredArrays
Definition: RegisteredArray.h:115
ogdf::RegistryBase::m_autoShrink
bool m_autoShrink
Definition: RegisteredArray.h:116
ogdf::internal::RegisteredArrayBase::resize
virtual void resize(int size, bool shrink)=0
Resizes the registered array to size. The array will only shrink if shrink is true.
ogdf::internal::RegisteredArrayWithDefault::RegisteredArrayWithDefault
RegisteredArrayWithDefault()
Creates a new registered array associated with no registry and a default-constructed default value.
Definition: RegisteredArray.h:658
ogdf::RegisteredArray::init
void init(const Base *base, const Value &new_default)
Definition: RegisteredArray.h:873
ogdf::RegisteredArray< Registry, bool, WithDefault, Base >::getDefault
value_ref_type getDefault()
Definition: RegisteredArray.h:920
memory.h
Declaration of memory manager for allocating small pieces of memory.
ogdf::internal::RegisteredArrayWithoutDefaultOrIndexAccess::end
iterator end()
Returns the past-the-end iterator of the array.
Definition: RegisteredArray.h:542
ogdf::RegistryBase::unregisterArrays
void unregisterArrays() noexcept
Unregister all associated arrays.
Definition: RegisteredArray.h:225
ogdf::RegisteredArrayIterator::array_pointer_type
typename std::conditional< isConst, const ArrayType *, ArrayType * >::type array_pointer_type
Definition: RegisteredArray.h:359
ogdf::RegisteredArray::RegisteredArray
RegisteredArray(const Base &base, const Value &def)
Creates a new registered array associated with the matching registry of base and initializes all valu...
Definition: RegisteredArray.h:845
ogdf::internal::RegisteredArrayWithoutDefaultOrIndexAccess::init
void init(const Registry *registry=nullptr)
Associates the array with registry. All entries are initialized using the default constructor of Valu...
Definition: RegisteredArray.h:469
ogdf::internal::RegisteredArrayWithoutDefaultOrIndexAccess::const_iterator
RegisteredArrayIterator< registered_array, key_iterator, true > const_iterator
Definition: RegisteredArray.h:452
ogdf::RegistryBase::reserveSpace
void reserveSpace(int new_keys)
Resizes all arrays to make space of new_keys new keys.
Definition: RegisteredArray.h:206
ogdf::RegisteredArray::init
void init(const Base &base, const Value &new_default)
Reinitializes the array with default value new_default.
Definition: RegisteredArray.h:868
ogdf::RegisteredArray< Registry, bool, WithDefault, Base >::value_type
bool value_type
Definition: RegisteredArray.h:890
ogdf::internal::RegisteredArrayWithDefault::RegisteredArrayWithDefault
RegisteredArrayWithDefault(Value &&def)
Creates a new registered array associated with no registry and default value def.
Definition: RegisteredArray.h:677
ogdf::internal::RegisteredArrayWithoutDefaultWithIndexAccess::operator[]
RA::value_ref_type operator[](int idx)
Returns a reference to the element with index idx.
Definition: RegisteredArray.h:617
ogdf::internal::RegisteredArrayWithoutDefaultOrIndexAccess::valid
bool valid() const
Returns true iff the array is associated with a registry.
Definition: RegisteredArray.h:562