Skip to content

Commit 645b9c4

Browse files
authored
Merge pull request #36 from JuliaGraphs/fix-vertex-deletion
Fix vertex deletion
2 parents 1539095 + 089246b commit 645b9c4

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

docs/src/tutorial_basics.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ julia> using MetaGraphsNext
1111
We provide a default constructor in which you only need to specify types:
1212

1313
```jldoctest example
14-
julia> colors = MetaGraph( Graph(), VertexData = String, EdgeData = Symbol, graph_data = "graph_of_colors")
15-
Meta graph based on a Graphs.SimpleGraphs.SimpleGraph{Int64}(0, Vector{Int64}[]) with vertex labels of type Symbol, vertex metadata of type String, edge metadata of type Symbol, graph metadata given by "graph_of_colors", and default weight 1.0
14+
julia> colors = MetaGraph(Graph(), VertexData = String, EdgeData = Symbol, graph_data = "graph_of_colors")
15+
Meta graph based on a SimpleGraph{Int64}(0, Vector{Int64}[]) with vertex labels of type Symbol, vertex metadata of type String, edge metadata of type Symbol, graph metadata given by "graph_of_colors", and default weight 1.0
1616
```
1717

1818
## Modifying the graph

src/graphs.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@ function _rem_vertex!(meta_graph::MetaGraph, label, code)
154154
removed = rem_vertex!(meta_graph.graph, code)
155155
if removed
156156
if code != last_vertex_code # ignore if we're removing the last vertex.
157-
lastl = vertex_labels[last_vertex_code]
158-
lastvprop = vertex_properties[lastl]
159-
vertex_labels[code] = lastl
160-
vertex_properties[lastl] = lastvprop
157+
last_label = vertex_labels[last_vertex_code]
158+
_, last_data = vertex_properties[last_label]
159+
vertex_labels[code] = last_label
160+
vertex_properties[last_label] = code, last_data
161161
end
162162
delete!(vertex_labels, last_vertex_code)
163163
delete!(vertex_properties, label)

test/runtests.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
11
using Documenter
22
using MetaGraphsNext
33
using Test
4+
using Graphs
45

56
@testset "MetaGraphsNext" begin
67
doctest(MetaGraphsNext)
8+
9+
colors = MetaGraph( Graph(), VertexData = String, EdgeData = Symbol, graph_data = "graph_of_colors")
10+
11+
labels = [:red, :yellow, :blue]
12+
values = ["warm", "warm", "cool"]
13+
for (label, value) in zip(labels, values)
14+
colors[label] = value
15+
end
16+
for label in labels
17+
@test label_for(colors, code_for(colors, label)) == label
18+
end
19+
#delete an entry and test again
20+
rem_vertex!(colors, 1)
21+
popfirst!(labels)
22+
popfirst!(values)
23+
for label in labels
24+
@test label_for(colors, code_for(colors, label)) == label
25+
end
726
end

0 commit comments

Comments
 (0)