Skip to content

Commit c2a2b32

Browse files
authored
Merge pull request #22 from JuliaGraphs/sbromberger/fix-21
fixes #21
2 parents fc3c473 + 0340548 commit c2a2b32

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

src/StaticGraphs.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ end
7272
return view(g.f_vec, r)
7373
end
7474

75+
76+
@inline fadj(g::AbstractStaticGraph) = [fadj(g, v) for v in vertices(g)]
77+
7578
nv(g::AbstractStaticGraph{T, U}) where T where U = T(length(g.f_ind) - 1)
7679
vertices(g::AbstractStaticGraph{T, U}) where T where U = Base.OneTo(nv(g))
7780

src/staticdigraph.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ end
2121
return view(g.b_vec, r)
2222
end
2323

24+
@inline badj(g) = [badj(g, v) for v in vertices(g)]
25+
2426
ne(g::StaticDiGraph{T, U}) where T where U = U(length(g.f_vec))
2527

2628
# sorted src, dst vectors for forward and backward edgelists.
@@ -92,4 +94,4 @@ is_directed(::Type{StaticDiGraph{T}}) where T = true
9294
is_directed(::Type{StaticDiGraph{T, U}}) where T where U = true
9395
is_directed(g::StaticDiGraph) = true
9496

95-
reverse(g::StaticDiGraph) = StaticDiGraph(copy(g.b_vec), copy(g.b_ind), copy(g.f_vec), copy(g.f_ind))
97+
reverse(g::StaticDiGraph) = StaticDiGraph(copy(g.b_vec), copy(g.b_ind), copy(g.f_vec), copy(g.f_ind))

src/staticgraph.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ function StaticGraph()
4848
end
4949

5050
badj(g::StaticGraph, s) = fadj(g, s)
51+
badj(g::StaticGraph) = fadj(g)
5152

5253
ne(g::StaticGraph{T, U}) where T where U = U(length(g.f_vec) ÷ 2)
5354

test/runtests.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ const testdir = dirname(@__FILE__)
5252
@test @inferred !is_directed(hu)
5353
@test @inferred !is_directed(StaticGraph)
5454
@test @inferred collect(edges(hu)) == collect(edges(sg))
55+
@test @inferred StaticGraphs.fadj(hu) == [StaticGraphs.fadj(hu, x) for x in vertices(hu)]
56+
@test @inferred StaticGraphs.badj(hu) == StaticGraphs.fadj(hu)
5557

5658
(g1, m1) = @inferred induced_subgraph(hu, [3,2,1])
5759
g2 = @inferred hu[3:-1:1]
@@ -74,7 +76,7 @@ const testdir = dirname(@__FILE__)
7476

7577
@testset "staticdigraph" begin
7678
@test sprint(show, StaticDiGraph(DiGraph())) == "{0, 0} directed simple static {UInt8, UInt8} graph"
77-
dg = PathDiGraph(5)
79+
dg = path_digraph(5)
7880
dgu = squash(dg)
7981
dsg = StaticDiGraph(dg)
8082
dsgu = StaticDiGraph(dgu)
@@ -111,6 +113,8 @@ const testdir = dirname(@__FILE__)
111113
@test @inferred is_directed(dhu)
112114
@test @inferred is_directed(StaticDiGraph)
113115
@test @inferred collect(edges(dhu)) == collect(edges(dsg))
116+
@test @inferred StaticGraphs.fadj(dhu) == [StaticGraphs.fadj(dhu, x) for x in vertices(dhu)]
117+
@test @inferred StaticGraphs.badj(dhu) == [StaticGraphs.badj(dhu, x) for x in vertices(dhu)]
114118

115119
(g1, m1) = @inferred induced_subgraph(dhu, [3,2,1])
116120
g2 = @inferred dhu[3:-1:1]

0 commit comments

Comments
 (0)