Skip to content

Commit 6383358

Browse files
committed
Merge deleteat() into delete!() and deprecate it
The generic definition of delete!() suits deleteat!() very well, and the signatures do not conflict.
1 parent 3257ec9 commit 6383358

25 files changed

Lines changed: 110 additions & 107 deletions

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,8 @@ Deprecated or removed
324324
* `produce`, `consume` and iteration over a Task object have been deprecated in favor of
325325
using Channels for inter-task communication ([#19841]).
326326
327+
* `deleteat!` has been deprecated in favor of `delete!` ([#20531]).
328+
327329
<!--- generated by NEWS-update.jl: -->
328330
[#265]: https://github.com/JuliaLang/julia/issues/265
329331
[#7669]: https://github.com/JuliaLang/julia/issues/7669

base/array.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -767,13 +767,13 @@ function insert!{T}(a::Array{T,1}, i::Integer, item)
767767
end
768768

769769
"""
770-
deleteat!(a::Vector, i::Integer)
770+
delete!(a::Vector, i::Integer)
771771
772772
Remove the item at the given `i` and return the modified `a`. Subsequent items
773773
are shifted to fill the resulting gap.
774774
775775
```jldoctest
776-
julia> deleteat!([6, 5, 4, 3, 2, 1], 2)
776+
julia> delete!([6, 5, 4, 3, 2, 1], 2)
777777
5-element Array{Int64,1}:
778778
6
779779
4
@@ -782,34 +782,34 @@ julia> deleteat!([6, 5, 4, 3, 2, 1], 2)
782782
1
783783
```
784784
"""
785-
deleteat!(a::Vector, i::Integer) = (_deleteat!(a, i, 1); a)
785+
delete!(a::Vector, i::Integer) = (_deleteat!(a, i, 1); a)
786786

787-
function deleteat!{T<:Integer}(a::Vector, r::UnitRange{T})
787+
function delete!{T<:Integer}(a::Vector, r::UnitRange{T})
788788
n = length(a)
789789
isempty(r) || _deleteat!(a, first(r), length(r))
790790
return a
791791
end
792792

793793
"""
794-
deleteat!(a::Vector, inds)
794+
delete!(a::Vector, inds)
795795
796796
Remove the items at the indices given by `inds`, and return the modified `a`.
797797
Subsequent items are shifted to fill the resulting gap. `inds` must be sorted and unique.
798798
799799
```jldoctest
800-
julia> deleteat!([6, 5, 4, 3, 2, 1], 1:2:5)
800+
julia> delete!([6, 5, 4, 3, 2, 1], 1:2:5)
801801
3-element Array{Int64,1}:
802802
5
803803
3
804804
1
805805
806-
julia> deleteat!([6, 5, 4, 3, 2, 1], (2, 2))
806+
julia> delete!([6, 5, 4, 3, 2, 1], (2, 2))
807807
ERROR: ArgumentError: indices must be unique and sorted
808808
Stacktrace:
809-
[1] deleteat!(::Array{Int64,1}, ::Tuple{Int64,Int64}) at ./array.jl:808
809+
[1] delete!(::Array{Int64,1}, ::Tuple{Int64,Int64}) at ./array.jl:822
810810
```
811811
"""
812-
function deleteat!(a::Vector, inds)
812+
function delete!(a::Vector, inds)
813813
n = length(a)
814814
s = start(inds)
815815
done(inds, s) && return a
@@ -938,7 +938,7 @@ function splice!{T<:Integer}(a::Vector, r::UnitRange{T}, ins=_default_splice)
938938
v = a[r]
939939
m = length(ins)
940940
if m == 0
941-
deleteat!(a, r)
941+
delete!(a, r)
942942
return v
943943
end
944944

@@ -1746,7 +1746,7 @@ function filter!(f, a::Vector)
17461746
insrt += 1
17471747
end
17481748
end
1749-
deleteat!(a, insrt:length(a))
1749+
delete!(a, insrt:length(a))
17501750
return a
17511751
end
17521752

base/bitarray.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ function resize!(B::BitVector, n::Integer)
894894
n == n0 && return B
895895
n >= 0 || throw(BoundsError(B, n))
896896
if n < n0
897-
deleteat!(B, n+1:n0)
897+
delete!(B, n+1:n0)
898898
return B
899899
end
900900
Bc = B.chunks
@@ -992,7 +992,7 @@ function insert!(B::BitVector, i::Integer, item)
992992
B
993993
end
994994

995-
function _deleteat!(B::BitVector, i::Integer)
995+
function _delete!(B::BitVector, i::Integer)
996996
k, j = get_chunks_id(i)
997997

998998
msk_bef = _msk64 >>> (63 - j)
@@ -1025,14 +1025,14 @@ function _deleteat!(B::BitVector, i::Integer)
10251025
return B
10261026
end
10271027

1028-
function deleteat!(B::BitVector, i::Integer)
1028+
function delete!(B::BitVector, i::Integer)
10291029
n = length(B)
10301030
1 <= i <= n || throw(BoundsError(B, i))
10311031

1032-
return _deleteat!(B, i)
1032+
return _delete!(B, i)
10331033
end
10341034

1035-
function deleteat!(B::BitVector, r::UnitRange{Int})
1035+
function delete!(B::BitVector, r::UnitRange{Int})
10361036
n = length(B)
10371037
i_f = first(r)
10381038
i_l = last(r)
@@ -1056,7 +1056,7 @@ function deleteat!(B::BitVector, r::UnitRange{Int})
10561056
return B
10571057
end
10581058

1059-
function deleteat!(B::BitVector, inds)
1059+
function delete!(B::BitVector, inds)
10601060
n = new_l = length(B)
10611061
s = start(inds)
10621062
done(inds, s) && return B
@@ -1099,7 +1099,7 @@ function splice!(B::BitVector, i::Integer)
10991099
1 <= i <= n || throw(BoundsError(B, i))
11001100

11011101
v = B[i] # TODO: change to a copy if/when subscripting becomes an ArrayView
1102-
_deleteat!(B, i)
1102+
_delete!(B, i)
11031103
return v
11041104
end
11051105

base/client.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ try_include(path::AbstractString) = isfile(path) && include(path)
246246
function process_options(opts::JLOptions)
247247
if !isempty(ARGS)
248248
idxs = find(x -> x == "--", ARGS)
249-
length(idxs) > 0 && deleteat!(ARGS, idxs[1])
249+
length(idxs) > 0 && delete!(ARGS, idxs[1])
250250
end
251251
repl = true
252252
startup = (opts.startupfile != 2)

base/deprecated.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,8 +605,8 @@ function gen_broadcast_body_zpreserving(f::Function, is_first_sparse::Bool)
605605
end
606606
B.colptr[col+1] = ptrB
607607
end
608-
deleteat!(B.rowval, B.colptr[end]:length(B.rowval))
609-
deleteat!(B.nzval, B.colptr[end]:length(B.nzval))
608+
delete!(B.rowval, B.colptr[end]:length(B.rowval))
609+
delete!(B.nzval, B.colptr[end]:length(B.nzval))
610610
nothing
611611
end
612612
end
@@ -1227,6 +1227,8 @@ for name in ("alnum", "alpha", "cntrl", "digit", "number", "graph",
12271227
@eval @deprecate ($f)(s::AbstractString) all($f, s)
12281228
end
12291229

1230+
@deprecate deleteat! delete!
1231+
12301232
# TODO: remove warning for using `_` in parse_input_line in base/client.jl
12311233

12321234
# END 0.6 deprecations

base/dict.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,14 @@ function _delete!(h::Dict, index)
554554
return h
555555
end
556556

557+
"""
558+
delete!(collection, keys)
559+
560+
Delete the mapping for the given key(s) or index(es) in a collection, and return
561+
the collection.
562+
"""
563+
function delete! end
564+
557565
function delete!(h::Dict, key)
558566
index = ht_keyindex(h, key)
559567
if index > 0

base/docs/helpdb/Base.jl

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,13 +1170,6 @@ The largest integer losslessly representable by the given floating-point DataTyp
11701170
"""
11711171
maxintfloat
11721172

1173-
"""
1174-
delete!(collection, key)
1175-
1176-
Delete the mapping for the given key in a collection, and return the collection.
1177-
"""
1178-
delete!
1179-
11801173
"""
11811174
eps(T)
11821175

base/event.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ function wait()
204204
end
205205
# return ourself to the runnable state
206206
i = findfirst(Workqueue, ct)
207-
i == 0 || deleteat!(Workqueue, i)
207+
i == 0 || delete!(Workqueue, i)
208208
ct.state = :runnable
209209
end
210210
rethrow(e)

base/exports.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,6 @@ export
708708
contains,
709709
count,
710710
delete!,
711-
deleteat!,
712711
eltype,
713712
empty!,
714713
endof,

base/expr.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ function popmeta!(body::Array{Any,1}, sym::Symbol)
230230
return false, []
231231
end
232232
ret = isa(metaargs[i], Expr) ? (metaargs[i]::Expr).args : []
233-
deleteat!(metaargs, i)
234-
isempty(metaargs) && deleteat!(blockargs, idx)
233+
delete!(metaargs, i)
234+
isempty(metaargs) && delete!(blockargs, idx)
235235
true, ret
236236
end
237237

0 commit comments

Comments
 (0)