Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

RegisteredSet.h
Go to the documentation of this file.
1 
31 #pragma once
32 
33 #include <ogdf/basic/List.h>
35 
36 #include <type_traits>
37 
38 namespace ogdf {
39 
41 
54 template<class Registry, bool SupportFastSizeQuery = true>
56 public:
57  using element_type = typename Registry::key_type;
58  using list_type = typename std::conditional<SupportFastSizeQuery, List<element_type>,
60 
62  explicit RegisteredSet(const Registry& R) : m_it(&R) { }
63 
65  explicit RegisteredSet() : m_it() { }
66 
68  void init() {
69  m_it.init();
70  m_elements.clear();
71  }
72 
74  void init(const Registry& R) {
75  m_it.init(&R);
76  m_elements.clear();
77  }
78 
80 
86  void insert(element_type v) {
88  if (!itV.valid()) {
89  itV = m_elements.pushBack(v);
90  }
91  }
92 
94 
102  if (itV.valid()) {
103  m_elements.del(itV);
105  return true;
106  } else {
107  return false;
108  }
109  }
110 
112 
118  void clear() {
119  if (!registeredAt()) {
120  return;
121  }
122  if (size() * 10 < registeredAt()->getArraySize()) {
123  while (!m_elements.empty()) {
124  remove(m_elements.front());
125  }
126  } else {
128  m_elements.clear();
129  }
130  }
131 
133 
138  bool isMember(element_type v) const { return m_it[v].valid(); }
139 
141  bool operator()(element_type v) const { return isMember(v); }
142 
144  const list_type& elements() const { return m_elements; }
145 
147  const Registry* registeredAt() const { return m_it.registeredAt(); }
148 
150 
153  int size() const { return m_elements.size(); }
154 
155  typename list_type::const_iterator begin() const { return m_elements.begin(); }
156 
157  typename list_type::const_iterator end() const { return m_elements.end(); }
158 
160  template<bool OtherSupportsFastSizeQuery>
162  this = other;
163  }
164 
166  template<bool OtherSupportsFastSizeQuery>
168  m_elements.clear();
169  m_it.init(other.registeredAt());
170  for (element_type v : other.elements()) {
171  insert(v);
172  }
173  }
174 
175 private:
179 
182 };
183 
184 }
ogdf::RegisteredSet< ConstCombinatorialEmbedding, true >::element_type
typename ConstCombinatorialEmbedding ::key_type element_type
Definition: RegisteredSet.h:57
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::RegisteredSet::elements
const list_type & elements() const
Returns a reference to the list of elements contained in this set.
Definition: RegisteredSet.h:144
ogdf::RegisteredArray
Dynamic arrays indexed with arbitrary keys.
Definition: RegisteredArray.h:817
ogdf::RegisteredSet::begin
list_type::const_iterator begin() const
Definition: RegisteredSet.h:155
ogdf::RegisteredSet::m_elements
list_type m_elements
The list of elements contained in this set.
Definition: RegisteredSet.h:181
ogdf::ListIteratorBase::valid
bool valid() const
Returns true iff the iterator points to an element.
Definition: List.h:153
ogdf::RegisteredSet< ConstCombinatorialEmbedding, true >::list_type
typename std::conditional< SupportFastSizeQuery, List< element_type >, ListPure< element_type > >::type list_type
Definition: RegisteredSet.h:59
ogdf::RegisteredSet::size
int size() const
Returns the number of elements in this set.
Definition: RegisteredSet.h:153
ogdf::RegisteredSet::init
void init(const Registry &R)
Reinitializes the set. Associates the set with registry R.
Definition: RegisteredSet.h:74
ogdf::RegisteredSet::registeredAt
const Registry * registeredAt() const
Returns the associated registry.
Definition: RegisteredSet.h:147
ogdf::RegisteredSet::end
list_type::const_iterator end() const
Definition: RegisteredSet.h:157
ogdf::RegisteredSet::m_it
RegisteredArray< Registry, ListIterator< element_type >, false > m_it
m_it[v] contains the list iterator pointing to v if v is contained in this set, or an invalid list it...
Definition: RegisteredSet.h:178
ogdf::RegisteredSet::init
void init()
Reinitializes the set. Associates the set with no registry.
Definition: RegisteredSet.h:68
backward::Color::type
type
Definition: backward.hpp:1716
ogdf::RegisteredSet::insert
void insert(element_type v)
Inserts element v into this set.
Definition: RegisteredSet.h:86
RegisteredArray.h
Declaration and implementation of RegisteredArray class.
ogdf::RegisteredSet::remove
bool remove(element_type v)
Removes element v from this set and return true iff v was previously present.
Definition: RegisteredSet.h:100
ogdf::RegisteredSet::isMember
bool isMember(element_type v) const
Returns true iff element v is contained in this set.
Definition: RegisteredSet.h:138
ogdf::RegisteredSet::clear
void clear()
Removes all elements from this set.
Definition: RegisteredSet.h:118
ogdf::RegisteredSet
Constant-time set operations.
Definition: RegisteredSet.h:55
ogdf::RegisteredSet::RegisteredSet
RegisteredSet()
Creates an empty set associated with no registry.
Definition: RegisteredSet.h:65
ogdf::ListPure
Doubly linked lists.
Definition: List.h:55
ogdf::RegisteredSet::operator()
bool operator()(element_type v) const
Returns the same as isMember() to use an RegisteredSet instance as filter function.
Definition: RegisteredSet.h:141
ogdf::RegisteredSet::RegisteredSet
RegisteredSet(const RegisteredSet< Registry, OtherSupportsFastSizeQuery > &other)
Copy constructor.
Definition: RegisteredSet.h:161
ogdf::RegisteredSet::operator=
RegisteredSet & operator=(const RegisteredSet< Registry, OtherSupportsFastSizeQuery > &other)
Assignment operator.
Definition: RegisteredSet.h:167
List.h
Declaration of doubly linked lists and iterators.
ogdf::ListIteratorBase
Encapsulates a pointer to a list element.
Definition: List.h:51
ogdf::RegisteredSet::RegisteredSet
RegisteredSet(const Registry &R)
Creates an empty set associated with registry R.
Definition: RegisteredSet.h:62