Skip to content

Commit c9a3931

Browse files
committed
format
1 parent 0310484 commit c9a3931

File tree

6 files changed

+83
-63
lines changed

6 files changed

+83
-63
lines changed

docs/make.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using Pkg: develop, instantiate, PackageSpec
2-
develop(PackageSpec(path=pwd()))
2+
develop(PackageSpec(path = pwd()))
33

44
using MetaGraphs
55

src/MetaGraphs.jl

Lines changed: 63 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,57 @@ using LightGraphs
33
using JLD2
44

55
import Base:
6-
eltype, show, ==,
7-
Tuple, copy, length, size,
8-
issubset, zero, getindex, haskey, setindex!, delete!
6+
eltype,
7+
show,
8+
==,
9+
Tuple,
10+
copy,
11+
length,
12+
size,
13+
issubset,
14+
zero,
15+
getindex,
16+
haskey,
17+
setindex!,
18+
delete!
919

1020
import LightGraphs:
11-
AbstractGraph, edgetype, nv,
12-
ne, vertices, edges, is_directed,
13-
add_vertex!, add_edge!, rem_vertex!, rem_edge!,
14-
has_vertex, has_edge, inneighbors, outneighbors,
21+
AbstractGraph,
22+
edgetype,
23+
nv,
24+
ne,
25+
vertices,
26+
edges,
27+
is_directed,
28+
add_vertex!,
29+
add_edge!,
30+
rem_vertex!,
31+
rem_edge!,
32+
has_vertex,
33+
has_edge,
34+
inneighbors,
35+
outneighbors,
1536
weights,
1637
induced_subgraph,
17-
loadgraph, savegraph, AbstractGraphFormat,
38+
loadgraph,
39+
savegraph,
40+
AbstractGraphFormat,
1841
reverse
1942

20-
import LightGraphs.SimpleGraphs:
21-
SimpleGraph, SimpleDiGraph,
22-
fadj, badj
23-
24-
export
25-
MetaGraph,
26-
weighttype,
27-
defaultweight,
28-
weightfunction,
29-
MGFormat,
30-
DOTFormat,
31-
reverse
43+
import LightGraphs.SimpleGraphs: SimpleGraph, SimpleDiGraph, fadj, badj
44+
45+
export MetaGraph, weighttype, defaultweight, weightfunction, MGFormat, DOTFormat, reverse
3246

3347
include("metagraph.jl")
3448

35-
function show(io::IO, g::MetaGraph{<: Any, Label, <: Any, VertexMeta, EdgeMeta}) where {Label, VertexMeta, EdgeMeta}
36-
print(io, "Meta graph based on a $(g.graph) with vertices indexed by $Label(s), $VertexMeta(s) vertex metadata, $EdgeMeta(s) edge metadata, $(repr(g.gprops)) as graph metadata, and default weight $(g.defaultweight)")
49+
function show(
50+
io::IO,
51+
g::MetaGraph{<:Any,Label,<:Any,VertexMeta,EdgeMeta},
52+
) where {Label,VertexMeta,EdgeMeta}
53+
print(
54+
io,
55+
"Meta graph based on a $(g.graph) with vertices indexed by $Label(s), $VertexMeta(s) vertex metadata, $EdgeMeta(s) edge metadata, $(repr(g.gprops)) as graph metadata, and default weight $(g.defaultweight)",
56+
)
3757
end
3858

3959
@inline fadj(g::MetaGraph, x...) = fadj(g.graph, x...)
@@ -54,7 +74,7 @@ has_vertex(g::MetaGraph, x...) = has_vertex(g.graph, x...)
5474
inneighbors(g::MetaGraph, v::Integer) = inneighbors(g.graph, v)
5575
outneighbors(g::MetaGraph, v::Integer) = fadj(g.graph, v)
5676

57-
issubset(g::T, h::T) where T <: MetaGraph = issubset(g.graph, h.graph)
77+
issubset(g::T, h::T) where {T<:MetaGraph} = issubset(g.graph, h.graph)
5878

5979
"""
6080
add_edge!(g, u, v, val)
@@ -105,7 +125,7 @@ function _rem_vertex!(g, label, v)
105125
delete!(eprops, arrange(g, label, metaindex[n], v, n))
106126
end
107127
for n in inneighbors(g, v)
108-
delete!(eprops, arrange(g, metaindex[n], label, n, v))
128+
delete!(eprops, arrange(g, metaindex[n], label, n, v))
109129
end
110130
removed = rem_vertex!(g.graph, v)
111131
if removed
@@ -130,7 +150,7 @@ function rem_vertex!(g::MetaGraph, v::Integer)
130150
end
131151
end
132152

133-
struct MetaWeights{InnerMetaGraph, U <: Real} <: AbstractMatrix{U}
153+
struct MetaWeights{InnerMetaGraph,U<:Real} <: AbstractMatrix{U}
134154
meta_graph::InnerMetaGraph
135155
end
136156

@@ -220,7 +240,7 @@ julia> weighttype(MetaGraph(Graph(), defaultweight = 1.0))
220240
Float64
221241
```
222242
"""
223-
weighttype(g::MetaGraph{<: Any, <: Any, <: Any, <: Any, <: Any, <: Any, <:Any, Weight}) where {Weight} =
243+
weighttype(g::MetaGraph{<:Any,<:Any,<:Any,<:Any,<:Any,<:Any,<:Any,Weight}) where {Weight} =
224244
Weight
225245

226246
"""
@@ -255,7 +275,7 @@ julia> defaultweight(MetaGraph(Graph(), defaultweight = 2))
255275
"""
256276
defaultweight(g::MetaGraph) = g.defaultweight
257277

258-
function _copy_props!(oldg::T, newg::T, vmap) where T <: MetaGraph
278+
function _copy_props!(oldg::T, newg::T, vmap) where {T<:MetaGraph}
259279
for (newv, oldv) in enumerate(vmap)
260280
oldl = oldg.metaindex[oldv]
261281
_, meta = oldg.vprops[oldl]
@@ -267,22 +287,26 @@ function _copy_props!(oldg::T, newg::T, vmap) where T <: MetaGraph
267287
u, v = Tuple(newe)
268288
label_1 = metaindex[u]
269289
label_2 = metaindex[v]
270-
newg.eprops[arrange(newg, label_1, label_2, u, v)] = oldg.eprops[arrange(oldg, label_1, label_2)]
290+
newg.eprops[arrange(newg, label_1, label_2, u, v)] =
291+
oldg.eprops[arrange(oldg, label_1, label_2)]
271292
end
272293
return nothing
273294
end
274295

275-
function induced_subgraph(g::T, v::AbstractVector{U}) where T <: MetaGraph where U <: Integer
296+
function induced_subgraph(
297+
g::T,
298+
v::AbstractVector{U},
299+
) where {T<:MetaGraph} where {U<:Integer}
276300
inducedgraph, vmap = induced_subgraph(g.graph, v)
277-
newg =
278-
MetaGraph(inducedgraph,
279-
empty(g.vprops),
280-
empty(g.eprops),
281-
g.gprops,
282-
g.weightfunction,
283-
g.defaultweight,
284-
empty(g.metaindex)
285-
)
301+
newg = MetaGraph(
302+
inducedgraph,
303+
empty(g.vprops),
304+
empty(g.eprops),
305+
g.gprops,
306+
g.weightfunction,
307+
g.defaultweight,
308+
empty(g.metaindex),
309+
)
286310
_copy_props!(g, newg, vmap)
287311
return newg, vmap
288312
end
@@ -293,7 +317,7 @@ end
293317

294318
==(x::MetaGraph, y::MetaGraph) = x.graph == y.graph
295319

296-
copy(g::T) where T <: MetaGraph = deepcopy(g)
320+
copy(g::T) where {T<:MetaGraph} = deepcopy(g)
297321

298322
include("metadigraph.jl")
299323
include("overrides.jl")

src/metadigraph.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const MetaDiGraph = MetaGraph{<: Any, <: Any, <: DiGraph}
1+
const MetaDiGraph = MetaGraph{<:Any,<:Any,<:DiGraph}
22

33
SimpleDiGraph(g::MetaDiGraph) = g.graph
44

5-
is_directed(::Type{<: MetaDiGraph}) = true
5+
is_directed(::Type{<:MetaDiGraph}) = true
66

77
function arrange(g::MetaDiGraph, label_1, label_2, code...)
88
label_1, label_2

src/metagraph.jl

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -233,19 +233,19 @@ function MetaGraph(
233233
gprops = nothing,
234234
weightfunction = eprops -> 1.0,
235235
defaultweight = 1.0,
236-
) where {Vertex, T}
236+
) where {Vertex,T}
237237
MetaGraph(
238238
g,
239239
Dict{Label,Tuple{T,VertexMeta}}(),
240240
Dict{Tuple{Label,Label},EdgeMeta}(),
241241
gprops,
242242
weightfunction,
243243
defaultweight,
244-
Dict{T,Label}()
244+
Dict{T,Label}(),
245245
)
246246
end
247247

248-
const MetaUndirectedGraph = MetaGraph{<:Any, <:Any, <:SimpleGraph}
248+
const MetaUndirectedGraph = MetaGraph{<:Any,<:Any,<:SimpleGraph}
249249

250250
SimpleGraph(g::MetaUndirectedGraph) = g.graph
251251

@@ -264,12 +264,14 @@ function arrange(g::MetaUndirectedGraph, label_1, label_2, u, v)
264264
end
265265
end
266266

267-
zero(g::MetaGraph{T, Label, Graph, VertexMeta, EdgeMeta, GraphMeta}) where {T, Label, Graph, VertexMeta, EdgeMeta, GraphMeta} =
268-
MetaGraph(Graph();
269-
Label = Label,
270-
VertexMeta = VertexMeta,
271-
EdgeMeta = EdgeMeta,
272-
gprops = g.gprops,
273-
weightfunction = g.weightfunction,
274-
defaultweight = g.defaultweight
275-
)
267+
zero(
268+
g::MetaGraph{T,Label,Graph,VertexMeta,EdgeMeta,GraphMeta},
269+
) where {T,Label,Graph,VertexMeta,EdgeMeta,GraphMeta} = MetaGraph(
270+
Graph();
271+
Label = Label,
272+
VertexMeta = VertexMeta,
273+
EdgeMeta = EdgeMeta,
274+
gprops = g.gprops,
275+
weightfunction = g.weightfunction,
276+
defaultweight = g.defaultweight,
277+
)

src/overrides.jl

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,8 @@ function reverse(mg::MetaDiGraph)
1111
reprops[(v, u)] = mg.eprops[(u, v)]
1212
end
1313

14-
rmg = MetaGraph(rg,
15-
rvprops,
16-
reprops,
17-
rgprops,
18-
rweightfunction,
19-
rdefaultweight,
20-
rindices
21-
)
14+
rmg =
15+
MetaGraph(rg, rvprops, reprops, rgprops, rweightfunction, rdefaultweight, rindices)
2216

2317
return rmg
2418
end

src/persistence.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function savemg(fn::AbstractString, g::MetaGraph)
8282
end
8383

8484
loadgraph(fn::AbstractString, gname::String, ::MGFormat) = loadmg(fn)
85-
savegraph(fn::AbstractString, g::MetaGraph) = savemg(fn, g)
85+
savegraph(fn::AbstractString, g::MetaGraph) = savemg(fn, g)
8686

8787
function show_meta_list(io::IO, meta)
8888
if meta !== nothing && length(meta) > 0

0 commit comments

Comments
 (0)