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

fix #69 and #70 #71

Merged
merged 6 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions src/graphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,18 @@ Add an edge `(label_1, label_2)` to MetaGraph `meta_graph` with metadata `data`.
If the `EdgeData` type of `meta_graph` is `Nothing`, `data` can be omitted.

Return `true` if the edge has been added, `false` otherwise.
If `(label_1, label_2)` already existed, its data is *not* updated to `data`.
If `(label_1, label_2)` already existed, its data is updated to `data`.
gdalle marked this conversation as resolved.
Show resolved Hide resolved
"""
function Graphs.add_edge!(meta_graph::MetaGraph, label_1, label_2, data)
if !haskey(meta_graph, label_1) || !haskey(meta_graph, label_2)
return false
end
code_1, code_2 = code_for(meta_graph, label_1), code_for(meta_graph, label_2)
label_tup = arrange(meta_graph, label_1, label_2)
meta_graph.edge_data[label_tup] = data
if has_edge(meta_graph.graph, code_1, code_2)
return false
end
meta_graph.edge_data[label_tup] = data
ne_prev = ne(meta_graph.graph)
add_edge!(meta_graph.graph, code_1, code_2)
if ne(meta_graph.graph) == ne_prev # undo
Expand Down
4 changes: 2 additions & 2 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ end
# attempt to add an existing edge: non-standard order, different data
@test !add_edge!(colors, :green, :blue, :teal)
@test length(colors.edge_data) == ne(colors)
@test colors[:blue, :green] == :cyan
@test colors[:blue, :green] == :teal

# Delete vertex in a copy and test again

colors_copy = copy(colors)
rem_vertex!(colors_copy, 1)
test_labels_codes(colors_copy)
@test ne(colors_copy) == 1
@test colors_copy[:blue, :green] == :cyan
@test colors_copy[:blue, :green] == :teal
end

@testset verbose = true "Short-form add_vertex!/add_edge!" begin
Expand Down