diff --git a/Project.toml b/Project.toml index e64c3da00..60608952c 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "DataStructures" uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" -version = "0.17.18" +version = "0.17.19" [deps] InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" diff --git a/src/sorted_dict.jl b/src/sorted_dict.jl index 836c18b0d..278cc13a8 100644 --- a/src/sorted_dict.jl +++ b/src/sorted_dict.jl @@ -535,6 +535,11 @@ function mergetwo!(m::SortedDict{K,D,Ord}, end end +# Standard copy functions use packcopy - that is, they retain elements but not +# the identical structure. +Base.copymutable(m::SortedDict) = packcopy(m) +Base.copy(m::SortedDict) = packcopy(m) + """ packcopy(sc) diff --git a/src/sorted_multi_dict.jl b/src/sorted_multi_dict.jl index a55b8f7a6..02e5937b2 100644 --- a/src/sorted_multi_dict.jl +++ b/src/sorted_multi_dict.jl @@ -385,6 +385,11 @@ function mergetwo!(m::SortedMultiDict{K,D,Ord}, end end +# Standard copy functions use packcopy - that is, they retain elements but not +# the identical structure. +Base.copymutable(m::SortedMultiDict) = packcopy(m) +Base.copy(m::SortedMultiDict) = packcopy(m) + """ packcopy(sc) diff --git a/src/sorted_set.jl b/src/sorted_set.jl index 7d9d31c7f..4bcf265a5 100644 --- a/src/sorted_set.jl +++ b/src/sorted_set.jl @@ -519,6 +519,11 @@ function issubset(iterable, m2::SortedSet) return true end +# Standard copy functions use packcopy - that is, they retain elements but not +# the identical structure. +Base.copymutable(m::SortedSet) = packcopy(m) +Base.copy(m::SortedSet) = packcopy(m) + """ packcopy(sc) diff --git a/test/test_sorted_containers.jl b/test/test_sorted_containers.jl index 67b08cd00..846d1f915 100644 --- a/test/test_sorted_containers.jl +++ b/test/test_sorted_containers.jl @@ -1717,4 +1717,16 @@ end @test pop!(s,50, nothing) == nothing @test isempty(s) + # Test AbstractSet/AbstractDict interface + for m in [SortedSet([1,2]), SortedDict(1=>2, 2=>3), SortedMultiDict(1=>2, 1=>3)] + # copy() + let m1 = copy(m) + @test isequal(m1, m) + @test typeof(m1) === typeof(m) + end + let m1 = Base.copymutable(m) + @test isequal(m1, m) + @test typeof(m1) === typeof(m) + end + end end