-
Notifications
You must be signed in to change notification settings - Fork 1
Starting to fix #37 #40
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -628,7 +628,57 @@ end | |
# rem_vertex! | ||
# ------------------------------------------------------ | ||
|
||
# TODO | ||
function LG.rem_vertex!(g::ValGraph, v::Integer) | ||
# Procedure: swap v and n, then remove n | ||
v in vertices(g) || return false | ||
n = nv(g) | ||
self_loop_n = false # true if n is self-looped (see #820) | ||
|
||
# Swap the vertex values of v and n | ||
if v != n | ||
for i in 1:length(g.vertexvals) | ||
g.vertexvals[i][v] = g.vertexvals[i][n] | ||
end | ||
end | ||
|
||
# Swap the edges and edge values of v and n | ||
|
||
# remove the in_edges incident to v | ||
neigs_v = copy(inneighbors(g, v)) | ||
for s in neigs_v | ||
rem_edge!(g, s, v) | ||
end | ||
values_selfloop = nothing # TODO: fix this type instability | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would not worry too much about type instability. If you have some variable of type |
||
if v != n | ||
neigs_n = copy(inneighbors(g, n)) | ||
for s in neigs_n | ||
values = get_edgeval(g, s, n, :) | ||
# remove the edges incident to the last vertex | ||
rem_edge!(g, s, n) | ||
# add them back as incident to v | ||
if s != n | ||
add_edge!(g, s, v, values) | ||
else # don't add an edge to the last vertex yet - see LG #820. | ||
self_loop_n = true | ||
values_selfloop = copy(values) | ||
end | ||
end | ||
end | ||
|
||
if self_loop_n | ||
add_edge!(g, v, v, values_selfloop) | ||
end | ||
|
||
pop!(g.fadjlist) | ||
for i in 1:length(g.vertexvals) | ||
pop!(g.vertexvals[i]) | ||
end | ||
for i in 1:length(g.edgevals) | ||
pop!(g.edgevals[i]) | ||
end | ||
|
||
return true | ||
end | ||
|
||
# ------------------------------------------------------ | ||
# has_edge | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it were not better, if we would work directly with the adjacency lists here - after all this method does not have to solve the abstract case, but only has to work for this graph.