Skip to content

Commit 204b6d4

Browse files
committed
Separate structural info from symbolic info
1 parent 020899f commit 204b6d4

File tree

4 files changed

+215
-150
lines changed

4 files changed

+215
-150
lines changed

src/bipartite_graph.jl

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export BipartiteEdge, BipartiteGraph, DiCMOBiGraph, Unassigned, unassigned,
66

77
export 𝑠vertices, 𝑑vertices, has_𝑠vertex, has_𝑑vertex, 𝑠neighbors, 𝑑neighbors,
88
𝑠edges, 𝑑edges, nsrcs, ndsts, SRC, DST, set_neighbors!, invview,
9-
complete
9+
complete, delete_srcs!, delete_dsts!
1010

1111
using DocStringExtensions
1212
using UnPack
@@ -424,11 +424,15 @@ function Graphs.add_vertex!(g::BipartiteGraph{T}, type::VertType) where {T}
424424
return true # vertex successfully added
425425
end
426426

427-
function set_neighbors!(g::BipartiteGraph, i::Integer, new_neighbors::AbstractVector)
427+
function set_neighbors!(g::BipartiteGraph, i::Integer, new_neighbors)
428428
old_neighbors = g.fadjlist[i]
429429
old_nneighbors = length(old_neighbors)
430430
new_nneighbors = length(new_neighbors)
431-
g.fadjlist[i] = new_neighbors
431+
if iszero(new_nneighbors) # this handles Tuple as well
432+
empty!(g.fadjlist[i])
433+
else
434+
g.fadjlist[i] = new_neighbors
435+
end
432436
g.ne += new_nneighbors - old_nneighbors
433437
if isa(g.badjlist, AbstractVector)
434438
for n in old_neighbors
@@ -444,6 +448,14 @@ function set_neighbors!(g::BipartiteGraph, i::Integer, new_neighbors::AbstractVe
444448
end
445449
end
446450

451+
function delete_srcs!(g::BipartiteGraph, srcs)
452+
for s in srcs
453+
set_neighbors!(g, s, ())
454+
end
455+
g
456+
end
457+
delete_dsts!(g::BipartiteGraph, srcs) = delete_srcs!(invview(g), srcs)
458+
447459
###
448460
### Edges iteration
449461
###

0 commit comments

Comments
 (0)