Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

NodeSet.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/NodeArray.h>
35 #include <ogdf/basic/List.h>
36 
37 namespace ogdf {
38 
40 
53 template<bool SupportFastSizeQuery = true>
54 class NodeSet {
55 public:
56  using ListType = typename std::conditional<SupportFastSizeQuery, List<node>, ListPure<node>>::type;
57 
59  explicit NodeSet(const Graph &G) : m_it(G) { }
60 
62 
68  void insert(node v) {
69  OGDF_ASSERT(v->graphOf() == m_it.graphOf());
70  ListIterator<node> &itV = m_it[v];
71 
72  if (!itV.valid()) {
73  itV = m_nodes.pushBack(v);
74  }
75  }
76 
78 
84  void remove(node v) {
85  OGDF_ASSERT(v->graphOf() == m_it.graphOf());
86  ListIterator<node> &itV = m_it[v];
87 
88  if (itV.valid()) {
89  m_nodes.del(itV);
90  itV = ListIterator<node>();
91  }
92  }
93 
95 
99  void clear() {
100  m_it.init(graphOf());
101  m_nodes.clear();
102  }
103 
105 
110  bool isMember(node v) const {
111  OGDF_ASSERT(v->graphOf() == m_it.graphOf());
112  return m_it[v].valid();
113  }
114 
116  const ListType &nodes() const {
117  return m_nodes;
118  }
119 
121  const Graph& graphOf() const {
122  return *m_it.graphOf();
123  }
124 
126 
129  int size() const {
130  return m_nodes.size();
131  }
132 
134  template<bool OtherSupportsFastSizeQuery>
136  this = other;
137  }
138 
140  template<bool OtherSupportsFastSizeQuery>
142  m_nodes.clear();
143  m_it.init(other.graphOf());
144  for(node v : other.nodes()) {
145  insert(v);
146  }
147  }
148 
149 private:
153 
156 };
157 
158 }
bool isMember(node v) const
Returns true iff node v is contained in this set.
Definition: NodeSet.h:110
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:492
int size() const
Returns the number of nodes in this set.
Definition: NodeSet.h:129
Doubly linked lists.
Definition: List.h:41
const ListType & nodes() const
Returns a reference to the list of nodes contained in this set.
Definition: NodeSet.h:116
Dynamic arrays indexed with nodes.
Definition: Graph_d.h:438
typename std::conditional< SupportFastSizeQuery, List< node >, ListPure< node > >::type ListType
Definition: NodeSet.h:56
ListType m_nodes
The list of nodes contained in this set.
Definition: NodeSet.h:155
Class for the representation of nodes.
Definition: Graph_d.h:169
Declaration and implementation of NodeArray class.
Encapsulates a pointer to a list element.
Definition: List.h:42
NodeSet(const Graph &G)
Creates an empty node set associated with graph G.
Definition: NodeSet.h:59
NodeArray< ListIterator< node > > 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: NodeSet.h:152
NodeSet & operator=(const NodeSet< OtherSupportsFastSizeQuery > &other)
Assignment operator.
Definition: NodeSet.h:141
void clear()
Removes all nodes from this set.
Definition: NodeSet.h:99
Node sets.
Definition: NodeSet.h:54
The namespace for all OGDF objects.
const Graph & graphOf() const
Returns the associated graph.
Definition: NodeSet.h:121
void insert(node v)
Inserts node v into this set.
Definition: NodeSet.h:68
NodeSet(const NodeSet< OtherSupportsFastSizeQuery > &other)
Copy constructor.
Definition: NodeSet.h:135
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:41
Declaration of doubly linked lists and iterators.