Skip to content

Commit 6dea392

Browse files
authored
Merge pull request #637 from NHDaly/nhd-SortedSetDict-copy
Add Base.copy, Base.copymutable for Sorted containers
2 parents b11fdc0 + d9d3901 commit 6dea392

File tree

5 files changed

+28
-1
lines changed

5 files changed

+28
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "DataStructures"
22
uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
3-
version = "0.17.18"
3+
version = "0.17.19"
44

55
[deps]
66
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

src/sorted_dict.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,11 @@ function mergetwo!(m::SortedDict{K,D,Ord},
535535
end
536536
end
537537

538+
# Standard copy functions use packcopy - that is, they retain elements but not
539+
# the identical structure.
540+
Base.copymutable(m::SortedDict) = packcopy(m)
541+
Base.copy(m::SortedDict) = packcopy(m)
542+
538543
"""
539544
packcopy(sc)
540545

src/sorted_multi_dict.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,11 @@ function mergetwo!(m::SortedMultiDict{K,D,Ord},
385385
end
386386
end
387387

388+
# Standard copy functions use packcopy - that is, they retain elements but not
389+
# the identical structure.
390+
Base.copymutable(m::SortedMultiDict) = packcopy(m)
391+
Base.copy(m::SortedMultiDict) = packcopy(m)
392+
388393
"""
389394
packcopy(sc)
390395

src/sorted_set.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,11 @@ function issubset(iterable, m2::SortedSet)
519519
return true
520520
end
521521

522+
# Standard copy functions use packcopy - that is, they retain elements but not
523+
# the identical structure.
524+
Base.copymutable(m::SortedSet) = packcopy(m)
525+
Base.copy(m::SortedSet) = packcopy(m)
526+
522527
"""
523528
packcopy(sc)
524529

test/test_sorted_containers.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,4 +1717,16 @@ end
17171717
@test pop!(s,50, nothing) == nothing
17181718
@test isempty(s)
17191719

1720+
# Test AbstractSet/AbstractDict interface
1721+
for m in [SortedSet([1,2]), SortedDict(1=>2, 2=>3), SortedMultiDict(1=>2, 1=>3)]
1722+
# copy()
1723+
let m1 = copy(m)
1724+
@test isequal(m1, m)
1725+
@test typeof(m1) === typeof(m)
1726+
end
1727+
let m1 = Base.copymutable(m)
1728+
@test isequal(m1, m)
1729+
@test typeof(m1) === typeof(m)
1730+
end
1731+
end
17201732
end

0 commit comments

Comments
 (0)