Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

OGDFVector.h
Go to the documentation of this file.
1 
31 #pragma once
32 
33 #include <cstddef>
34 #include <vector>
35 
36 namespace ogdf {
37 namespace internal {
38 namespace gcm {
39 
40 namespace datastructure {
41 
42 template<typename T, typename Graph>
43 class NodeVector : public std::vector<T> {
44 private:
45  using Node = typename Graph::Node;
46  using reference = typename std::vector<T>::reference;
47  using const_reference = typename std::vector<T>::const_reference;
48 
49  const Graph* g;
51 
52 
53 public:
54  NodeVector() : g(nullptr) { }
55 
56  NodeVector(const Graph& _g) : std::vector<T>(_g.max_node_index() + 1), g(&_g) { }
57 
58  NodeVector(const Graph& _g, T& v)
59  : std::vector<T>(_g.max_node_index() + 1, v), g(&_g), default_value(v) { }
60 
61  NodeVector(const Graph& _g, T v)
62  : std::vector<T>(_g.max_node_index() + 1, v), g(&_g), default_value(v) { }
63 
65  : std::vector<T>(x), g(x.g), default_value(x.default_value) { }
66 
67  inline void adapt() {
68  if ((std::size_t)g->max_node_index() >= std::vector<T>::size()) {
69  std::vector<T>::resize(g->max_node_index() + 1, default_value);
70  }
71  }
72 
74  adapt();
75  return std::vector<T>::operator[](v->index());
76  }
77 
78  const_reference operator[](const Node& v) const {
79  OGDF_ASSERT((std::size_t)v->index() < this->size());
80  return std::vector<T>::operator[](v->index());
81  }
82 
84  std::vector<T>::operator=(x);
86  return *this;
87  }
88 
90  std::vector<T>::operator=(std::move(x));
91  default_value = x.default_value;
92  return *this;
93  }
94 };
95 
96 template<typename T, typename Graph>
97 class EdgeVector : public std::vector<T> {
98 private:
99  using Edge = typename Graph::Edge;
100  using reference = typename std::vector<T>::reference;
101  using const_reference = typename std::vector<T>::const_reference;
102  const Graph* g;
104 
105 public:
106  EdgeVector() : g(nullptr) { }
107 
108  EdgeVector(const Graph& _g) : std::vector<T>(_g.max_edge_index() + 1), g(&_g) { }
109 
110  EdgeVector(const Graph& _g, T& v)
111  : std::vector<T>(_g.max_edge_index() + 1, v), g(&_g), default_value(v) { }
112 
113  EdgeVector(const Graph& _g, T v)
114  : std::vector<T>(_g.max_edge_index() + 1, v), g(&_g), default_value(v) { }
115 
116  EdgeVector(const EdgeVector& x) : std::vector<T>(x), g(&x.g), default_value(x.default_value) { }
117 
119  : std::vector<T>(x), g(std::move(x.g)), default_value(x.default_value) { }
120 
121  inline void adapt() {
122  if (g && (std::size_t)g->max_edge_index() >= std::vector<T>::size()) {
123  std::vector<T>::resize(g->max_edge_index() + 1, default_value);
124  }
125  }
126 
128  adapt();
129  return std::vector<T>::operator[](e->index());
130  }
131 
132  const_reference operator[](const Edge& e) const {
133  OGDF_ASSERT((std::size_t)e->index() < this->size());
134  return std::vector<T>::operator[](e->index());
135  }
136 
138  std::vector<T>::operator=(x);
140  return *this;
141  }
142 
144  std::vector<T>::operator=(std::move(x));
145  default_value = x.default_value;
146  return *this;
147  }
148 };
149 
150 }
151 
152 }
153 }
154 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::internal::gcm::datastructure::NodeVector::operator=
NodeVector< T, Graph > & operator=(const NodeVector< T, Graph > &x)
Definition: OGDFVector.h:83
ogdf::internal::gcm::datastructure::NodeVector::reference
typename std::vector< T >::reference reference
Definition: OGDFVector.h:46
ogdf::internal::gcm::datastructure::EdgeVector::operator[]
reference operator[](const Edge &e)
Definition: OGDFVector.h:127
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:66
ogdf::internal::gcm::datastructure::EdgeVector::EdgeVector
EdgeVector(const Graph &_g)
Definition: OGDFVector.h:108
ogdf::internal::gcm::datastructure::NodeVector::const_reference
typename std::vector< T >::const_reference const_reference
Definition: OGDFVector.h:47
ogdf::internal::gcm::datastructure::NodeVector::operator[]
reference operator[](const Node &v)
Definition: OGDFVector.h:73
ogdf::internal::gcm::datastructure::NodeVector::Node
typename Graph::Node Node
Definition: OGDFVector.h:45
ogdf::internal::gcm::datastructure::NodeVector::adapt
void adapt()
Definition: OGDFVector.h:67
ogdf::internal::gcm::datastructure::NodeVector::NodeVector
NodeVector(const Graph &_g)
Definition: OGDFVector.h:56
ogdf::internal::gcm::datastructure::EdgeVector::EdgeVector
EdgeVector(const EdgeVector &x)
Definition: OGDFVector.h:116
ogdf::internal::gcm::datastructure::EdgeVector::adapt
void adapt()
Definition: OGDFVector.h:121
ogdf::internal::gcm::datastructure::EdgeVector::operator=
EdgeVector< T, Graph > & operator=(EdgeVector< T, Graph > &&x)
Definition: OGDFVector.h:143
backward::details::move
const T & move(const T &v)
Definition: backward.hpp:243
ogdf::internal::gcm::datastructure::NodeVector::NodeVector
NodeVector(const NodeVector< T, Graph > &x)
Definition: OGDFVector.h:64
ogdf::internal::gcm::datastructure::NodeVector::NodeVector
NodeVector()
Definition: OGDFVector.h:54
ogdf::internal::gcm::datastructure::EdgeVector::operator[]
const_reference operator[](const Edge &e) const
Definition: OGDFVector.h:132
ogdf::internal::gcm::datastructure::EdgeVector::EdgeVector
EdgeVector(const EdgeVector &&x)
Definition: OGDFVector.h:118
ogdf::internal::gcm::datastructure::EdgeVector::reference
typename std::vector< T >::reference reference
Definition: OGDFVector.h:100
ogdf::internal::gcm::datastructure::NodeVector::default_value
T default_value
Definition: OGDFVector.h:50
ogdf::internal::gcm::datastructure::NodeVector::g
const Graph * g
Definition: OGDFVector.h:49
ogdf::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:869
ogdf::internal::gcm::datastructure::NodeVector::operator=
NodeVector< T, Graph > & operator=(NodeVector< T, Graph > &&x)
Definition: OGDFVector.h:89
ogdf::internal::gcm::datastructure::EdgeVector::const_reference
typename std::vector< T >::const_reference const_reference
Definition: OGDFVector.h:101
ogdf::internal::gcm::datastructure::EdgeVector::default_value
T default_value
Definition: OGDFVector.h:103
ogdf::internal::gcm::datastructure::NodeVector::NodeVector
NodeVector(const Graph &_g, T v)
Definition: OGDFVector.h:61
ogdf::internal::gcm::datastructure::EdgeVector::EdgeVector
EdgeVector(const Graph &_g, T v)
Definition: OGDFVector.h:113
ogdf::internal::gcm::datastructure::EdgeVector
Definition: OGDFVector.h:97
std
Definition: GML.h:111
ogdf::internal::gcm::datastructure::EdgeVector::EdgeVector
EdgeVector()
Definition: OGDFVector.h:106
ogdf::internal::gcm::datastructure::NodeVector::operator[]
const_reference operator[](const Node &v) const
Definition: OGDFVector.h:78
ogdf::internal::gcm::datastructure::NodeVector
Definition: OGDFVector.h:43
ogdf::internal::gcm::datastructure::EdgeVector::operator=
EdgeVector< T, Graph > & operator=(const EdgeVector< T, Graph > &x)
Definition: OGDFVector.h:137
ogdf::internal::gcm::datastructure::EdgeVector::g
const Graph * g
Definition: OGDFVector.h:102
ogdf::internal::gcm::datastructure::EdgeVector::EdgeVector
EdgeVector(const Graph &_g, T &v)
Definition: OGDFVector.h:110
ogdf::internal::gcm::datastructure::EdgeVector::Edge
typename Graph::Edge Edge
Definition: OGDFVector.h:99
ogdf::internal::gcm::datastructure::NodeVector::NodeVector
NodeVector(const Graph &_g, T &v)
Definition: OGDFVector.h:58