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

Commit

Permalink
first cut
Browse files Browse the repository at this point in the history
  • Loading branch information
sbromberger committed Feb 20, 2018
1 parent 73f0957 commit ffd3d7f
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion REQUIRE
@@ -1,4 +1,4 @@
julia 0.6
julia 0.7-
CodecZlib 0.4
DataStructures 0.7
SimpleTraits 0.4.0
2 changes: 2 additions & 0 deletions src/LightGraphs.jl
@@ -1,6 +1,8 @@
__precompile__(true)
module LightGraphs

using SharedArrays
using Random
import CodecZlib
using DataStructures
using SimpleTraits
Expand Down
2 changes: 1 addition & 1 deletion src/community/cliques.jl
Expand Up @@ -24,7 +24,7 @@ julia> maximal_cliques(g)
"""
function maximal_cliques end
# see https://github.com/mauro3/SimpleTraits.jl/issues/47#issuecomment-327880153 for syntax
@traitfn function maximal_cliques{T, AG<:AbstractGraph{T}}(g::AG::(!IsDirected))
@traitfn function maximal_cliques(g::AG::(!IsDirected)) where {T, AG<:AbstractGraph{T}}
# Cache nbrs and find first pivot (highest degree)
maxconn = -1
# uncomment this when https://github.com/JuliaLang/julia/issues/23618 is fixed
Expand Down
4 changes: 2 additions & 2 deletions src/digraph/cycles/hadwick-james.jl
Expand Up @@ -9,7 +9,7 @@ of Hadwick & James.
"""
function simplecycles_hadwick_james end
# see https://github.com/mauro3/SimpleTraits.jl/issues/47#issuecomment-327880153 for syntax
@traitfn function simplecycles_hadwick_james{T, AG<:AbstractGraph{T}}(g::AG::IsDirected)
@traitfn function simplecycles_hadwick_james(g::AG::IsDirected) where {T, AG<:AbstractGraph{T}}
nvg = nv(g)
B = Vector{T}[Vector{T}() for i in vertices(g)]
blocked = zeros(Bool, nvg)
Expand Down Expand Up @@ -43,7 +43,7 @@ resetblocked!(blocked) = fill!(blocked, false)
Find circuits in `g` recursively starting from v1.
"""
function circuit_recursive! end
@traitfn function circuit_recursive!{T<:Integer}(g::::IsDirected, v1::T, v2::T, blocked::AbstractVector, B::Vector{Vector{T}}, stack::Vector{T}, cycles::Vector{Vector{T}})
@traitfn function circuit_recursive!(g::::IsDirected, v1::T, v2::T, blocked::AbstractVector, B::Vector{Vector{T}}, stack::Vector{T}, cycles::Vector{Vector{T}}) where T<:Integer
f = false
push!(stack, v2)
blocked[v2] = true
Expand Down
8 changes: 4 additions & 4 deletions src/digraph/cycles/johnson.jl
Expand Up @@ -127,8 +127,8 @@ recursive version. Modify the vector of cycles, when needed.
- [Johnson](http://epubs.siam.org/doi/abs/10.1137/0204007)
"""
function circuit end
@traitfn function circuit{T<:Integer}(v::T, dg::::IsDirected, vis::JohnsonVisitor{T},
allcycles::Vector{Vector{T}}, vmap::Vector{T}, startnode::T = v)
@traitfn function circuit(v::T, dg::::IsDirected, vis::JohnsonVisitor{T},
allcycles::Vector{Vector{T}}, vmap::Vector{T}, startnode::T = v) where T<:Integer
done = false
push!(vis.stack, v)
vis.blocked[v] = true
Expand Down Expand Up @@ -215,8 +215,8 @@ the same as v, otherwise it should be passed.
- [Johnson](http://epubs.siam.org/doi/abs/10.1137/0204007)
"""
function circuit_iter end
@traitfn function circuit_iter{T<:Integer}(v::T, dg::::IsDirected, vis::JohnsonVisitor{T},
vmap::Vector{T}, cycle::Channel, startnode::T = v)
@traitfn function circuit_iter(v::T, dg::::IsDirected, vis::JohnsonVisitor{T},
vmap::Vector{T}, cycle::Channel, startnode::T = v) where T<:Integer
done = false
push!(vis.stack, v)
vis.blocked[v] = true
Expand Down
4 changes: 2 additions & 2 deletions src/linalg/spectral.jl
Expand Up @@ -179,7 +179,7 @@ If `k` is ommitted, uses full spectrum.
function spectral_distance end

# can't use Traitor syntax here (https://github.com/mauro3/SimpleTraits.jl/issues/36)
@traitfn function spectral_distance{G<:AbstractGraph; !IsDirected{G}}(G₁::G, G₂::G, k::Integer)
@traitfn function spectral_distance(G₁::G, G₂::G, k::Integer) where {G<:AbstractGraph; !IsDirected{G}}
A₁ = adjacency_matrix(G₁)
A₂ = adjacency_matrix(G₂)

Expand All @@ -190,7 +190,7 @@ function spectral_distance end
end

# can't use Traitor syntax here (https://github.com/mauro3/SimpleTraits.jl/issues/36)
@traitfn function spectral_distance{G<:AbstractGraph; !IsDirected{G}}(G₁::G, G₂::G)
@traitfn function spectral_distance(G₁::G, G₂::G) where {G<:AbstractGraph; !IsDirected{G}}
nv(G₁) == nv(G₂) || throw(ArgumentError("Spectral distance not defined for |G₁| != |G₂|"))
return spectral_distance(G₁, G₂, nv(G₁))
end
2 changes: 1 addition & 1 deletion src/operators.jl
Expand Up @@ -211,7 +211,7 @@ in the generated graph exceeds the eltype.
"""
function crosspath end
# see https://github.com/mauro3/SimpleTraits.jl/issues/47#issuecomment-327880153 for syntax
@traitfn function crosspath{T, AG<:AbstractGraph{T}}(len::Integer, g::AG::(!IsDirected))
@traitfn function crosspath(len::Integer, g::AG::(!IsDirected)) where {T, AG<:AbstractGraph{T}}
p = PathGraph(len)
h = Graph{T}(p)
return cartesian_product(h, g)
Expand Down
4 changes: 2 additions & 2 deletions src/spanningtrees/kruskal.jl
Expand Up @@ -40,10 +40,10 @@ distance matrix `distmx` using [Kruskal's algorithm](https://en.wikipedia.org/wi
"""
function kruskal_mst end
# see https://github.com/mauro3/SimpleTraits.jl/issues/47#issuecomment-327880153 for syntax
@traitfn function kruskal_mst{T<:Real, U, AG<:AbstractGraph{U}}(
@traitfn function kruskal_mst(
g::AG::(!IsDirected),
distmx::AbstractMatrix{T} = weights(g)
)
) where {T<:Real, U, AG<:AbstractGraph{U}}

edge_list = Vector{KruskalHeapEntry{T}}()
mst = Vector{Edge}()
Expand Down
4 changes: 2 additions & 2 deletions src/spanningtrees/prim.jl
Expand Up @@ -13,10 +13,10 @@ distance matrix `distmx` using [Prim's algorithm](https://en.wikipedia.org/wiki/
Return a vector of edges.
"""
function prim_mst end
@traitfn function prim_mst{T<:Real, U, AG<:AbstractGraph{U}}(
@traitfn function prim_mst(
g::AG::(!IsDirected),
distmx::AbstractMatrix{T} = weights(g)
)
) where {T<:Real, U, AG<:AbstractGraph{U}}
pq = Vector{PrimHeapEntry{T}}()
mst = Vector{Edge}()
marked = zeros(Bool, nv(g))
Expand Down
4 changes: 2 additions & 2 deletions src/traversals/dfs.jl
Expand Up @@ -12,7 +12,7 @@ Uses DFS.
function is_cyclic end
@traitfn is_cyclic(g::::(!IsDirected)) = ne(g) > 0
# see https://github.com/mauro3/SimpleTraits.jl/issues/47#issuecomment-327880153 for syntax
@traitfn function is_cyclic{T,AG<:AbstractGraph{T}}(g::AG::IsDirected)
@traitfn function is_cyclic(g::AG::IsDirected) where {T, AG<:AbstractGraph{T}}
vcolor = zeros(UInt8, nv(g))
for v in vertices(g)
vcolor[v] != 0 && continue
Expand Down Expand Up @@ -50,7 +50,7 @@ graph `g` as a vector of vertices in topological order.
"""
function toplogical_sort_by_dfs end
# see https://github.com/mauro3/SimpleTraits.jl/issues/47#issuecomment-327880153 for syntax
@traitfn function topological_sort_by_dfs{T, AG<:AbstractGraph{T}}(g::AG::IsDirected)
@traitfn function topological_sort_by_dfs(g::AG::IsDirected) where {T, AG<:AbstractGraph{T}}
vcolor = zeros(UInt8, nv(g))
verts = Vector{T}()
for v in vertices(g)
Expand Down
4 changes: 2 additions & 2 deletions src/traversals/randomwalks.jl
Expand Up @@ -29,7 +29,7 @@ vector of vertices visited in order.
"""
function non_backtracking_randomwalk end
# see https://github.com/mauro3/SimpleTraits.jl/issues/47#issuecomment-327880153 for syntax
@traitfn function non_backtracking_randomwalk{T, AG<:AbstractGraph{T}}(g::AG::(!IsDirected), s::Integer, niter::Integer)
@traitfn function non_backtracking_randomwalk(g::AG::(!IsDirected), s::Integer, niter::Integer) where {T, AG<:AbstractGraph{T}}
s in vertices(g) || throw(BoundsError())
visited = Vector{T}()
sizehint!(visited, niter)
Expand Down Expand Up @@ -61,7 +61,7 @@ function non_backtracking_randomwalk end
end

# see https://github.com/mauro3/SimpleTraits.jl/issues/47#issuecomment-327880153 for syntax
@traitfn function non_backtracking_randomwalk{T, AG<:AbstractGraph{T}}(g::AG::IsDirected, s::Integer, niter::Integer)
@traitfn function non_backtracking_randomwalk(g::AG::IsDirected, s::Integer, niter::Integer) where {T, AG<:AbstractGraph{T}}
s in vertices(g) || throw(BoundsError())
visited = Vector{T}()
sizehint!(visited, niter)
Expand Down

0 comments on commit ffd3d7f

Please sign in to comment.