Skip to content

ReverseView and UndirectedView#376

Merged
Krastanov merged 16 commits intoJuliaGraphs:masterfrom
etiennedeg:undirected_wrapper
Feb 21, 2026
Merged

ReverseView and UndirectedView#376
Krastanov merged 16 commits intoJuliaGraphs:masterfrom
etiennedeg:undirected_wrapper

Conversation

@etiennedeg
Copy link
Copy Markdown
Member

No description provided.

@codecov
Copy link
Copy Markdown

codecov bot commented May 8, 2024

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.30%. Comparing base (72bcb3b) to head (a009047).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #376      +/-   ##
==========================================
+ Coverage   97.26%   97.30%   +0.04%     
==========================================
  Files         122      123       +1     
  Lines        7340     7378      +38     
==========================================
+ Hits         7139     7179      +40     
+ Misses        201      199       -2     

☔ View full report in Codecov by Sentry.
📢 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.

@etiennedeg
Copy link
Copy Markdown
Member Author

@gdalle Should be good for review. Do you know what's wrong with the documentation?

Comment on lines +24 to +31
struct ReverseView{T<:Integer,G<:AbstractGraph} <: AbstractGraph{T}
g::G

@traitfn ReverseView{T,G}(g::::(IsDirected)) where {T<:Integer,G<:AbstractGraph{T}} =
new(g)
@traitfn ReverseView{T,G}(g::::(!IsDirected)) where {T<:Integer,G<:AbstractGraph{T}} =
throw(ArgumentError("Your graph needs to be directed"))
end
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it make more sense if this function works on all graphs? Even if it does nothing for undirected graphs.

1
```
"""
struct UndirectedView{T<:Integer,G<:AbstractGraph} <: AbstractGraph{T}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we distinguish between weak and strong connectivity? I.e. weaks means that v and w in the undirected view are connected if either v -> w or v <- w in the original graph. Strong means that v <-> w in the original graph.

"""
struct UndirectedView{T<:Integer,G<:AbstractGraph} <: AbstractGraph{T}
g::G
ne::Int
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Precalculating ne is a bit dangerous as one might change the underlying graph and then the view would be invalid. If we cache this value then we should be very clear about that in the documentation.

I think it might be worth not to cache it and then make sure that all our algorithms calculate ne only once.

@traitfn function UndirectedView{T,G}(
g::::(IsDirected)
) where {T<:Integer,G<:AbstractGraph{T}}
ne = count(e -> src(e) <= dst(e) || !has_edge(g, dst(e), src(e)), Graphs.edges(g))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ne = count(e -> src(e) <= dst(e) || !has_edge(g, dst(e), src(e)), Graphs.edges(g))
ne = count(e -> src(e) <= dst(e) && src(e) <= dst(e), Graphs.edges(g))

This way we can avoid the expensive call to has_edge!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be checking the same thing twice?

Krastanov and others added 2 commits February 21, 2026 01:35
Krastanov and others added 2 commits February 21, 2026 01:57
…underlying graph

UndirectedView caches the number of edges at construction time, and
ReverseView forwards properties from the underlying graph. In both
cases, modifying the underlying graph after constructing the view can
lead to incorrect results.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Krastanov
Copy link
Copy Markdown
Member

There are a number of functionality and performance improvements left suggested in the review, but all documentation and correctness comments are now addressed. I will proceed with merging this. Future PRs can address the missing features and improve performance.

@Krastanov Krastanov merged commit 496c4b6 into JuliaGraphs:master Feb 21, 2026
11 of 14 checks passed
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.

4 participants