Skip to content

Commit

Permalink
Merge pull request #637 from NHDaly/nhd-SortedSetDict-copy
Browse files Browse the repository at this point in the history
Add Base.copy, Base.copymutable for Sorted containers
  • Loading branch information
oxinabox authored Jun 25, 2020
2 parents b11fdc0 + d9d3901 commit 6dea392
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
5 changes: 5 additions & 0 deletions src/sorted_dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions src/sorted_multi_dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions src/sorted_set.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions test/test_sorted_containers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 comments on commit 6dea392

@oxinabox
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/16983

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.17.19 -m "<description of version>" 6dea392834f9a3bffa3b8d17ab309db93c810c32
git push origin v0.17.19

Please sign in to comment.