Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
RegisteredArray.h
Go to the documentation of this file.
1
32#pragma once
33
34#include <ogdf/basic/Math.h>
35#include <ogdf/basic/Observer.h>
36#include <ogdf/basic/basic.h>
37#include <ogdf/basic/internal/config_autogen.h>
38#include <ogdf/basic/memory.h>
39
40#include <algorithm>
41#include <cstddef>
42#include <iterator>
43#include <list>
44#include <memory> // IWYU pragma: keep
45#include <type_traits>
46#include <utility>
47#include <vector>
48
49#ifndef OGDF_MEMORY_POOL_NTS
50
51# include <mutex>
52
53#endif
54
55namespace ogdf {
56namespace internal {
57template<typename Registry>
58class RegisteredArrayBase;
59}
60template<typename Key, typename Registry, typename Iterator = void>
61class RegistryBase; // IWYU pragma: keep
62
64static constexpr int MIN_TABLE_SIZE = (1 << 4);
65
67
70inline int calculateTableSize(int actualCount) {
71 return Math::nextPower2(MIN_TABLE_SIZE, actualCount);
72}
73
75template<typename Registry>
76class RegisteredObserver : public Observer<Registry, RegisteredObserver<Registry>> {
78
79public:
81 RegisteredObserver() = default;
82
83 OGDF_DEPRECATED("calls registrationChanged with only partially-constructed child classes, "
84 "see copy constructor of Observer for fix")
85
86 explicit RegisteredObserver(const Registry* R) { Obs::reregister(R); }
87
89 virtual void keyRemoved(typename Registry::key_type v) = 0;
90
92 virtual void keyAdded(typename Registry::key_type v) = 0;
93
95 virtual void keysSwapped(int index1, int index2) = 0;
96
98 virtual void keysCopied(int toIndex, int fromIndex) = 0;
99
101 virtual void keysCleared() = 0;
102
103 const Registry* getRegistry() const { return Obs::getObserved(); }
104};
105
107
138template<typename Key, typename Registry, typename Iterator> // default Iterator=void defined above
139class RegistryBase : public Observable<RegisteredObserver<Registry>, Registry> {
140public:
142 using key_type = Key;
143 using registry_type = Registry;
144 using iterator_type = Iterator;
146 std::list<registered_array_type*, OGDFAllocator<registered_array_type*>>;
147 using registration_iterator_type = typename registration_list_type::iterator;
148
149private:
151
153 bool m_autoShrink = false;
154 int m_size = 0;
155
156#ifndef OGDF_MEMORY_POOL_NTS
157 mutable std::mutex m_mutexRegArrays;
158#endif
159
160protected:
161 RegistryBase() = default;
162
163public:
165 virtual ~RegistryBase() noexcept {
168 }
169
171
177#ifndef OGDF_MEMORY_POOL_NTS
178 std::lock_guard<std::mutex> guard(m_mutexRegArrays);
179#endif
180 return m_registeredArrays.emplace(m_registeredArrays.end(), pArray);
181 }
182
184
188#ifndef OGDF_MEMORY_POOL_NTS
189 std::lock_guard<std::mutex> guard(m_mutexRegArrays);
190#endif
191 m_registeredArrays.erase(it);
192 }
193
196#ifndef OGDF_MEMORY_POOL_NTS
197 std::lock_guard<std::mutex> guard(m_mutexRegArrays);
198#endif
199 *it = pArray;
200 }
201
203 void keyAdded(Key key) {
204 if (static_cast<Registry*>(this)->keyToIndex(key) >= m_size) {
205 resizeArrays();
206 }
207 for (auto& ob : getObservers()) {
208 ob->keyAdded(key);
209 }
210 }
211
213 void keyRemoved(Key key) {
214 if (m_autoShrink) {
215 resizeArrays();
216 }
217 for (auto& ob : getObservers()) {
218 ob->keyRemoved(key);
219 }
220 }
221
223 void keysCleared() {
224 resizeArrays(0);
225 for (auto& ob : getObservers()) {
226 ob->keysCleared();
227 }
228 }
229
232 void resizeArrays() { resizeArrays(static_cast<Registry*>(this)->calculateArraySize(0)); }
233
235 void resizeArrays(int size) { resizeArrays(size, m_autoShrink); }
236
238 void resizeArrays(int size, bool shrink) {
239 if (size == m_size) {
240 return;
241 }
242 m_size = size = max(size, 0);
244 ab->resize(size, shrink);
245 }
246 }
247
249 void reserveSpace(int new_keys) {
250 resizeArrays(static_cast<Registry*>(this)->calculateArraySize(new_keys));
251 }
252
254 void swapArrayEntries(int index1, int index2) {
256 ab->swapEntries(index1, index2);
257 }
258 for (auto& ob : getObservers()) {
259 ob->keysSwapped(index1, index2);
260 }
261 }
262
264 void copyArrayEntries(int toIndex, int fromIndex) {
266 ab->copyEntry(toIndex, fromIndex);
267 }
268 for (auto& ob : getObservers()) {
269 ob->keysCopied(fromIndex, toIndex);
270 }
271 }
272
274 void unregisterArrays() noexcept {
275 while (!m_registeredArrays.empty()) {
276#ifdef OGDF_DEBUG
277 auto size = m_registeredArrays.size();
278#endif
279 m_registeredArrays.front()->unregister();
280 OGDF_ASSERT(m_registeredArrays.size() < size);
281 }
282 }
283
286
288 bool isAutoShrink() const { return m_autoShrink; }
289
291 void setAutoShrink(bool mAutoShrink) { m_autoShrink = mAutoShrink; }
292
294 int getArraySize() const { return m_size; }
295
296 using Obs::getObservers;
297};
298
299namespace internal {
301
307template<class Registry>
309 using registry_type = Registry;
310 using registration_iterator_type = typename Registry::registration_iterator_type;
311
313 const Registry* m_pRegistry = nullptr;
314
315public:
318
321
324 moveRegister(move_from);
325 }
326
330 return *this;
331 }
332
335 moveRegister(move_from);
336 return *this;
337 }
338
340 virtual ~RegisteredArrayBase() noexcept {
341 if (m_pRegistry) {
342 m_pRegistry->unregisterArray(m_registration);
343 }
344 }
345
347 virtual void resize(int size, bool shrink) = 0;
348
350 virtual void swapEntries(int index1, int index2) = 0;
351
353 virtual void copyEntry(int newIndex, int oldIndex) = 0;
354
356 void unregister() noexcept {
357 resize(0, true);
358 reregister(nullptr);
359 }
360
361protected:
363 void reregister(const Registry* registry) {
364 if (m_pRegistry) {
365 m_pRegistry->unregisterArray(m_registration);
366 }
367 m_pRegistry = registry;
368 if (m_pRegistry != nullptr) {
369 m_registration = m_pRegistry->registerArray(this);
370 } else {
372 }
373 }
374
377 if (m_pRegistry) {
378 m_pRegistry->unregisterArray(m_registration);
379 }
380 m_pRegistry = move_from.m_pRegistry;
381 m_registration = move_from.m_registration;
382 move_from.m_pRegistry = nullptr;
384 if (m_pRegistry != nullptr) {
385 m_pRegistry->moveRegisterArray(m_registration, this);
386 }
387 }
388
389public:
391 const Registry* registeredAt() const { return m_pRegistry; }
392};
393}
394
396
403template<class ArrayType, class KeyIterator, bool isConst = false>
405public:
406 using registry_type = typename ArrayType::registry_type;
407 using key_type = typename ArrayType::key_type;
408 using value_type = typename std::conditional<isConst, const typename ArrayType::value_type,
409 typename ArrayType::value_type>::type;
410 using array_pointer_type = typename std::conditional<isConst, const ArrayType*, ArrayType*>::type;
411
412private:
413 KeyIterator m_it;
415
416public:
419
421
426 : m_it(mIt), m_array(mArray) { }
427
429 key_type key() const { return *m_it; }
430
432 value_type& value() const { return (*m_array)[*m_it]; }
433
435 value_type& operator*() const { return (*m_array)[*m_it]; }
436
439 return m_it == iter.m_it && m_array == iter.m_array;
440 }
441
444 return !operator==(iter);
445 }
446
452
459
465
472};
473
474namespace internal {
476
487template<class Registry, class Value>
489protected:
490 using key_iterator = typename Registry::iterator_type;
493
494public:
495 using registry_type = Registry;
496 using key_type = typename Registry::key_type;
497 using vector_type = std::vector<Value, OGDFAllocator<Value>>;
498 using value_type = typename vector_type::value_type;
499 using value_ref_type = typename vector_type::reference;
500 using value_const_ref_type = typename vector_type::const_reference;
501
504
505protected:
507
508public:
511
513 explicit RegisteredArrayWithoutDefaultOrIndexAccess(const Registry* registry) {
514 // during base class initialization, no part of the derived class exists, so this will always call our base init
515 // so base classes should call their own init themselves
516 registered_array::init(registry);
517 }
518
520 void init(const Registry* registry = nullptr) {
521 if (registry == nullptr) {
522 resize(0, true);
523 } else {
524 OGDF_ASSERT(registry->maxKeyIndex() < registry->getArraySize());
525 resize(0, false);
526 resize(registry->getArraySize(), true);
527 }
529 }
530
532 void fill(value_const_ref_type x) { m_data.assign(m_data.size(), x); }
533
536 OGDF_ASSERT(getRegistry().isKeyAssociated(key));
537#ifdef OGDF_DEBUG
538 return m_data.at(registeredAt()->keyToIndex(key));
539#else
540 return m_data[registeredAt()->keyToIndex(key)];
541#endif
542 }
543
546 OGDF_ASSERT(getRegistry().isKeyAssociated(key));
547#ifdef OGDF_DEBUG
548 return m_data.at(registeredAt()->keyToIndex(key));
549#else
550 return m_data[registeredAt()->keyToIndex(key)];
551#endif
552 }
553
556 OGDF_ASSERT(getRegistry().isKeyAssociated(key));
557#ifdef OGDF_DEBUG
558 return m_data.at(registeredAt()->keyToIndex(key));
559#else
560 return m_data[registeredAt()->keyToIndex(key)];
561#endif
562 }
563
566 OGDF_ASSERT(getRegistry().isKeyAssociated(key));
567#ifdef OGDF_DEBUG
568 return m_data.at(registeredAt()->keyToIndex(key));
569#else
570 return m_data[registeredAt()->keyToIndex(key)];
571#endif
572 }
573
576 using std::begin;
577 return iterator(begin(getRegistry()), this);
578 }
579
582 using std::begin;
583 return const_iterator(begin(getRegistry()), this);
584 }
585
588 using std::begin;
589 return const_iterator(begin(getRegistry()), this);
590 }
591
594 using std::end;
595 return iterator(end(getRegistry()), this);
596 }
597
600 using std::end;
601 return const_iterator(end(getRegistry()), this);
602 }
603
606 using std::end;
607 return const_iterator(end(getRegistry()), this);
608 }
609
611
613 bool valid() const {
614 OGDF_ASSERT(registeredAt() == nullptr || registeredAt()->maxKeyIndex() < 0
615 || ((size_t)registeredAt()->maxKeyIndex()) < m_data.size());
616 return registeredAt();
617 }
618
619protected:
621 inline const Registry& getRegistry() const {
624 return *registeredAt();
625 }
626
627 void resize(int size, bool shrink) override {
628 m_data.resize(size);
629 if (shrink) {
630 m_data.shrink_to_fit();
631 }
632 }
633
634 void swapEntries(int index1, int index2) override {
635 using std::swap;
636 swap(m_data.at(index1), m_data.at(index2));
637 }
638
640 void copyEntry(int toIndex, int fromIndex) override {
641 // silently ignored
642 }
643};
644
646template<class Registry, class Value>
648 : public RegisteredArrayWithoutDefaultOrIndexAccess<Registry, Value> {
650
651public:
653
654 explicit RegisteredArrayWithoutDefaultWithIndexAccess(const Registry* registry)
655 : RA(registry) { }
656
657 using RA::operator[];
658
660 typename RA::value_const_ref_type operator[](int idx) const {
661#ifdef OGDF_DEBUG
662 return RA::m_data.at(idx);
663#else
664 return RA::m_data[idx];
665#endif
666 }
667
669 typename RA::value_ref_type operator[](int idx) {
670#ifdef OGDF_DEBUG
671 return RA::m_data.at(idx);
672#else
673 return RA::m_data[idx];
674#endif
675 }
676};
677
679template<class Registry, class Value>
681 typename std::conditional_t<std::is_integral_v<typename Registry::key_type>,
684
686
698template<class Registry, class Value>
702
703 static_assert(std::is_copy_constructible_v<Value>,
704 "This RegisteredArrayWithDefault<Value> instantiation (e.g. NodeArray<Graph>) is "
705 "invalid because Value is not copy-constructible! "
706 "Use, e.g., NodeArrayP<Graph> or NodeArray<unique_ptr<Graph>, false> instead.");
707
708public:
711
713 explicit RegisteredArrayWithDefault(const Registry* registry) : RA(), m_default() {
714 // call init from here, as our virtual override of init is not available during initialization of the base class
715 RA::init(registry);
716 };
717
719 explicit RegisteredArrayWithDefault(const Value& def) : RA(), m_default(def) {};
720
722 explicit RegisteredArrayWithDefault(const Registry* registry, const Value& def)
723 : RA(), m_default(def) {
724 // call init from here, as our virtual override of init is not available during initialization of the base class
725 RA::init(registry);
726 };
727
729 explicit RegisteredArrayWithDefault(Value&& def) : RA(), m_default(std::forward<Value>(def)) {};
730
732 explicit RegisteredArrayWithDefault(const Registry* registry, Value&& def)
733 : RA(), m_default(std::forward<Value>(def)) {
734 // call init from here, as our virtual override of init is not available during initialization of the base class
735 RA::init(registry);
736 };
737
739 void setDefault(Value&& def) { m_default = std::forward<Value>(def); }
740
742 void setDefault(const Value& def) { m_default = def; }
743
745 const Value& getDefault() const { return m_default; }
746
748 Value& getDefault() { return m_default; }
749
751 void fillWithDefault() { RA::m_data.assign(RA::getRegistry().getArraySize(), m_default); }
752
753protected:
755 void copyEntry(int toIndex, int fromIndex) override {
756 RA::m_data.at(toIndex) = RA::m_data.at(fromIndex);
757 }
758
759 void resize(int size, bool shrink) override {
760 RA::m_data.resize(size, m_default);
761 if (shrink) {
762 RA::m_data.shrink_to_fit();
763 }
764 }
765};
766}
767
769
868template<class Registry, class Value, bool WithDefault = true, class Base = Registry>
870 : public std::conditional<WithDefault, internal::RegisteredArrayWithDefault<Registry, Value>,
871 internal::RegisteredArrayWithoutDefault<Registry, Value>>::type {
872 using RA =
873 typename std::conditional<WithDefault, internal::RegisteredArrayWithDefault<Registry, Value>,
875
876 static inline const Registry* cast(const Base* base) {
877 if (base != nullptr) {
878 // unpack the pointer to invoke the conversion operator
879 return &((const Registry&)*base);
880 } else {
881 return nullptr;
882 }
883 }
884
885public:
888
890 explicit RegisteredArray(const Base& base) : RA(cast(&base)) {};
891
897 RegisteredArray(const Base& base, const Value& def) : RA(cast(&base), def) {};
898
900 explicit RegisteredArray(const Base* base) : RA(cast(base)) {};
901
907 RegisteredArray(const Base* base, const Value& def) : RA(cast(base), def) {};
908
910 void init(const Base* base = nullptr) { RA::init(cast(base)); }
911
913 void init(const Base& base) { RA::init(cast(&base)); }
914
920 void init(const Base& base, const Value& new_default) {
921 RA::setDefault(new_default);
922 RA::init(cast(&base));
923 }
924
925 void init(const Base* base, const Value& new_default) {
926 RA::setDefault(new_default);
927 RA::init(cast(base));
928 }
929};
930
932template<class Registry, bool WithDefault, class Base>
933class RegisteredArray<Registry, bool, WithDefault, Base>
934 : public RegisteredArray<Registry, unsigned char, WithDefault, Base> {
937
938public:
939 using RA::RA;
940
941 using key_type = typename RA::key_type;
942 using value_type = bool;
943 using value_const_ref_type = const bool&;
944 using value_ref_type = bool&;
947
949 return reinterpret_cast<value_const_ref_type>(RA::operator[](key));
950 }
951
953 return reinterpret_cast<value_ref_type>(RA::operator[](key));
954 }
955
957 return reinterpret_cast<value_const_ref_type>(RA::operator()(key));
958 }
959
961 return reinterpret_cast<value_ref_type>(RA::operator()(key));
962 }
963
965 return reinterpret_cast<value_const_ref_type>(RA::operator[](idx));
966 }
967
969 return reinterpret_cast<value_ref_type>(RA::operator[](idx));
970 }
971
972 value_ref_type getDefault() { return reinterpret_cast<value_ref_type>(RA::getDefault()); }
973
975 return reinterpret_cast<value_const_ref_type>(RA::getDefault());
976 }
977
979 using std::begin;
980 return iterator(begin(RA::getRegistry()), this);
981 }
982
984 using std::begin;
985 return const_iterator(begin(RA::getRegistry()), this);
986 }
987
989 using std::begin;
990 return const_iterator(begin(RA::getRegistry()), this);
991 }
992
994 using std::end;
995 return iterator(end(RA::getRegistry()), this);
996 }
997
999 using std::end;
1000 return const_iterator(end(RA::getRegistry()), this);
1001 }
1002
1004 using std::end;
1005 return const_iterator(end(RA::getRegistry()), this);
1006 }
1007};
1008}
1009
1010template<typename RA1, typename RA2>
1012inline void invertRegisteredArray(const RA1& from, RA2& to) {
1013 OGDF_ASSERT(from.registeredAt() != nullptr);
1014 for (const auto& key : *from.registeredAt()) {
1015 to[from[key]] = key;
1016 }
1017}
1018
1019/* The following macro will be expanded in the docs, see doc/ogdf-doxygen.cfg:EXPAND_AS_DEFINED */
1020
1021#define OGDF_DECL_REG_ARRAY(NAME) \
1022 template<typename Value, bool WithDefault = true> \
1023 using NAME = OGDF_DECL_REG_ARRAY_TYPE(Value, WithDefault); \
1024
\
1028 template<typename Value> \
1029 using NAME##P = NAME<std::unique_ptr<Value>, false>;
Simple, safe base classes for C++ observables and observers.
void invertRegisteredArray(const RA1 &from, RA2 &to)
Copy data from a ABCArray<XYZ> to an XYZArray<ABC>
Mathematical Helpers.
Basic declarations, included by all source files.
Base class for an observable object that can be tracked by multiple Observer objects.
Definition Observer.h:127
const ListPure< RegisteredObserver< Registry > * > & getObservers() const
Definition Observer.h:206
Base class for an observer for a single Observable object.
Definition Observer.h:53
void reregister(const Registry *obs)
Associates observer instance with instance obs.
Definition Observer.h:96
Specialization to work around vector<bool>.
value_const_ref_type operator[](key_type key) const
value_const_ref_type operator()(key_type key) const
Dynamic arrays indexed with arbitrary keys.
typename std::conditional< WithDefault, internal::RegisteredArrayWithDefault< Registry, Value >, internal::RegisteredArrayWithoutDefault< Registry, Value > >::type RA
RegisteredArray(const Base &base, const Value &def)
Creates a new registered array associated with the matching registry of base and initializes all valu...
void init(const Base &base)
Reinitializes the array. Associates the array with the matching registry of base.
RegisteredArray()
Creates a new registered array associated with no registry.
RegisteredArray(const Base *base)
Creates a new registered array associated with the matching registry of base.
void init(const Base *base=nullptr)
Reinitializes the array. Associates the array with the matching registry of base.
void init(const Base &base, const Value &new_default)
Reinitializes the array with default value new_default.
static const Registry * cast(const Base *base)
void init(const Base *base, const Value &new_default)
RegisteredArray(const Base *base, const Value &def)
Creates a new registered array associated with the matching registry of base and initializes all valu...
RegisteredArray(const Base &base)
Creates a new registered array associated with the matching registry of base.
Iterator for registered arrays.
RegisteredArrayIterator(KeyIterator mIt, array_pointer_type mArray)
Creates a new iterator.
value_type & value() const
Returns the value of key() in the registered array.
bool operator==(const RegisteredArrayIterator< ArrayType, KeyIterator, isConst > &iter) const
Equality operator.
RegisteredArrayIterator< ArrayType, KeyIterator, isConst > operator++(int)
Increment operator (postfix).
typename std::conditional< isConst, const ArrayType *, ArrayType * >::type array_pointer_type
typename ArrayType::key_type key_type
typename std::conditional< isConst, const typename ArrayType::value_type, typename ArrayType::value_type >::type value_type
RegisteredArrayIterator< ArrayType, KeyIterator, isConst > operator--(int)
Decrement operator (postfix).
key_type key() const
Returns the current key.
RegisteredArrayIterator< ArrayType, KeyIterator, isConst > & operator++()
Increment operator (prefix).
bool operator!=(const RegisteredArrayIterator< ArrayType, KeyIterator, isConst > &iter) const
Inequality operator.
value_type & operator*() const
Returns the value of key() in the registered array.
RegisteredArrayIterator()
Creates a new iterator associated with no array.
RegisteredArrayIterator< ArrayType, KeyIterator, isConst > & operator--()
Decrement operator (prefix).
typename ArrayType::registry_type registry_type
Abstract Base class for registry observers.
virtual void keyRemoved(typename Registry::key_type v)=0
Called by watched registry just before a key is deleted.
virtual void keyAdded(typename Registry::key_type v)=0
Called by watched registry after a key has been added.
const Registry * getRegistry() const
virtual void keysSwapped(int index1, int index2)=0
Called when an entry is swapped between index1 and index2 in all registered arrays.
virtual void keysCopied(int toIndex, int fromIndex)=0
Called when an entry is copied from fromIndex to toIndex in all registered arrays.
virtual void keysCleared()=0
Called by watched registry when its clear function is called, just before things are removed.
RegisteredObserver()=default
Constructs instance of RegisteredObserver class.
Abstract base class for registries.
typename registration_list_type::iterator registration_iterator_type
void copyArrayEntries(int toIndex, int fromIndex)
Copies the entry from fromIndex to toIndex in all registered arrays.
const registration_list_type & getRegisteredArrays() const
Returns a reference to the list of all registered arrays.
void resizeArrays(int size, bool shrink)
Resizes all arrays to size. If shrink is true, the arrays may also shrink.
RegistryBase()=default
void resizeArrays(int size)
Resizes all arrays to size. Only shrinks the arrays if auto shrink is enabled.
void keyAdded(Key key)
Records the addition of a new key and resizes all registered arrays if necessary.
bool isAutoShrink() const
Returns whether the registry allows arrays to shrink when keys are removed.
virtual ~RegistryBase() noexcept
Destructor. Unregisters all associated arrays.
std::mutex m_mutexRegArrays
void reserveSpace(int new_keys)
Resizes all arrays to make space of new_keys new keys.
void resizeArrays()
Resizes all arrays to the size requested by calculateArraySize(). Only shrinks the arrays if auto shr...
int getArraySize() const
Returns the current size of all registered arrays.
registration_list_type m_registeredArrays
void keysCleared()
Records that all keys have been cleared. If auto shrink is enabled, all arrays are cleared and resize...
void moveRegisterArray(registration_iterator_type it, registered_array_type *pArray) const
Stores array pArray at position it in the list of registered arrays.
void swapArrayEntries(int index1, int index2)
Swaps the entries at index1 and index2 in all registered arrays.
OGDF_NODISCARD registration_iterator_type registerArray(registered_array_type *pArray) const
Registers a new array with this registry.
void unregisterArray(registration_iterator_type it) const noexcept
Unregisters an array associated with this registry.
std::list< registered_array_type *, OGDFAllocator< registered_array_type * > > registration_list_type
void keyRemoved(Key key)
Records the deletion of a key and resizes all registered arrays if auto shrink is enabled.
void setAutoShrink(bool mAutoShrink)
Specifies whether the registry allows arrays to shrink when keys are removed.
void unregisterArrays() noexcept
Unregister all associated arrays.
Abstract base class for registered arrays.
const Registry * registeredAt() const
Returns a pointer to the associated registry.
RegisteredArrayBase & operator=(const RegisteredArrayBase< Registry > &copy)
Assignment operator.
virtual void swapEntries(int index1, int index2)=0
Swaps the entries stored at index1 and index2.
virtual void copyEntry(int newIndex, int oldIndex)=0
Copies the entry stored at oldIndex to newIndex.
RegisteredArrayBase(const RegisteredArrayBase< Registry > &copy)
Creates a registered array associated with the same registry as copy.
typename Registry::registration_iterator_type registration_iterator_type
void moveRegister(RegisteredArrayBase< Registry > &move_from)
Moves array registration from move_from to this array.
RegisteredArrayBase(RegisteredArrayBase< Registry > &&move_from) noexcept
Moves the registration of move_from to this registered array.
RegisteredArrayBase & operator=(RegisteredArrayBase< Registry > &&move_from) noexcept
Assignment operator (move semantics).
void unregister() noexcept
Clears the array and associates it with no registry.
virtual ~RegisteredArrayBase() noexcept
Destructor.
registration_iterator_type m_registration
RegisteredArrayBase()=default
Creates a registered array associated with no registry.
void reregister(const Registry *registry)
Associates the array with a new registry.
virtual void resize(int size, bool shrink)=0
Resizes the registered array to size. The array will only shrink if shrink is true.
Registered arrays with default values.
RegisteredArrayWithDefault(const Value &def)
Creates a new registered array associated with no registry and default value def.
RegisteredArrayWithoutDefault< Registry, Value > RA
RegisteredArrayWithDefault()
Creates a new registered array associated with no registry and a default-constructed default value.
void setDefault(Value &&def)
Sets a new default value for new keys.
RegisteredArrayWithDefault(const Registry *registry, Value &&def)
Creates a new registered array associated with registry and default value def.
RegisteredArrayWithDefault(Value &&def)
Creates a new registered array associated with no registry and default value def.
void fillWithDefault()
Overwrites all values with the current default value.
void copyEntry(int toIndex, int fromIndex) override
Copies the entry stored at oldIndex to newIndex.
const Value & getDefault() const
Returns the current default value for new keys.
void resize(int size, bool shrink) override
void setDefault(const Value &def)
Sets a new default value for new keys.
RegisteredArrayWithDefault(const Registry *registry)
Creates a new registered array associated with registry and a default-constructed default value.
Value & getDefault()
Returns the current default value for new keys.
RegisteredArrayWithDefault(const Registry *registry, const Value &def)
Creates a new registered array associated with registry and default value def.
Registered arrays without default values or by-index access to values.
RegisteredArrayIterator< registered_array, key_iterator, false > iterator
const Registry * registeredAt() const
Returns a pointer to the associated registry.
value_ref_type operator()(key_type key)
Returns a reference to the element associated with key.
bool valid() const
Returns true iff the array is associated with a registry.
typename vector_type::const_reference value_const_ref_type
const_iterator cbegin() const
Returns a const iterator to the first key-value pair in the array.
void resize(int size, bool shrink) override
Resizes the registered array to size. The array will only shrink if shrink is true.
const_iterator begin() const
Returns a const iterator to the first key-value pair in the array.
value_const_ref_type operator[](key_type key) const
Returns a const reference to the element associated with key.
iterator begin()
Returns an iterator to the first key-value pair in the array.
const_iterator end() const
Returns the const past-the-end iterator of the array.
value_const_ref_type operator()(key_type key) const
Returns a const reference to the element associated with key.
iterator end()
Returns the past-the-end iterator of the array.
void init(const Registry *registry=nullptr)
Associates the array with registry. All entries are initialized using the default constructor of Valu...
const Registry & getRegistry() const
Returns a reference to the associated registry.
RegisteredArrayIterator< registered_array, key_iterator, true > const_iterator
void fill(value_const_ref_type x)
Fills all entries with value x.
RegisteredArrayWithoutDefaultOrIndexAccess()=default
Creates a new registered array associated with no registry.
void swapEntries(int index1, int index2) override
Swaps the entries stored at index1 and index2.
const_iterator cend() const
Returns the const past-the-end iterator of the array.
void copyEntry(int toIndex, int fromIndex) override
This operation is not supported for registered arrays without default.
RegisteredArrayWithoutDefaultOrIndexAccess(const Registry *registry)
Creates a new registered array associated with registry.
value_ref_type operator[](key_type key)
Returns a reference to the element associated with key.
std::vector< Value, OGDFAllocator< Value > > vector_type
RegisteredArrayWithoutDefaultOrIndexAccess that also allows accessing its values directly by their in...
RA::value_const_ref_type operator[](int idx) const
Returns a const reference to the element with index idx.
RA::value_ref_type operator[](int idx)
Returns a reference to the element with index idx.
#define OGDF_NODISCARD
Indicate that the result of a function call should not be discarded.
Definition config.h:289
#define OGDF_DEPRECATED(reason)
Mark a class / member / function as deprecated.
Definition config.h:206
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:52
Declaration of memory manager for allocating small pieces of memory.
T nextPower2(T x)
Returns the smallest power of 2 that is no less than the given (integral) argument.
Definition Math.h:82
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...
The namespace for all OGDF objects.
HypergraphRegistry< HypernodeElement >::iterator begin(const HypergraphRegistry< HypernodeElement > &self)
int calculateTableSize(int actualCount)
The default growth function for registered arrays.
static constexpr int MIN_TABLE_SIZE
The default minimum table size for registered arrays.
HypergraphRegistry< HypernodeElement >::iterator end(const HypergraphRegistry< HypernodeElement > &self)
Definition GML.h:111