Skip to content

Implement the edges iterator - #35

Closed
singhharsh1708 wants to merge 2 commits into
JuliaGraphs:masterfrom
singhharsh1708:feat/edges
Closed

singhharsh1708 wants to merge 2 commits into
JuliaGraphs:masterfrom
singhharsh1708:feat/edges

Conversation

@singhharsh1708

@singhharsh1708 singhharsh1708 commented Sep 7, 2026 •

Copy link
Copy Markdown

Fills in the last Graphs.edges TODO, so the AbstractGraph interface on VNGraph is complete. edges(g) returns a lazy iterator yielding each edge once in lexicographic order, matching edges(SimpleGraph(g)) edge for edge.

The inherited SimpleEdgeIter cannot be used: it reaches for fadj(g, u), which resolves to g.fadjlist and does not exist on a VNGraph, and it has no eltype method for anything but SimpleGraph and SimpleDiGraph. Defining fadj over the C array would be worse than an error, since very_nauty stores adjacency unsorted and SimpleEdgeIter calls searchsortedfirst on it, so it would silently return the wrong edge set.

A self loop is stored twice in the vertex's own adjacency list while nedges counts it once. #34 collapses that repeat in outneighbors, so the iterator yields it once and length(edges(g)) == ne(g) stays exact.

One pre-existing inconsistency, deliberately not touched here: SimpleGraph(::VNGraph) converts with a strict i < j test, so it drops self loops. On a graph with a self loop, ne(g) and edges(g) count it but the converted SimpleGraph does not. Making those agree means deciding whether this wrapper admits self loops at all, which is your call rather than a side effect of this PR.

Verified against the SimpleGraph conversion on 20 random regular graphs, checking the full edge sequence, lexicographic order and length == ne, plus element type, the empty and edgeless graphs, duplicate adds, the self loop and in: 908 passing. Reverting the iterator makes the test error on its first collect.

Part of JuliaGraphs/Graphs.jl#448, stacked on #34; commit 7d5155e is the one belonging to this PR.

AI Disclosure: Claude assisted with the code. Testing and review by @singhharsh1708.

@codecov

codecov Bot commented Sep 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.18%. Comparing base (0fa35cb) to head (7d5155e).

Additional details and impacted files
@@             Coverage Diff             @@
##           master      #35       +/-   ##
===========================================
+ Coverage   45.90%   68.18%   +22.28%     
===========================================
  Files           1        1               
  Lines          61       88       +27     
===========================================
+ Hits           28       60       +32     
+ Misses         33       28        -5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@singhharsh1708

singhharsh1708 commented Sep 7, 2026 •

Copy link
Copy Markdown
Author

#14 carries an edges too: eager, in stored rather than lexicographic order, and dropping self loops through a strict i < j, so its length runs short of ne. This one is lazy and lexicographic and yields a self loop once. Which self-loop convention the wrapper should adopt is the open question in the description.

@Krastanov

Copy link
Copy Markdown
Member

LLM work from new contributors is not acceptable for bounties

@Krastanov Krastanov closed this Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants