Skip to content
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

rem_parts! and cascading_rem_parts! can take colon arg #117

Merged
merged 1 commit into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/ACSetInterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,10 @@ See also: [`rem_part!`](@ref).
end
end

@inline function rem_parts!(acs::ACSet, type, ::Colon)
rem_parts!(acs, type, parts(acs, type))
end

""" Remove parts and all parts incident to them, recursively.

The parts may be supplied in any order and may include duplicates.
Expand Down
3 changes: 3 additions & 0 deletions src/DenseACSets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,9 @@ function delete_subobj!(X::ACSet, delparts)
end)
end

ACSetInterface.cascading_rem_parts!(acs::ACSet, type, ::Colon) =
cascading_rem_parts!(acs, type, parts(acs, type))

ACSetInterface.cascading_rem_parts!(acs::ACSet, type, parts) =
delete_subobj!(acs, Dict(type=>parts))

Expand Down
11 changes: 11 additions & 0 deletions test/ACSets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ for dds_maker in dds_makers
@test incident(dds, 2, :Φ) == []
end

# delete all parts of an Ob
dds = dds_maker()
add_parts!(dds, :X, 4, Φ=[2,3,3,4])
rem_parts!(dds, :X, :)
@test nparts(dds, :X) == 0

# Recursive deletion.
dds = dds_maker()
add_parts!(dds, :X, 3, Φ=[2,3,3])
Expand All @@ -148,6 +154,11 @@ for dds_maker in dds_makers
cascading_rem_parts!(dds, :X, [1,2])
@test nparts(dds, :X) == 1

dds = dds_maker()
add_parts!(dds, :X, 3, Φ=[2,3,3])
cascading_rem_parts!(dds, :X, :)
@test nparts(dds, :X) == 0

# Pretty printing.
dds = dds_maker()
add_parts!(dds, :X, 3, Φ=[2,3,3])
Expand Down
Loading