Skip to content

Commit c9e6776

Browse files
committed
I think the edge ids improvement won't work
It would require aligning all edge ids after removing a single edge, which is fine, but it would also require aligning all edge ids after removing a vertex, and this operation might remove multiple edges at once and the logic of aligning the edge ids in that situation would be too complex to spend any more time on this now, while the hypergraph module implementation is the main focuse of the 2.0.0 release of the library...
1 parent 192cd2a commit c9e6776

6 files changed

Lines changed: 337 additions & 334 deletions

File tree

include/gl/edge_descriptor.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class edge_descriptor final {
5151

5252
// TODO: add tests
5353
[[nodiscard]] bool operator==(const edge_descriptor& other) const noexcept {
54-
return this->_id == other._id and this->_vertices == other._vertices;
54+
return this->_id == other._id; // compare vertices ?
5555
}
5656

5757
[[nodiscard]] constexpr bool is_directed() const noexcept {

include/gl/impl/specialized/adjacency_list.hpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,7 @@ template <type_traits::c_instantiation_of<adjacency_list> AdjacencyList>
190190
requires(type_traits::is_undirected_v<typename AdjacencyList::edge_type>)
191191
struct undirected_adjacency_list {
192192
using impl_type = AdjacencyList;
193-
using vertex_type = typename impl_type::vertex_type;
194193
using edge_type = typename impl_type::edge_type;
195-
using edge_ptr_type = typename impl_type::edge_ptr_type;
196-
using edge_list_type = typename impl_type::edge_list_type;
197194

198195
[[nodiscard]] gl_attr_force_inline static types::size_type in_degree(
199196
const impl_type& self, const types::id_type vertex_id
@@ -237,19 +234,16 @@ struct undirected_adjacency_list {
237234
}
238235

239236
template <bool GetRemovedEdgeIds>
240-
static auto remove_vertex(impl_type& self, const types::id_type vertex_id)
241-
requires(GetRemovedEdgeIds)
242-
{
237+
static auto remove_vertex(impl_type& self, const types::id_type vertex_id) {
243238
// remove all edges incident with the vertex (scan only the selected vertices)
244239
for (const auto& item : self._list[vertex_id]) {
245240
if (item.target_id == vertex_id)
246241
continue; // will be removed with the vertex's list
247242

248243
auto& adj_edges = self._list[item.target_id];
249-
const auto removed_subrng =
250-
std::ranges::remove_if(adj_edges, [vertex_id](const auto& edge) {
251-
return edge->is_incident_with(vertex_id);
252-
});
244+
const auto removed_subrng = std::ranges::remove_if(
245+
adj_edges, [vertex_id](const auto& item) { return item.target_id == vertex_id; }
246+
);
253247
adj_edges.erase(removed_subrng.begin(), removed_subrng.end());
254248
}
255249

@@ -270,8 +264,8 @@ struct undirected_adjacency_list {
270264
impl_type& self, types::id_type edge_id, types::id_type source_id, types::id_type target_id
271265
) {
272266
self._list[source_id].emplace_back(edge_id, target_id);
273-
if (source_id != target_id)
274-
self._list[target_id].push_back(edge_id, source_id);
267+
if (target_id != source_id)
268+
self._list[target_id].emplace_back(edge_id, source_id);
275269
}
276270

277271
static void add_edges_from(

tests/include/testing/gl/transforms.hpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@
66

77
namespace gl_testing::transforms {
88

9-
// TODO: replace with generic get_id
10-
template <
11-
gl::type_traits::c_instantiation_of<gl::vertex_descriptor> VertexType = gl::vertex_descriptor<>>
12-
inline gl::types::id_type extract_vertex_id(const VertexType& vertex) {
13-
return vertex.id();
9+
inline gl::types::id_type get_id(auto&& element) {
10+
return element.id();
1411
}
1512

1613
// TODO: remove

0 commit comments

Comments
 (0)