Skip to content

Commit b57acef

Browse files
committed
More robust set_neighbors!
1 parent 6601039 commit b57acef

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/bipartite_graph.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,14 +442,16 @@ function set_neighbors!(g::BipartiteGraph, i::Integer, new_neighbors)
442442
for n in new_neighbors
443443
@inbounds list = g.badjlist[n]
444444
index = searchsortedfirst(list, i)
445-
insert!(list, index, i)
445+
if !(1 <= index <= length(list) && list[index] == i)
446+
insert!(list, index, i)
447+
end
446448
end
447449
end
448450
if iszero(new_nneighbors) # this handles Tuple as well
449451
# Warning: Aliases old_neighbors
450452
empty!(g.fadjlist[i])
451453
else
452-
g.fadjlist[i] = copy(new_neighbors)
454+
g.fadjlist[i] = unique!(sort(new_neighbors))
453455
end
454456
end
455457

0 commit comments

Comments
 (0)