Skip to content

Commit fb1acd1

Browse files
committed
Add Base.copy,Base.copymutable for Sorted containers
1 parent b11fdc0 commit fb1acd1

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,4 +1717,10 @@ 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+
@test isequal(copy(m), m)
1724+
@test isequal(Base.copymutable(m), m)
1725+
end
17201726
end

0 commit comments

Comments
 (0)