Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReverseView and UndirectedView #376

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

etiennedeg
Copy link
Member

No description provided.

Copy link

codecov bot commented May 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.35%. Comparing base (599ef81) to head (24f255b).
Report is 6 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #376      +/-   ##
==========================================
+ Coverage   97.27%   97.35%   +0.07%     
==========================================
  Files         118      121       +3     
  Lines        6874     6992     +118     
==========================================
+ Hits         6687     6807     +120     
+ Misses        187      185       -2     

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

@etiennedeg
Copy link
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
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
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
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
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!

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