Skip to content

Commit

Permalink
Merge deleteat() into delete!() and deprecate it
Browse files Browse the repository at this point in the history
The generic definition of delete!() suits deleteat!() very well, and
the signatures do not conflict.
  • Loading branch information
nalimilan committed Feb 8, 2017
1 parent e24faa5 commit a6d4207
Show file tree
Hide file tree
Showing 25 changed files with 110 additions and 107 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ Deprecated or removed
* `produce`, `consume` and iteration over a Task object have been deprecated in favor of
using Channels for inter-task communication ([#19841]).
* `deleteat!` has been deprecated in favor of `delete!` ([#20531]).
<!--- generated by NEWS-update.jl: -->
[#265]: https://github.com/JuliaLang/julia/issues/265
[#7669]: https://github.com/JuliaLang/julia/issues/7669
Expand Down
22 changes: 11 additions & 11 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -767,13 +767,13 @@ function insert!{T}(a::Array{T,1}, i::Integer, item)
end

"""
deleteat!(a::Vector, i::Integer)
delete!(a::Vector, i::Integer)
Remove the item at the given `i` and return the modified `a`. Subsequent items
are shifted to fill the resulting gap.
```jldoctest
julia> deleteat!([6, 5, 4, 3, 2, 1], 2)
julia> delete!([6, 5, 4, 3, 2, 1], 2)
5-element Array{Int64,1}:
6
4
Expand All @@ -782,34 +782,34 @@ julia> deleteat!([6, 5, 4, 3, 2, 1], 2)
1
```
"""
deleteat!(a::Vector, i::Integer) = (_deleteat!(a, i, 1); a)
delete!(a::Vector, i::Integer) = (_deleteat!(a, i, 1); a)

function deleteat!{T<:Integer}(a::Vector, r::UnitRange{T})
function delete!{T<:Integer}(a::Vector, r::UnitRange{T})
n = length(a)
isempty(r) || _deleteat!(a, first(r), length(r))
return a
end

"""
deleteat!(a::Vector, inds)
delete!(a::Vector, inds)
Remove the items at the indices given by `inds`, and return the modified `a`.
Subsequent items are shifted to fill the resulting gap. `inds` must be sorted and unique.
```jldoctest
julia> deleteat!([6, 5, 4, 3, 2, 1], 1:2:5)
julia> delete!([6, 5, 4, 3, 2, 1], 1:2:5)
3-element Array{Int64,1}:
5
3
1
julia> deleteat!([6, 5, 4, 3, 2, 1], (2, 2))
julia> delete!([6, 5, 4, 3, 2, 1], (2, 2))
ERROR: ArgumentError: indices must be unique and sorted
Stacktrace:
[1] deleteat!(::Array{Int64,1}, ::Tuple{Int64,Int64}) at ./array.jl:808
[1] delete!(::Array{Int64,1}, ::Tuple{Int64,Int64}) at ./array.jl:822
```
"""
function deleteat!(a::Vector, inds)
function delete!(a::Vector, inds)
n = length(a)
s = start(inds)
done(inds, s) && return a
Expand Down Expand Up @@ -938,7 +938,7 @@ function splice!{T<:Integer}(a::Vector, r::UnitRange{T}, ins=_default_splice)
v = a[r]
m = length(ins)
if m == 0
deleteat!(a, r)
delete!(a, r)
return v
end

Expand Down Expand Up @@ -1746,7 +1746,7 @@ function filter!(f, a::Vector)
insrt += 1
end
end
deleteat!(a, insrt:length(a))
delete!(a, insrt:length(a))
return a
end

Expand Down
14 changes: 7 additions & 7 deletions base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ function resize!(B::BitVector, n::Integer)
n == n0 && return B
n >= 0 || throw(BoundsError(B, n))
if n < n0
deleteat!(B, n+1:n0)
delete!(B, n+1:n0)
return B
end
Bc = B.chunks
Expand Down Expand Up @@ -992,7 +992,7 @@ function insert!(B::BitVector, i::Integer, item)
B
end

function _deleteat!(B::BitVector, i::Integer)
function _delete!(B::BitVector, i::Integer)
k, j = get_chunks_id(i)

msk_bef = _msk64 >>> (63 - j)
Expand Down Expand Up @@ -1025,14 +1025,14 @@ function _deleteat!(B::BitVector, i::Integer)
return B
end

function deleteat!(B::BitVector, i::Integer)
function delete!(B::BitVector, i::Integer)
n = length(B)
1 <= i <= n || throw(BoundsError(B, i))

return _deleteat!(B, i)
return _delete!(B, i)
end

function deleteat!(B::BitVector, r::UnitRange{Int})
function delete!(B::BitVector, r::UnitRange{Int})
n = length(B)
i_f = first(r)
i_l = last(r)
Expand All @@ -1056,7 +1056,7 @@ function deleteat!(B::BitVector, r::UnitRange{Int})
return B
end

function deleteat!(B::BitVector, inds)
function delete!(B::BitVector, inds)
n = new_l = length(B)
s = start(inds)
done(inds, s) && return B
Expand Down Expand Up @@ -1099,7 +1099,7 @@ function splice!(B::BitVector, i::Integer)
1 <= i <= n || throw(BoundsError(B, i))

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

Expand Down
2 changes: 1 addition & 1 deletion base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ try_include(path::AbstractString) = isfile(path) && include(path)
function process_options(opts::JLOptions)
if !isempty(ARGS)
idxs = find(x -> x == "--", ARGS)
length(idxs) > 0 && deleteat!(ARGS, idxs[1])
length(idxs) > 0 && delete!(ARGS, idxs[1])
end
repl = true
startup = (opts.startupfile != 2)
Expand Down
6 changes: 4 additions & 2 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,8 @@ function gen_broadcast_body_zpreserving(f::Function, is_first_sparse::Bool)
end
B.colptr[col+1] = ptrB
end
deleteat!(B.rowval, B.colptr[end]:length(B.rowval))
deleteat!(B.nzval, B.colptr[end]:length(B.nzval))
delete!(B.rowval, B.colptr[end]:length(B.rowval))
delete!(B.nzval, B.colptr[end]:length(B.nzval))
nothing
end
end
Expand Down Expand Up @@ -1227,6 +1227,8 @@ for name in ("alnum", "alpha", "cntrl", "digit", "number", "graph",
@eval @deprecate ($f)(s::AbstractString) all($f, s)
end

@deprecate deleteat! delete!

# END 0.6 deprecations

# BEGIN 1.0 deprecations
Expand Down
8 changes: 8 additions & 0 deletions base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,14 @@ function _delete!(h::Dict, index)
return h
end

"""
delete!(collection, keys)
Delete the mapping for the given key(s) or index(es) in a collection, and return
the collection.
"""
function delete! end

function delete!(h::Dict, key)
index = ht_keyindex(h, key)
if index > 0
Expand Down
7 changes: 0 additions & 7 deletions base/docs/helpdb/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1170,13 +1170,6 @@ The largest integer losslessly representable by the given floating-point DataTyp
"""
maxintfloat

"""
delete!(collection, key)
Delete the mapping for the given key in a collection, and return the collection.
"""
delete!

"""
eps(T)
Expand Down
2 changes: 1 addition & 1 deletion base/event.jl
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ function wait()
end
# return ourself to the runnable state
i = findfirst(Workqueue, ct)
i == 0 || deleteat!(Workqueue, i)
i == 0 || delete!(Workqueue, i)
ct.state = :runnable
end
rethrow(e)
Expand Down
1 change: 0 additions & 1 deletion base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,6 @@ export
contains,
count,
delete!,
deleteat!,
eltype,
empty!,
endof,
Expand Down
4 changes: 2 additions & 2 deletions base/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ function popmeta!(body::Array{Any,1}, sym::Symbol)
return false, []
end
ret = isa(metaargs[i], Expr) ? (metaargs[i]::Expr).args : []
deleteat!(metaargs, i)
isempty(metaargs) && deleteat!(blockargs, idx)
delete!(metaargs, i)
isempty(metaargs) && delete!(blockargs, idx)
true, ret
end

Expand Down
8 changes: 4 additions & 4 deletions base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3066,8 +3066,8 @@ function type_annotate!(sv::InferenceState)
end
# This can create `Expr(:gotoifnot)` with dangling label, which we
# clean up in `reindex_labels!`
deleteat!(body, i)
deleteat!(states, i)
delete!(body, i)
delete!(states, i)
nexpr -= 1
continue
end
Expand Down Expand Up @@ -4898,7 +4898,7 @@ function alloc_elim_pass!(sv::InferenceState)
continue
end

deleteat!(body, i) # remove tuple allocation
delete!(body, i) # remove tuple allocation
# convert tuple allocation to a series of local var assignments
n_ins = 0
if var === nothing
Expand Down Expand Up @@ -4993,7 +4993,7 @@ function delete_void_use!(body, var::Slot, i0)
while i <= narg
a = body[i]
if isa(a, Slot) && slot_id(a) == slot_id(var)
deleteat!(body, i)
delete!(body, i)
if i + ndel < i0
ndel += 1
end
Expand Down
2 changes: 1 addition & 1 deletion base/methodshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function kwarg_decl(m::Method, kwtype::DataType)
i = findfirst(x -> endswith(string(x), "..."), kws)
i==0 && return kws
push!(kws, kws[i])
return deleteat!(kws,i)
return delete!(kws,i)
end
return ()
end
Expand Down
2 changes: 1 addition & 1 deletion base/path.jl
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ function normpath(path::String)
clean = true
for j = 1:length(parts)-1
if parts[j] != ".." && parts[j+1] == ".."
deleteat!(parts, j:j+1)
delete!(parts, j:j+1)
clean = false
break
end
Expand Down
2 changes: 1 addition & 1 deletion base/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ precompile(Base.convert, (Type{Module}, Module))
precompile(Base.convert, (Type{AbstractString}, String))
precompile(Base.copy!, (Array{Dict{Any, Any}, 1}, Int, Array{Dict{Any, Any}, 1}, Int, Int))
precompile(Base.copy, (Bool,))
precompile(Base.deleteat!, (Array{UInt8, 1}, Base.UnitRange{Int}))
precompile(Base.delete!, (Array{UInt8, 1}, Base.UnitRange{Int}))
precompile(Base.done, (Array{Base.LineEdit.TextInterface, 1}, Int))
precompile(Base.done, (Dict{Any,Any}, Int))
precompile(Base.done, (Dict{Symbol,Any}, Int))
Expand Down
2 changes: 1 addition & 1 deletion base/printf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function parse(s::AbstractString)
end
list[i] *= list[j]
end
deleteat!(list,i+1:j)
delete!(list,i+1:j)
end
i += 1
end
Expand Down
12 changes: 6 additions & 6 deletions base/sparse/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ function spmatmul{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}, B::SparseMatrixCSC{Tv,Ti};
colptrC[nB+1] = ip
end

deleteat!(rowvalC, colptrC[end]:length(rowvalC))
deleteat!(nzvalC, colptrC[end]:length(nzvalC))
delete!(rowvalC, colptrC[end]:length(rowvalC))
delete!(nzvalC, colptrC[end]:length(nzvalC))

# The Gustavson algorithm does not guarantee the product to have sorted row indices.
Cunsorted = SparseMatrixCSC(mA, nB, colptrC, rowvalC, nzvalC)
Expand Down Expand Up @@ -394,8 +394,8 @@ function sparse_diff1{Tv,Ti}(S::SparseMatrixCSC{Tv,Ti})
end
colptr[col+1] = numnz+1
end
deleteat!(rowval, numnz+1:length(rowval))
deleteat!(nzval, numnz+1:length(nzval))
delete!(rowval, numnz+1:length(rowval))
delete!(nzval, numnz+1:length(nzval))
return SparseMatrixCSC(m-1, n, colptr, rowval, nzval)
end

Expand Down Expand Up @@ -483,8 +483,8 @@ function sparse_diff2{Tv,Ti}(a::SparseMatrixCSC{Tv,Ti})

colptr[col+1] = ptrS
end
deleteat!(rowval, ptrS:length(rowval))
deleteat!(nzval, ptrS:length(nzval))
delete!(rowval, ptrS:length(rowval))
delete!(nzval, ptrS:length(nzval))
return SparseMatrixCSC(m, n-1, colptr, rowval, nzval)
end

Expand Down
Loading

0 comments on commit a6d4207

Please sign in to comment.