Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

NodeSet.h
Go to the documentation of this file.
1 
33 #pragma once
34 
35 #include <ogdf/basic/NodeArray.h>
36 #include <ogdf/basic/List.h>
37 #include <ogdf/basic/SList.h>
38 
39 
40 
41 namespace ogdf {
42 
43 
45 
57 public:
59  explicit NodeSetSimple(const Graph &G) : m_isContained(G,false) { }
60 
61  // destructor
63 
65 
70  void insert(node v) {
71  OGDF_ASSERT(v->graphOf() == m_isContained.graphOf());
72  bool &isContained = m_isContained[v];
73  if (isContained == false) {
74  isContained = true;
75  m_nodes.pushFront(v);
76  }
77  }
78 
80 
85  void clear() {
86  for(node v : m_nodes) {
87  m_isContained[v] = false;
88  }
89  m_nodes.clear();
90  }
91 
93 
98  bool isMember(node v) const {
99  OGDF_ASSERT(v->graphOf() == m_isContained.graphOf());
100  return m_isContained[v];
101  }
102 
104 
107  const SListPure<node> &nodes() const {
108  return m_nodes;
109  }
110 
111 private:
114 
117 };
118 
119 
120 
122 
137 public:
139  explicit NodeSetPure(const Graph &G) : m_it(G,ListIterator<node>()) { }
140 
141  // destructor
143 
145 
150  void insert(node v) {
151  OGDF_ASSERT(v->graphOf() == m_it.graphOf());
152  ListIterator<node> &itV = m_it[v];
153  if (!itV.valid())
154  itV = m_nodes.pushBack(v);
155  }
156 
158 
163  void remove(node v) {
164  OGDF_ASSERT(v->graphOf() == m_it.graphOf());
165  ListIterator<node> &itV = m_it[v];
166  if (itV.valid()) {
167  m_nodes.del(itV);
168  itV = ListIterator<node>();
169  }
170  }
171 
172 
174 
179  void clear() {
180  for(node v : m_nodes) {
181  m_it[v] = ListIterator<node>();
182  }
183  m_nodes.clear();
184  }
185 
186 
188 
193  bool isMember(node v) const {
194  OGDF_ASSERT(v->graphOf() == m_it.graphOf());
195  return m_it[v].valid();
196  }
197 
199 
202  const ListPure<node> &nodes() const {
203  return m_nodes;
204  }
205 
207  NodeSetPure(const NodeSetPure& V) : m_it(*V.m_it.graphOf(), ListIterator<node>()) {
208  for(node v : V.m_nodes) {
209  insert(v);
210  }
211  }
212 
215  m_nodes.clear();
216  m_it.init(*V.m_it.graphOf());
217  for(node v :V.m_nodes) {
218  insert(v);
219  }
220  return *this;
221  }
222 
223 private:
227 
230 };
231 
232 
233 
235 
250 public:
252  explicit NodeSet(const Graph &G) : m_it(G,ListIterator<node>()) { }
253 
254  // destructor
255  ~NodeSet() { }
256 
258 
263  void insert(node v) {
264  OGDF_ASSERT(v->graphOf() == m_it.graphOf());
265  ListIterator<node> &itV = m_it[v];
266  if (!itV.valid())
267  itV = m_nodes.pushBack(v);
268  }
269 
271 
276  void remove(node v) {
277  OGDF_ASSERT(v->graphOf() == m_it.graphOf());
278  ListIterator<node> &itV = m_it[v];
279  if (itV.valid()) {
280  m_nodes.del(itV);
281  itV = ListIterator<node>();
282  }
283  }
284 
285 
287 
292  void clear() {
293  for(node v : m_nodes) {
294  m_it[v] = ListIterator<node>();
295  }
296  m_nodes.clear();
297  }
298 
299 
301 
306  bool isMember(node v) const {
307  OGDF_ASSERT(v->graphOf() == m_it.graphOf());
308  return m_it[v].valid();
309  }
310 
312 
315  int size() const {
316  return m_nodes.size();
317  }
318 
320 
323  const List<node> &nodes() const {
324  return m_nodes;
325  }
326 
328  NodeSet(const NodeSet& V) : m_it(*V.m_it.graphOf(), ListIterator<node>()) {
329  for(node v : V.m_nodes) {
330  insert(v);
331  }
332  }
333 
335  NodeSet &operator=(const NodeSet &V) {
336  m_nodes.clear();
337  m_it.init(*V.m_it.graphOf());
338  for(node v : V.m_nodes) {
339  insert(v);
340  }
341  return *this;
342  }
343 
344 private:
348 
351 };
352 
353 
354 } // end namespace ogdf
Declaration of singly linked lists and iterators.
void clear()
Removes all nodes from S.
Definition: NodeSet.h:179
bool isMember(node v) const
Returns true if node v is contained in S, false otherwise.
Definition: NodeSet.h:306
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:472
void insert(node v)
Inserts node v into S.
Definition: NodeSet.h:70
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:99
bool isMember(node v) const
Returns true if node v is contained in S, false otherwise.
Definition: NodeSet.h:98
Singly linked lists.
Definition: SList.h:38
NodeSet(const Graph &G)
Creates an empty node set associated with graph G.
Definition: NodeSet.h:252
Doubly linked lists.
Definition: List.h:40
bool isMember(node v) const
Returns true if node v is contained in S, false otherwise.
Definition: NodeSet.h:193
ListPure< node > m_nodes
The list of nodes contained in S.
Definition: NodeSet.h:229
int size() const
Returns the size of S.
Definition: NodeSet.h:315
Node sets.
Definition: NodeSet.h:136
const List< node > & nodes() const
Returns a reference to the list of nodes contained in S.
Definition: NodeSet.h:323
void insert(node v)
Inserts node v into S.
Definition: NodeSet.h:263
void insert(node v)
Inserts node v into S.
Definition: NodeSet.h:150
NodeSetPure & operator=(const NodeSetPure &V)
Assignment operator.
Definition: NodeSet.h:214
NodeSet & operator=(const NodeSet &V)
Assignment operator.
Definition: NodeSet.h:335
Doubly linked lists (maintaining the length of the list).
Definition: List.h:39
Class for the representation of nodes.
Definition: Graph_d.h:167
Declaration and implementation of NodeArray class.
NodeArray< ListIterator< node > > m_it
m_it[v] contains the list iterator pointing to v if v is contained in S, an invalid list iterator oth...
Definition: NodeSet.h:347
Encapsulates a pointer to a list element.
Definition: List.h:41
NodeArray< ListIterator< node > > m_it
m_it[v] contains the list iterator pointing to v if v is contained in S, an invalid list iterator oth...
Definition: NodeSet.h:226
NodeSetPure(const NodeSetPure &V)
Copy constructor.
Definition: NodeSet.h:207
const ListPure< node > & nodes() const
Returns a reference to the list of nodes contained in S.
Definition: NodeSet.h:202
const SListPure< node > & nodes() const
Returns a reference to the list of nodes contained in S.
Definition: NodeSet.h:107
NodeSetSimple(const Graph &G)
Creates an empty node set associated with graph G.
Definition: NodeSet.h:59
NodeArray< bool > m_isContained
m_isContained[v] is true iff v is contained in S.
Definition: NodeSet.h:113
Simple node sets.
Definition: NodeSet.h:56
Node sets.
Definition: NodeSet.h:249
List< node > m_nodes
The list of nodes contained in S.
Definition: NodeSet.h:350
The namespace for all OGDF objects.
SListPure< node > m_nodes
The list of nodes contained in S.
Definition: NodeSet.h:116
NodeSet(const NodeSet &V)
Copy constructor.
Definition: NodeSet.h:328
void clear()
Removes all nodes from S.
Definition: NodeSet.h:85
void clear()
Removes all nodes from S.
Definition: NodeSet.h:292
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:41
NodeSetPure(const Graph &G)
Creates an empty node set associated with graph G.
Definition: NodeSet.h:139
Declaration of doubly linked lists and iterators.