-
Notifications
You must be signed in to change notification settings - Fork 93
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
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
@gdalle Should be good for review. Do you know what's wrong with the documentation? |
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 |
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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!
No description provided.