Skip to content

Commit 53c8934

Browse files
committed
alignment (test tgt flags)
1 parent bc1141a commit 53c8934

21 files changed

Lines changed: 126 additions & 71 deletions

include/gl/graph.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class graph final {
212212
}
213213
}
214214

215-
gl_attr_force_inline void remove_vertex(const size_type vertex_id) {
215+
gl_attr_force_inline void remove_vertex(const id_type vertex_id) {
216216
this->_verify_vertex_id(vertex_id);
217217
this->_remove_vertex_impl(vertex_id);
218218
}

include/gl/impl/adjacency_list.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ class adjacency_list final {
297297
edge_item.edge_id = invalid_id; // edge was removed
298298
else
299299
// shift by the number of removed IDs < edge-id
300-
edge_item.edge_id -= std::ranges::distance(removed_edge_ids.begin(), it);
300+
edge_item.edge_id -= static_cast<id_type>(it - removed_edge_ids.begin());
301301

302302
// align the vertex id
303303
edge_item.vertex_id -= edge_item.vertex_id > removed_vertex_id;

include/gl/impl/adjacency_matrix.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,13 @@ class adjacency_matrix final {
197197
{
198198
return std::views::iota(initial_id_v<id_type>, this->_matrix.size())
199199
| std::views::filter([this, vertex_id](const auto source_id) {
200-
return this->_matrix[to_idx(source_id)][to_idx(vertex_id)] != invalid_id;
200+
return specialized_impl::get_edge_id(*this, source_id, vertex_id) != invalid_id;
201201
})
202202
| std::views::transform([this, vertex_id](const auto source_id) {
203203
return edge_type{
204-
this->_matrix[to_idx(source_id)][to_idx(vertex_id)], source_id, vertex_id
204+
specialized_impl::get_edge_id(*this, source_id, vertex_id),
205+
source_id,
206+
vertex_id
205207
};
206208
});
207209
}
@@ -213,10 +215,10 @@ class adjacency_matrix final {
213215
{
214216
return std::views::iota(initial_id_v<id_type>, this->_matrix.size())
215217
| std::views::filter([this, vertex_id](const auto source_id) {
216-
return this->_matrix[to_idx(source_id)][to_idx(vertex_id)] != invalid_id;
218+
return specialized_impl::get_edge_id(*this, source_id, vertex_id) != invalid_id;
217219
})
218220
| std::views::transform([this, vertex_id, &edge_properties_map](const auto source_id) {
219-
const auto edge_id = this->_matrix[to_idx(source_id)][to_idx(vertex_id)];
221+
const auto edge_id = specialized_impl::get_edge_id(*this, source_id, vertex_id);
220222
return edge_type{
221223
edge_id, source_id, vertex_id, *edge_properties_map[to_idx(edge_id)]
222224
};

include/gl/impl/specialized/adjacency_list.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ struct directed_adjacency_list {
150150
}
151151

152152
// remove the list of edges incident from the vertex entirely
153-
self._list.erase(std::next(std::begin(self._list), vertex_idx));
153+
self._list.erase(self._list.begin() + vertex_id);
154154
return removed_edges;
155155
}
156156

@@ -251,7 +251,7 @@ struct undirected_adjacency_list {
251251
const auto removed_edges =
252252
self._list[vertex_idx] | std::views::transform(&item_type::edge_id)
253253
| std::ranges::to<std::vector>();
254-
self._list.erase(std::next(std::begin(self._list), vertex_idx));
254+
self._list.erase(self._list.begin() + vertex_idx);
255255
return removed_edges;
256256
}
257257

include/gl/impl/specialized/adjacency_matrix.hpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ struct directed_adjacency_matrix {
8888
const impl_type& self, id_type vertex_id
8989
) {
9090
return self._matrix[vertex_id].size()
91-
- std::ranges::count(self._matrix[vertex_id], invalid_id_v<id_type>);
91+
- static_cast<size_type>(
92+
std::ranges::count(self._matrix[vertex_id], invalid_id_v<id_type>)
93+
);
9294
}
9395

9496
[[nodiscard]] gl_attr_force_inline static size_type degree(
@@ -154,6 +156,10 @@ struct directed_adjacency_matrix {
154156
return removed_edges;
155157
}
156158

159+
static id_type get_edge_id(const impl_type& self, id_type source_id, id_type target_id) {
160+
return self._matrix[to_idx(source_id)][to_idx(target_id)];
161+
}
162+
157163
static inline void add_edge(
158164
impl_type& self, id_type edge_id, id_type source_id, id_type target_id
159165
) {
@@ -271,6 +277,10 @@ struct undirected_adjacency_matrix {
271277
return removed_edges;
272278
}
273279

280+
static id_type get_edge_id(const impl_type& self, id_type source_id, id_type target_id) {
281+
return self._matrix[to_idx(source_id)][to_idx(target_id)];
282+
}
283+
274284
static void add_edge(impl_type& self, id_type edge_id, id_type source_id, id_type target_id) {
275285
detail::check_edge_override(self._matrix, source_id, target_id);
276286

include/gl/impl/specialized/flat_adjacency_list.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ struct directed_flat_adjacency_list {
4242
}
4343

4444
[[nodiscard]] static size_type in_degree(const impl_type& self, id_type vertex_id) {
45-
return std::ranges::count(self._list.data_view(), vertex_id, &item_type::vertex_id);
45+
return static_cast<size_type>(
46+
std::ranges::count(self._list.data_view(), vertex_id, &item_type::vertex_id)
47+
);
4648
}
4749

4850
[[nodiscard]] gl_attr_force_inline static size_type out_degree(

include/gl/impl/specialized/flat_adjacency_matrix.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ struct directed_flat_adjacency_matrix {
160160
return removed_edges;
161161
}
162162

163+
static id_type get_edge_id(const impl_type& self, id_type source_id, id_type target_id) {
164+
return self._matrix[to_idx(source_id), to_idx(target_id)];
165+
}
166+
163167
static inline void add_edge(
164168
impl_type& self, id_type edge_id, id_type source_id, id_type target_id
165169
) {
@@ -272,6 +276,10 @@ struct undirected_flat_adjacency_matrix {
272276
return removed_edges;
273277
}
274278

279+
static id_type get_edge_id(const impl_type& self, id_type source_id, id_type target_id) {
280+
return self._matrix[to_idx(source_id), to_idx(target_id)];
281+
}
282+
275283
static void add_edge(impl_type& self, id_type edge_id, id_type source_id, id_type target_id) {
276284
detail::check_edge_override(self._matrix, source_id, target_id);
277285

include/gl/topology/cycle.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ template <traits::c_graph GraphType>
1717
GraphType graph{n_vertices};
1818

1919
for (id_type source_id = initial_id; source_id < n_vertices; ++source_id)
20-
graph.add_edge(source_id, (source_id + 1uz) % n_vertices);
20+
graph.add_edge(source_id, static_cast<id_type>((source_id + 1uz) % n_vertices));
2121

2222
return graph;
2323
}
@@ -36,7 +36,7 @@ template <traits::c_graph GraphType>
3636
GraphType graph{n_vertices};
3737

3838
for (id_type source_id = initial_id; source_id < n_vertices; ++source_id) {
39-
const auto target_id = (source_id + 1uz) % n_vertices;
39+
const auto target_id = static_cast<id_type>((source_id + 1uz) % n_vertices);
4040
graph.add_edge(source_id, target_id);
4141
graph.add_edge(target_id, source_id);
4242
}

include/gl/types/flat_jagged_vector.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ class flat_jagged_vector {
10651065
/// position in the underlying vector, and $S$ is the number of segments after `seg`.
10661066
void erase(size_type seg, size_type pos) {
10671067
this->_data.erase(this->_data.begin() + this->_offsets[seg] + pos);
1068-
for (size_type i = seg + 1uz; i < this->_offsets.size(); i++)
1068+
for (auto i = seg + 1uz; i < this->_offsets.size(); i++)
10691069
this->_offsets[i]--;
10701070
}
10711071

tests/CMakeLists.txt

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,20 @@ function(add_test_target TARGET_NAME SOURCE_DIRS DATA_DIR TESTING_DEF)
2424
)
2525

2626
target_include_directories(${TARGET_NAME} PRIVATE ${INCLUDE_DIRS})
27-
# TODO: uncomment and align
28-
# target_compile_options(${TARGET_NAME} PRIVATE
29-
# -Werror
30-
# -Wall
31-
# -Wextra
32-
# -Wcast-align
33-
# -Wconversion
34-
# -Wsign-conversion
35-
# -Wunreachable-code
36-
# -Wuninitialized
37-
# -Wunused
38-
# -pedantic
39-
# -g
40-
# -O2
41-
# )
27+
# TODO: add -Wsign-conversion
28+
target_compile_options(${TARGET_NAME} PRIVATE
29+
-Werror
30+
-Wall
31+
-Wextra
32+
-Wcast-align
33+
-Wconversion
34+
-Wunreachable-code
35+
-Wuninitialized
36+
-Wunused
37+
-pedantic
38+
-g
39+
-O2
40+
)
4241
target_compile_definitions(${TARGET_NAME} PRIVATE
4342
${TESTING_DEF}
4443
TEST_DATA_PATH="${DATA_DIR}"

0 commit comments

Comments
 (0)