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

Static Graphs issue #8 #12

Merged
merged 1 commit into from
Aug 18, 2018
Merged
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
11 changes: 6 additions & 5 deletions src/StaticGraphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Base:
import LightGraphs:
_NI, _insert_and_dedup!, AbstractEdge, AbstractEdgeIter,
src, dst, edgetype, nv, ne, vertices, edges, is_directed,
has_vertex, has_edge, in_neighbors, out_neighbors,
has_vertex, has_edge, inneighbors, outneighbors,
indegree, outdegree, degree, insorted, squash,

AbstractGraphFormat, loadgraph, savegraph
Expand Down Expand Up @@ -75,17 +75,16 @@ end
nv(g::AbstractStaticGraph{T, U}) where T where U = T(length(g.f_ind) - 1)
vertices(g::AbstractStaticGraph{T, U}) where T where U = one(T):nv(g)


has_edge(g::AbstractStaticGraph, e::AbstractStaticEdge) =
insorted(dst(e), out_neighbors(g, src(e)))
insorted(dst(e), outneighbors(g, src(e)))

edgetype(g::AbstractStaticGraph{T}) where T = StaticEdge{T}
edges(g::AbstractStaticGraph) = StaticEdgeIter(g)

has_vertex(g::AbstractStaticGraph, v::Integer) = v in vertices(g)

out_neighbors(g::AbstractStaticGraph, v::Integer) = fadj(g, v)
in_neighbors(g::AbstractStaticGraph, v::Integer) = badj(g, v)
outneighbors(g::AbstractStaticGraph, v::Integer) = fadj(g, v)
inneighbors(g::AbstractStaticGraph, v::Integer) = badj(g, v)

zero(g::T) where T<:AbstractStaticGraph = T()

Expand All @@ -97,6 +96,7 @@ include("staticgraph.jl")
include("staticdigraph.jl")
include("persistence.jl")


const SGraph = StaticGraph
const SDiGraph = StaticDiGraph

Expand All @@ -105,5 +105,6 @@ const StaticEdgeIter{G} = LightGraphs.SimpleGraphs.SimpleEdgeIter{G}
eltype(::Type{StaticEdgeIter{StaticGraph{T, U}}}) where T where U = StaticGraphEdge{T}
eltype(::Type{StaticEdgeIter{StaticDiGraph{T, U}}}) where T where U = StaticDiGraphEdge{T}

include("overrides.jl")

end # module
2 changes: 2 additions & 0 deletions src/overrides.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
adjacency_matrix(g::StaticGraph) = SparseMatrixCSC{Bool,UInt32}(nv(g), nv(g), g.f_ind, g.f_vec, ones(Bool, ne(g)*2))
adjacency_matrix(g::StaticDiGraph) = SparseMatrixCSC{Bool,UInt32}(nv(g), nv(g), g.f_ind, g.f_vec, ones(Bool, ne(g)))
8 changes: 4 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ const testdir = dirname(@__FILE__)
@test @inferred eltype(hu) == UInt8
@test testfn(ne)
@test testfn(nv)
@test testfn(in_neighbors, 1)
@test testfn(out_neighbors, 1)
@test testfn(inneighbors, 1)
@test testfn(outneighbors, 1)
@test testfn(vertices)
@test testfn(degree)
@test testfn(degree, 1)
Expand Down Expand Up @@ -73,8 +73,8 @@ const testdir = dirname(@__FILE__)
@test @inferred eltype(dhu) == UInt8
@test dtestfn(ne)
@test dtestfn(nv)
@test dtestfn(in_neighbors, 1)
@test dtestfn(out_neighbors, 1)
@test dtestfn(inneighbors, 1)
@test dtestfn(outneighbors, 1)
@test dtestfn(vertices)
@test dtestfn(degree)
@test dtestfn(degree, 1)
Expand Down