Skip to content

Commit 606acc3

Browse files
committed
Fix set_neighbors! for complete graph
1 parent ca60bfb commit 606acc3

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/bipartite_graph.jl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,10 +341,23 @@ function Graphs.add_vertex!(g::BipartiteGraph{T}, type::VertType) where T
341341
end
342342

343343
function set_neighbors!(g::BipartiteGraph, i::Integer, new_neighbors::AbstractVector)
344-
old_nneighbors = length(g.fadjlist[i])
344+
old_neighbors = g.fadjlist[i]
345+
old_nneighbors = length(old_neighbors)
345346
new_nneighbors = length(new_neighbors)
346347
g.fadjlist[i] = new_neighbors
347348
g.ne += new_nneighbors - old_nneighbors
349+
if isa(g.badjlist, AbstractVector)
350+
for n in old_neighbors
351+
@inbounds list = g.badjlist[n]
352+
index = searchsortedfirst(list, i)
353+
deleteat!(list, index)
354+
end
355+
for n in new_neighbors
356+
@inbounds list = g.badjlist[n]
357+
index = searchsortedfirst(list, i)
358+
insert!(list, index, i)
359+
end
360+
end
348361
end
349362

350363
###

0 commit comments

Comments
 (0)