Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

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