Skip to content

Commit 6d88a59

Browse files
committed
Fix self-loop infinite iteration with cycle detection in iterator
- Add cycle detection in ual_vertex_edge_list::const_iterator::advance() - Remember starting edge and detect when iteration cycles back - Set edge_ to nullptr when cycle detected (end-of-iteration) - Enable self-loop test (remove [.][broken] tags) - Phase 4.3 now complete: 5/5 tests passing (482 assertions) - All tests pass: 3827 test cases, 35826 assertions (100%)
1 parent d1d73f5 commit 6d88a59

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

include/graph/container/detail/undirected_adjacency_list_impl.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ template <typename VV,
100100
class VContainer,
101101
typename Alloc>
102102
void ual_vertex_edge_list<VV, EV, GV, KeyT, VContainer, Alloc>::const_iterator::advance() {
103+
edge_type* start_edge = edge_; // Remember where we started for cycle detection
104+
103105
vertex_edge_list_inward_link_type& inward_link = *edge_; // in.vertex_key_ == this->vertex_key_;
104106
vertex_edge_list_outward_link_type& outward_link = *edge_;
105107
if (inward_link.vertex_key_ == vertex_key_) {
@@ -108,6 +110,11 @@ void ual_vertex_edge_list<VV, EV, GV, KeyT, VContainer, Alloc>::const_iterator::
108110
assert(outward_link.vertex_key_ == vertex_key_);
109111
edge_ = outward_link.next_;
110112
}
113+
114+
// Self-loop detection: if we've cycled back to the starting edge, treat as end
115+
if (edge_ == start_edge) {
116+
edge_ = nullptr;
117+
}
111118
}
112119

113120
template <typename VV,

tests/test_undirected_adjlist_edge_cases.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ using std::set;
1212
// Phase 4.3: Edge Cases and Stress Tests
1313
// =============================================================================
1414

15-
TEST_CASE("self-loops behavior", "[.][edge_cases][self_loop][broken]") {
15+
TEST_CASE("self-loops behavior", "[edge_cases][self_loop]") {
1616
// NOTE: Self-loops currently cause infinite loops during iteration
1717
// This is a known bug that needs fixing in the link/unlink logic
1818
// Using [.] tag to hide from default test runs

0 commit comments

Comments
 (0)