@@ -6,7 +6,7 @@ export BipartiteEdge, BipartiteGraph, DiCMOBiGraph, Unassigned, unassigned,
6
6
7
7
export 𝑠vertices, 𝑑vertices, has_𝑠vertex, has_𝑑vertex, 𝑠neighbors, 𝑑neighbors,
8
8
𝑠edges, 𝑑edges, nsrcs, ndsts, SRC, DST, set_neighbors!, invview,
9
- complete
9
+ complete, delete_srcs!, delete_dsts!
10
10
11
11
using DocStringExtensions
12
12
using UnPack
@@ -424,11 +424,15 @@ function Graphs.add_vertex!(g::BipartiteGraph{T}, type::VertType) where {T}
424
424
return true # vertex successfully added
425
425
end
426
426
427
- function set_neighbors! (g:: BipartiteGraph , i:: Integer , new_neighbors:: AbstractVector )
427
+ function set_neighbors! (g:: BipartiteGraph , i:: Integer , new_neighbors)
428
428
old_neighbors = g. fadjlist[i]
429
429
old_nneighbors = length (old_neighbors)
430
430
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
432
436
g. ne += new_nneighbors - old_nneighbors
433
437
if isa (g. badjlist, AbstractVector)
434
438
for n in old_neighbors
@@ -444,6 +448,14 @@ function set_neighbors!(g::BipartiteGraph, i::Integer, new_neighbors::AbstractVe
444
448
end
445
449
end
446
450
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
+
447
459
# ##
448
460
# ## Edges iteration
449
461
# ##
0 commit comments