-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# This file is a part of Julia. License is MIT: https://julialang.org/license | ||
|
||
"The `Future` module implements future behavior of already existing functions, | ||
which will replace the current version in a future release of Julia." | ||
module Future | ||
|
||
## copy! | ||
|
||
""" | ||
Future.copy!(dst, src) -> dst | ||
Copy `src` into `dst`. | ||
For collections of the same type, copy the elements of `src` into `dst`, | ||
discarding any pre-existing elements in `dst`. | ||
Usually, `dst == src` holds after the call. | ||
""" | ||
copy!(dst::AbstractSet, src::AbstractSet) = union!(empty!(dst), src) | ||
copy!(dst::AbstractDict, src::AbstractDict) = merge!(empty!(dst), src) | ||
copy!(dst::AbstractVector, src::AbstractVector) = append!(empty!(dst), src) | ||
|
||
function copy!(dst::AbstractArray, src::AbstractArray) | ||
size(dst) == size(src) || throw(ArgumentError( | ||
"arrays must have the same size for copy! (consider using `copyto!`)")) | ||
copyto!(dst, src) | ||
end | ||
|
||
end # module Future |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# This file is a part of Julia. License is MIT: https://julialang.org/license | ||
|
||
using Test | ||
using Future | ||
|
||
@testset "Future.copy! for AbstractSet" begin | ||
for S = (Set, BitSet) | ||
s = S([1, 2]) | ||
for a = ([1], UInt[1], [3, 4, 5], UInt[3, 4, 5]) | ||
@test s === Future.copy!(s, Set(a)) == S(a) | ||
@test s === Future.copy!(s, BitSet(a)) == S(a) | ||
end | ||
end | ||
end | ||
|
||
|
||
@testset "Future.copy! for AbstractDict" begin | ||
s = Dict(1=>2, 2=>3) | ||
for a = ([3=>4], [0x3=>0x4], [3=>4, 5=>6, 7=>8], Pair{UInt,UInt}[3=>4, 5=>6, 7=>8]) | ||
@test s === Future.copy!(s, Dict(a)) == Dict(a) | ||
if length(a) == 1 # current limitation of Base.ImmutableDict | ||
@test s === Future.copy!(s, Base.ImmutableDict(a[])) == Dict(a[]) | ||
end | ||
end | ||
end | ||
|
||
@testset "Future.copy! for AbstractVector" begin | ||
s = Vector([1, 2]) | ||
for a = ([1], UInt[1], [3, 4, 5], UInt[3, 4, 5]) | ||
@test s === Future.copy!(s, Vector(a)) == Vector(a) | ||
@test s === Future.copy!(s, SparseVector(a)) == Vector(a) | ||
end | ||
end | ||
|
||
@testset "Future.copy! for AbstractArray" begin | ||
@test_throws ArgumentError Future.copy!(zeros(2, 3), zeros(3, 2)) | ||
s = zeros(2, 2) | ||
@test s === Future.copy!(s, fill(1, 2, 2)) == fill(1, 2, 2) | ||
@test s === Future.copy!(s, fill(1.0, 2, 2)) == fill(1.0, 2, 2) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters