Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

take advantage of short circuiting any()/all() in is_bipartite() #106

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ producing a graph like this:
![Wheel Graph](https://cloud.githubusercontent.com/assets/941359/8960521/35582c1e-35c5-11e5-82d7-cd641dff424c.png)

###[TikzGraphs.jl](https://github.com/sisl/TikzGraphs.jl)
Another nice graph visulaization package. ([TikzPictures.jl](https://github.com/sisl/TikzPictures.jl)
Another nice graph visualization package. ([TikzPictures.jl](https://github.com/sisl/TikzPictures.jl)
required to render/save):
```julia
julia> g = WheelGraph(10); t = plot(g)
Expand Down
16 changes: 10 additions & 6 deletions src/traversals/bfs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,16 @@ function is_bipartite(g::SimpleGraph, s::Int)
return visitor.is_bipartite
end

function is_bipartite(g::SimpleGraph)
nvg = nv(g)
for v in vertices(g)
if !is_bipartite(g, v)
return false
# take advantage of short-circuiting all() in 0.4.0-dev+6371 and later
if VERSION >= v"0.4.0-dev+6371"
is_bipartite(g::SimpleGraph) = all(x->is_bipartite(g,x), vertices(g))
else
function is_bipartite(g::SimpleGraph)
for v in vertices(g)
if !is_bipartite(g, v)
return false
end
end
return true
end
return true
end