Skip to content

Commit 20be565

Browse files
committed
revised bounds checking
1 parent e8b06c3 commit 20be565

2 files changed

Lines changed: 34 additions & 36 deletions

File tree

include/osp/graph_implementations/adj_list_impl/computational_dag_vector_impl.hpp

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ namespace osp {
3232
* @brief A vector-based implementation of a computational DAG.
3333
*
3434
* This class implements a computational DAG using adjacency lists stored in two std::vectors.
35-
* It manages the storage of vertices and edges, and provides an interface to query and modify the graph.
36-
*
35+
* It manages the storage of vertices and edges, and provides an interface to query and modify the graph.
36+
*
3737
* This class satisfies the following concepts:
3838
* - `is_computational_dag_typed_vertices`
3939
* - `is_directed_graph`
@@ -80,7 +80,7 @@ class computational_dag_vector_impl {
8080
num_vertex_types_(0) {
8181

8282
for (vertex_idx i = 0; i < num_vertices; ++i) {
83-
vertices_.at(i).id = i;
83+
vertices_[i].id = i;
8484
}
8585
}
8686

@@ -150,40 +150,40 @@ class computational_dag_vector_impl {
150150
[[nodiscard]] vertex_idx num_edges() const { return num_edges_; }
151151

152152
/**
153-
* @brief Returns the parents (in-neighbors) of a vertex.
153+
* @brief Returns the parents (in-neighbors) of a vertex. Does not perform bounds checking.
154154
* @param v The vertex index.
155155
*/
156-
[[nodiscard]] const std::vector<vertex_idx> &parents(const vertex_idx v) const { return in_neigbors.at(v); }
156+
[[nodiscard]] const std::vector<vertex_idx> &parents(const vertex_idx v) const { return in_neigbors[v]; }
157157

158158
/**
159-
* @brief Returns the children (out-neighbors) of a vertex.
159+
* @brief Returns the children (out-neighbors) of a vertex. Does not perform bounds checking.
160160
* @param v The vertex index.
161161
*/
162-
[[nodiscard]] const std::vector<vertex_idx> &children(const vertex_idx v) const { return out_neigbors.at(v); }
162+
[[nodiscard]] const std::vector<vertex_idx> &children(const vertex_idx v) const { return out_neigbors[v]; }
163163

164164
/**
165-
* @brief Returns the in-degree of a vertex.
165+
* @brief Returns the in-degree of a vertex. Does not perform bounds checking.
166166
* @param v The vertex index.
167167
*/
168-
[[nodiscard]] vertex_idx in_degree(const vertex_idx v) const { return static_cast<vertex_idx>(in_neigbors.at(v).size()); }
168+
[[nodiscard]] vertex_idx in_degree(const vertex_idx v) const { return static_cast<vertex_idx>(in_neigbors[v].size()); }
169169

170170
/**
171-
* @brief Returns the out-degree of a vertex.
171+
* @brief Returns the out-degree of a vertex. Does not perform bounds checking.
172172
* @param v The vertex index.
173173
*/
174-
[[nodiscard]] vertex_idx out_degree(const vertex_idx v) const { return static_cast<vertex_idx>(out_neigbors.at(v).size()); }
174+
[[nodiscard]] vertex_idx out_degree(const vertex_idx v) const { return static_cast<vertex_idx>(out_neigbors[v].size()); }
175175

176-
[[nodiscard]] vertex_work_weight_type vertex_work_weight(const vertex_idx v) const { return vertices_.at(v).work_weight; }
176+
[[nodiscard]] vertex_work_weight_type vertex_work_weight(const vertex_idx v) const { return vertices_[v].work_weight; }
177177

178-
[[nodiscard]] vertex_comm_weight_type vertex_comm_weight(const vertex_idx v) const { return vertices_.at(v).comm_weight; }
178+
[[nodiscard]] vertex_comm_weight_type vertex_comm_weight(const vertex_idx v) const { return vertices_[v].comm_weight; }
179179

180-
[[nodiscard]] vertex_mem_weight_type vertex_mem_weight(const vertex_idx v) const { return vertices_.at(v).mem_weight; }
180+
[[nodiscard]] vertex_mem_weight_type vertex_mem_weight(const vertex_idx v) const { return vertices_[v].mem_weight; }
181181

182-
[[nodiscard]] vertex_type_type vertex_type(const vertex_idx v) const { return vertices_.at(v).vertex_type; }
182+
[[nodiscard]] vertex_type_type vertex_type(const vertex_idx v) const { return vertices_[v].vertex_type; }
183183

184184
[[nodiscard]] vertex_type_type num_vertex_types() const { return num_vertex_types_; }
185185

186-
[[nodiscard]] const v_impl &get_vertex_impl(const vertex_idx v) const { return vertices_.at(v); }
186+
[[nodiscard]] const v_impl &get_vertex_impl(const vertex_idx v) const { return vertices_[v]; }
187187

188188
/**
189189
* @brief Adds a new isolated vertex to the graph.
@@ -240,7 +240,7 @@ class computational_dag_vector_impl {
240240
return false;
241241
}
242242

243-
out_neigbors.at(source).push_back(target);
243+
out_neigbors[source].push_back(target);
244244
in_neigbors.at(target).push_back(source);
245245
num_edges_++;
246246

@@ -267,7 +267,6 @@ using computational_dag_vector_impl_def_t = computational_dag_vector_impl<cdag_v
267267
*/
268268
using computational_dag_vector_impl_def_int_t = computational_dag_vector_impl<cdag_vertex_impl_int>;
269269

270-
271270
static_assert(is_directed_graph_edge_desc_v<computational_dag_vector_impl<cdag_vertex_impl_unsigned>>,
272271
"computational_dag_vector_impl must satisfy the directed_graph_edge_desc concept");
273272

include/osp/graph_implementations/adj_list_impl/dag_vector_adapter.hpp

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ class dag_vector_adapter {
8080
dag_vector_adapter(const std::vector<std::vector<index_t>> &out_neigbors_,
8181
const std::vector<std::vector<index_t>> &in_neigbors_) : vertices_(out_neigbors_.size()), out_neigbors(&out_neigbors_), in_neigbors(&in_neigbors_), num_edges_(0), num_vertex_types_(1) {
8282
for (vertex_idx i = 0; i < static_cast<vertex_idx>(out_neigbors_.size()); ++i) {
83-
vertices_.at(i).id = i;
84-
num_edges_ += out_neigbors_.at(i).size();
83+
vertices_[i].id = i;
84+
num_edges_ += out_neigbors_[i].size();
8585
}
8686
}
8787

@@ -107,8 +107,8 @@ class dag_vector_adapter {
107107

108108
num_edges_ = 0;
109109
for (vertex_idx i = 0; i < static_cast<vertex_idx>(out_neigbors->size()); ++i) {
110-
vertices_.at(i).id = i;
111-
num_edges_ += out_neigbors->at(i).size();
110+
vertices_[i].id = i;
111+
num_edges_ += out_neigbors_[i].size();
112112
}
113113

114114
num_vertex_types_ = 1;
@@ -130,40 +130,40 @@ class dag_vector_adapter {
130130
[[nodiscard]] vertex_idx num_edges() const { return static_cast<vertex_idx>(num_edges_); }
131131

132132
/**
133-
* @brief Returns a view of the parents (in-neighbors) of a vertex.
133+
* @brief Returns a view of the parents (in-neighbors) of a vertex. Does not perform bounds checking.
134134
* @param v The vertex index.
135135
*/
136-
[[nodiscard]] auto parents(const vertex_idx v) const { return vector_cast_view<index_t, vertex_idx>(in_neigbors->at(v)); }
136+
[[nodiscard]] auto parents(const vertex_idx v) const { return vector_cast_view<index_t, vertex_idx>(in_neigbors_[v]); }
137137

138138
/**
139-
* @brief Returns a view of the children (out-neighbors) of a vertex.
139+
* @brief Returns a view of the children (out-neighbors) of a vertex. Does not perform bounds checking.
140140
* @param v The vertex index.
141141
*/
142-
[[nodiscard]] auto children(const vertex_idx v) const { return vector_cast_view<index_t, vertex_idx>(out_neigbors->at(v)); }
142+
[[nodiscard]] auto children(const vertex_idx v) const { return vector_cast_view<index_t, vertex_idx>(out_neigbors_[v]); }
143143

144144
/**
145-
* @brief Returns the in-degree of a vertex.
145+
* @brief Returns the in-degree of a vertex. Does not perform bounds checking.
146146
* @param v The vertex index.
147147
*/
148-
[[nodiscard]] vertex_idx in_degree(const vertex_idx v) const { return static_cast<vertex_idx>(in_neigbors->at(v).size()); }
148+
[[nodiscard]] vertex_idx in_degree(const vertex_idx v) const { return static_cast<vertex_idx>(in_neigbors_[v].size()); }
149149

150150
/**
151-
* @brief Returns the out-degree of a vertex.
151+
* @brief Returns the out-degree of a vertex. Does not perform bounds checking.
152152
* @param v The vertex index.
153153
*/
154-
[[nodiscard]] vertex_idx out_degree(const vertex_idx v) const { return static_cast<vertex_idx>(out_neigbors->at(v).size()); }
154+
[[nodiscard]] vertex_idx out_degree(const vertex_idx v) const { return static_cast<vertex_idx>(out_neigbors_[v].size()); }
155155

156-
[[nodiscard]] vertex_work_weight_type vertex_work_weight(const vertex_idx v) const { return vertices_.at(v).work_weight; }
156+
[[nodiscard]] vertex_work_weight_type vertex_work_weight(const vertex_idx v) const { return vertices_[v].work_weight; }
157157

158-
[[nodiscard]] vertex_comm_weight_type vertex_comm_weight(const vertex_idx v) const { return vertices_.at(v).comm_weight; }
158+
[[nodiscard]] vertex_comm_weight_type vertex_comm_weight(const vertex_idx v) const { return vertices_[v].comm_weight; }
159159

160-
[[nodiscard]] vertex_mem_weight_type vertex_mem_weight(const vertex_idx v) const { return vertices_.at(v).mem_weight; }
160+
[[nodiscard]] vertex_mem_weight_type vertex_mem_weight(const vertex_idx v) const { return vertices_[v].mem_weight; }
161161

162-
[[nodiscard]] vertex_type_type vertex_type(const vertex_idx v) const { return vertices_.at(v).vertex_type; }
162+
[[nodiscard]] vertex_type_type vertex_type(const vertex_idx v) const { return vertices_[v].vertex_type; }
163163

164164
[[nodiscard]] vertex_type_type num_vertex_types() const { return num_vertex_types_; }
165165

166-
[[nodiscard]] const v_impl &get_vertex_impl(const vertex_idx v) const { return vertices_.at(v); }
166+
[[nodiscard]] const v_impl &get_vertex_impl(const vertex_idx v) const { return vertices_[v]; }
167167

168168
void set_vertex_work_weight(const vertex_idx v, const vertex_work_weight_type work_weight) {
169169
vertices_.at(v).work_weight = work_weight;
@@ -192,7 +192,6 @@ class dag_vector_adapter {
192192
unsigned num_vertex_types_ = 0;
193193
};
194194

195-
196195
static_assert(is_directed_graph_edge_desc_v<dag_vector_adapter<cdag_vertex_impl_unsigned, int>>,
197196
"dag_vector_adapter must satisfy the directed_graph_edge_desc concept");
198197

0 commit comments

Comments
 (0)