|
4 | 4 |
|
5 | 5 | #pragma once |
6 | 6 |
|
| 7 | +#include "gl/attributes/diagnostics.hpp" |
7 | 8 | #include "gl/constants.hpp" |
8 | 9 | #include "gl/decl/impl_tags.hpp" |
9 | 10 | #include "gl/graph_traits.hpp" |
10 | 11 | #include "gl/types/core.hpp" |
11 | 12 |
|
12 | 13 | #include <algorithm> |
| 14 | +#include <cstddef> |
13 | 15 | #include <vector> |
14 | 16 |
|
15 | 17 | namespace gl::impl { |
@@ -76,19 +78,28 @@ struct directed_adjacency_matrix { |
76 | 78 | self._matrix.emplace_back(new_n_vertices, invalid_id); |
77 | 79 | } |
78 | 80 |
|
| 81 | + GL_SUPPRESS_WARNING_BEGIN("-Wsign-conversion") |
| 82 | + |
| 83 | + // NOTE: Indexing into a row which might be a vector (requires size type) or a span/subrange (requires difference type) |
| 84 | + |
79 | 85 | [[nodiscard]] gl_attr_force_inline static size_type in_degree( |
80 | 86 | const impl_type& self, id_type vertex_id |
81 | 87 | ) { |
82 | | - return std::ranges::count_if(self._matrix, [vertex_id](const auto& row) { |
83 | | - return row[to_idx(vertex_id)] != invalid_id; |
84 | | - }); |
| 88 | + return static_cast<size_type>(std::ranges::count_if( |
| 89 | + self._matrix, |
| 90 | + [vertex_id](const auto& row) { return row[to_idx(vertex_id)] != invalid_id; } |
| 91 | + )); |
85 | 92 | } |
86 | 93 |
|
| 94 | + GL_SUPPRESS_WARNING_END |
| 95 | + |
87 | 96 | [[nodiscard]] gl_attr_force_inline static size_type out_degree( |
88 | 97 | const impl_type& self, id_type vertex_id |
89 | 98 | ) { |
90 | 99 | return self._matrix[vertex_id].size() |
91 | | - - std::ranges::count(self._matrix[vertex_id], invalid_id_v<id_type>); |
| 100 | + - static_cast<size_type>( |
| 101 | + std::ranges::count(self._matrix[vertex_id], invalid_id_v<id_type>) |
| 102 | + ); |
92 | 103 | } |
93 | 104 |
|
94 | 105 | [[nodiscard]] gl_attr_force_inline static size_type degree( |
@@ -143,12 +154,12 @@ struct directed_adjacency_matrix { |
143 | 154 | | std::views::filter([](auto edge_id) { return edge_id != invalid_id; }) |
144 | 155 | | std::ranges::to<std::vector>(); |
145 | 156 |
|
146 | | - self._matrix.erase(std::next(std::begin(self._matrix), vertex_idx)); |
| 157 | + self._matrix.erase(self._matrix.begin() + static_cast<std::ptrdiff_t>(vertex_id)); |
147 | 158 |
|
148 | 159 | for (auto& row : self._matrix) { |
149 | 160 | if (const auto edge_id = row[vertex_idx]; edge_id != invalid_id) |
150 | 161 | removed_edges.push_back(edge_id); |
151 | | - row.erase(std::next(std::begin(row), vertex_idx)); |
| 162 | + row.erase(row.begin() + static_cast<std::ptrdiff_t>(vertex_id)); |
152 | 163 | } |
153 | 164 |
|
154 | 165 | return removed_edges; |
@@ -225,7 +236,9 @@ struct undirected_adjacency_matrix { |
225 | 236 | ) { |
226 | 237 | const auto vertex_idx = to_idx(vertex_id); |
227 | 238 | return self._matrix.size() |
228 | | - - std::ranges::count(self._matrix[vertex_idx], invalid_id_v<id_type>) |
| 239 | + - static_cast<size_type>( |
| 240 | + std::ranges::count(self._matrix[vertex_idx], invalid_id_v<id_type>) |
| 241 | + ) |
229 | 242 | + static_cast<size_type>(self._matrix[vertex_idx][vertex_idx] != invalid_id); |
230 | 243 | } |
231 | 244 |
|
@@ -264,9 +277,10 @@ struct undirected_adjacency_matrix { |
264 | 277 | | std::views::filter([](auto edge_id) { return edge_id != invalid_id; }) |
265 | 278 | | std::ranges::to<std::vector>(); |
266 | 279 |
|
267 | | - self._matrix.erase(std::next(std::begin(self._matrix), vertex_idx)); |
| 280 | + const auto vertex_pos = static_cast<std::ptrdiff_t>(vertex_id); |
| 281 | + self._matrix.erase(self._matrix.begin() + vertex_pos); |
268 | 282 | for (auto& row : self._matrix) |
269 | | - row.erase(std::next(std::begin(row), vertex_idx)); |
| 283 | + row.erase(row.begin() + vertex_pos); |
270 | 284 |
|
271 | 285 | return removed_edges; |
272 | 286 | } |
|
0 commit comments