Skip to content

Commit 84c1f78

Browse files
committed
Merge branch 'master' into dev
2 parents ade2eb2 + 7b034c2 commit 84c1f78

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

src/graphs.jl

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,17 @@ end
8888
add_vertex!(meta_graph, label, data)
8989
9090
Add a vertex to MetaGraph `meta_graph` with label `label` having metadata `data`.
91+
If the `VertexData` type of `meta_graph` is `Nothing`, `data` can be omitted.
9192
92-
Return true if the vertex has been added, false incase the label already exists or vertex was not added.
93+
Return true if the vertex has been added, false in case the label already exists or vertex was not added.
9394
"""
9495
function Graphs.add_vertex!(meta_graph::MetaGraph, label, data)
9596
if haskey(meta_graph, label)
9697
return false
9798
end
98-
added = add_vertex!(meta_graph.graph)
99+
nvnum = nv(meta_graph.graph)
100+
add_vertex!(meta_graph.graph)
101+
added = nvnum + 1 == nv(meta_graph.graph)
99102
if added
100103
code = nv(meta_graph)
101104
meta_graph.vertex_labels[code] = label
@@ -104,10 +107,15 @@ function Graphs.add_vertex!(meta_graph::MetaGraph, label, data)
104107
return added
105108
end
106109

110+
function Graphs.add_vertex!(meta_graph::MetaGraph{<:Any,<:Any,<:Any,Nothing}, label)
111+
return Graphs.add_vertex!(meta_graph, label, nothing)
112+
end
113+
107114
"""
108115
add_edge!(meta_graph, label_1, label_2, data)
109116
110117
Add an edge `(label_1, label_2)` to MetaGraph `meta_graph` with metadata `data`.
118+
If the `EdgeData` type of `meta_graph` is `Nothing`, `data` can be omitted.
111119
112120
Return `true` if the edge has been added, `false` otherwise.
113121
"""
@@ -120,6 +128,12 @@ function Graphs.add_edge!(meta_graph::MetaGraph, label_1, label_2, data)
120128
return added
121129
end
122130

131+
function Graphs.add_edge!(
132+
meta_graph::MetaGraph{<:Any,<:Any,<:Any,<:Any,Nothing}, label_1, label_2
133+
)
134+
return Graphs.add_edge!(meta_graph, label_1, label_2, nothing)
135+
end
136+
123137
## Remove vertex
124138

125139
function _rem_vertex!(meta_graph::MetaGraph, label, code)

test/misc.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
@testset verbose = true "Short-form add_vertex!/add_edge!" begin
2+
# short-form
3+
mg = MetaGraph(
4+
Graph(); label_type=Symbol, vertex_data_type=Nothing, edge_data_type=Nothing
5+
)
6+
@test add_vertex!(mg, :A)
7+
@test add_vertex!(mg, :B)
8+
@test add_edge!(mg, :A, :B)
9+
10+
# long-form
11+
mg2 = MetaGraph(
12+
Graph(); label_type=Symbol, vertex_data_type=Nothing, edge_data_type=Nothing
13+
)
14+
@test add_vertex!(mg2, :A, nothing)
15+
@test add_vertex!(mg2, :B, nothing)
16+
@test add_edge!(mg2, :A, :B, nothing)
17+
18+
# compare
19+
@test mg == mg2
20+
end

test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,8 @@ DocMeta.setdocmeta!(MetaGraphsNext, :DocTestSetup, :(using MetaGraphsNext); recu
3232
include(joinpath("tutorial", "4_type_stability.jl"))
3333
end
3434
end
35+
36+
@testset verbose = true "Miscellaneous" begin
37+
include("misc.jl")
38+
end
3539
end

0 commit comments

Comments
 (0)