Skip to content

Commit

Permalink
fix deprecations for 0.7
Browse files Browse the repository at this point in the history
  - use uninitialized for Array and BitArray constructors
  - parse -> Meta.parse
  - findfirst(x, v) -> findfirst(equalto(v), x)
  - some syntax deprecation warnings for parametric methods
  - KeyIterator{T} -> KeySet{K,T}
  • Loading branch information
fredrikekre committed Dec 3, 2017
1 parent 71e6001 commit fd742b0
Show file tree
Hide file tree
Showing 20 changed files with 72 additions and 60 deletions.
1 change: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
julia 0.6
Compat 0.39
27 changes: 19 additions & 8 deletions src/DataStructures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ module DataStructures
union, intersect, symdiff, setdiff, issubset,
find, searchsortedfirst, searchsortedlast, endof, in

import Compat.uninitialized
@static if !isdefined(Base, :KeySet) # https://github.com/JuliaLang/julia/pull/24580
const KeySet{K,T<:Associative{K}} = Base.KeyIterator{T}
else
import Base.KeySet
end

export Deque, Stack, Queue, CircularDeque
export deque, enqueue!, dequeue!, dequeue_pair!, update!, reverse_iter
export capacity, num_blocks, front, back, top, top_with_handle, sizehint!
Expand Down Expand Up @@ -52,7 +59,11 @@ module DataStructures

import Base: eachindex, keytype, valtype

_include_string(str) = eval(parse(str))
@static if VERSION < v"0.7.0-DEV.2437"
_include_string(str) = eval(parse(str))
else
_include_string(str) = eval(Meta.parse(str))
end

include("delegate.jl")

Expand Down Expand Up @@ -106,13 +117,13 @@ module DataStructures
# Remove when Julia 0.7 (or whatever version is after v0.6) is released
@deprecate DefaultDictBase(default, ks::AbstractArray, vs::AbstractArray) DefaultDictBase(default, zip(ks, vs))
@deprecate DefaultDictBase(default, ks, vs) DefaultDictBase(default, zip(ks, vs))
@deprecate DefaultDictBase{K,V}(::Type{K}, ::Type{V}, default) DefaultDictBase{K,V}(default)
@deprecate DefaultDictBase(::Type{K}, ::Type{V}, default) where {K,V} DefaultDictBase{K,V}(default)

@deprecate DefaultDict(default, ks, vs) DefaultDict(default, zip(ks, vs))
@deprecate DefaultDict{K,V}(::Type{K}, ::Type{V}, default) DefaultDict{K,V}(default)
@deprecate DefaultDict(::Type{K}, ::Type{V}, default) where {K,V} DefaultDict{K,V}(default)

@deprecate DefaultOrderedDict(default, ks, vs) DefaultOrderedDict(default, zip(ks, vs))
@deprecate DefaultOrderedDict{K,V}(::Type{K}, ::Type{V}, default) DefaultOrderedDict{K,V}(default)
@deprecate DefaultOrderedDict(::Type{K}, ::Type{V}, default) where {K,V} DefaultOrderedDict{K,V}(default)

function SortedMultiDict(ks::AbstractVector{K},
vs::AbstractVector{V},
Expand All @@ -124,10 +135,10 @@ module DataStructures
SortedMultiDict(o, zip(ks,vs))
end

@deprecate PriorityQueue{K,V}(::Type{K}, ::Type{V}) PriorityQueue{K,V}()
@deprecate PriorityQueue{K,V}(::Type{K}, ::Type{V}, o::Ordering) PriorityQueue{K,V,typeof(o)}(o)
@deprecate PriorityQueue(::Type{K}, ::Type{V}) where {K,V} PriorityQueue{K,V}()
@deprecate PriorityQueue(::Type{K}, ::Type{V}, o::Ordering) where {K,V} PriorityQueue{K,V,typeof(o)}(o)
@deprecate (PriorityQueue{K,V,ForwardOrdering}() where {K,V}) PriorityQueue{K,V}()

function PriorityQueue(ks::AbstractVector{K},
vs::AbstractVector{V},
o::Ordering=Forward) where {K,V}
Expand All @@ -137,5 +148,5 @@ module DataStructures
end
PriorityQueue(o, zip(ks,vs))
end

end
12 changes: 6 additions & 6 deletions src/balanced_tree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,15 @@ mutable struct BalancedTree23{K, D, Ord <: Ordering}
deletionchild::Array{Int,1}
deletionleftkey::Array{K,1}
function BalancedTree23{K,D,Ord}(ord1::Ord) where {K,D,Ord<:Ordering}
tree1 = Vector{TreeNode{K}}(1)
tree1 = Vector{TreeNode{K}}(uninitialized, 1)
initializeTree!(tree1)
data1 = Vector{KDRec{K,D}}(2)
data1 = Vector{KDRec{K,D}}(uninitialized, 2)
initializeData!(data1)
u1 = IntSet()
push!(u1, 1, 2)
new{K,D,Ord}(ord1, data1, tree1, 1, 1, Vector{Int}(0), Vector{Int}(0),
new{K,D,Ord}(ord1, data1, tree1, 1, 1, Vector{Int}(), Vector{Int}(),
u1,
Vector{Int}(3), Vector{K}(3))
Vector{Int}(uninitialized, 3), Vector{K}(uninitialized, 3))
end
end

Expand Down Expand Up @@ -243,8 +243,8 @@ function empty!(t::BalancedTree23)
initializeTree!(t.tree)
t.depth = 1
t.rootloc = 1
t.freetreeinds = Vector{Int}(0)
t.freedatainds = Vector{Int}(0)
t.freetreeinds = Vector{Int}()
t.freedatainds = Vector{Int}()
empty!(t.useddatacells)
push!(t.useddatacells, 1, 2)
nothing
Expand Down
2 changes: 1 addition & 1 deletion src/circ_deque.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mutable struct CircularDeque{T}
last::Int
end

CircularDeque{T}(n::Int) where {T} = CircularDeque(Vector{T}(n), n, 0, 1, n)
CircularDeque{T}(n::Int) where {T} = CircularDeque(Vector{T}(uninitialized, n), n, 0, 1, n)

Base.length(D::CircularDeque) = D.n
Base.eltype(::Type{CircularDeque{T}}) where {T} = T
Expand Down
2 changes: 1 addition & 1 deletion src/classified_collections.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ classified_lists(K::Type, V::Type) = ClassifiedCollections(K, Vector{V})
classified_sets(K::Type, V::Type) = ClassifiedCollections(K, Set{V})
classified_counters(K::Type, T::Type) = ClassifiedCollections(K, Accumulator{T, Int})

_create_empty(::Type{Vector{T}}) where {T} = Vector{T}(0)
_create_empty(::Type{Vector{T}}) where {T} = Vector{T}()
_create_empty(::Type{Set{T}}) where {T} = Set{T}()
_create_empty(::Type{Accumulator{T,V}}) where {T,V} = Accumulator(T, V)

Expand Down
8 changes: 4 additions & 4 deletions src/default_dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ DefaultDictBase{K,V}(default::F) where {K,V,F} = DefaultDictBase{K,V,F,Dict{K,V}
@delegate_return_parent DefaultDictBase.d [ delete!, empty!, setindex!, sizehint! ]

similar(d::DefaultDictBase{K,V,F}) where {K,V,F} = DefaultDictBase{K,V,F}(d.default)
in(key, v::Base.KeyIterator{T}) where {T<:DefaultDictBase} = key in keys(v.dict.d)
next(v::Base.KeyIterator{T}, i) where {T<:DefaultDictBase} = (v.dict.d.keys[i], Base.skip_deleted(v.dict.d,i+1))
in(key, v::KeySet{<:Any,T}) where {T<:DefaultDictBase} = key in keys(v.dict.d)
next(v::KeySet{<:Any,T}, i) where {T<:DefaultDictBase} = (v.dict.d.keys[i], Base.skip_deleted(v.dict.d,i+1))
next(v::Base.ValueIterator{T}, i) where {T<:DefaultDictBase} = (v.dict.d.vals[i], Base.skip_deleted(v.dict.d,i+1))

getindex(d::DefaultDictBase, key) = get!(d.d, key, d.default)
Expand Down Expand Up @@ -138,7 +138,7 @@ for _Dict in [:Dict, :OrderedDict]
push!(d::$DefaultDict, p, q, r...) = push!(push!(push!(d, p), q), r...)

similar(d::$DefaultDict{K,V,F}) where {K,V,F} = $DefaultDict{K,V,F}(d.d.default)
in(key, v::Base.KeyIterator{T}) where {T<:$DefaultDict} = key in keys(v.dict.d.d)
in(key, v::KeySet{<:Any,T}) where {T<:$DefaultDict} = key in keys(v.dict.d.d)
end
end

Expand Down Expand Up @@ -182,4 +182,4 @@ isordered(::Type{T}) where {T<:DefaultOrderedDict} = true
# @delegate_return_parent DefaultSortedDict.d [ delete!, empty!, setindex!, sizehint! ]

# similar{K,V,F}(d::DefaultSortedDict{K,V,F}) = DefaultSortedDict{K,V,F}(d.d.default)
# in{T<:DefaultSortedDict}(key, v::Base.KeyIterator{T}) = key in keys(v.dict.d.d)
# in{T<:DefaultSortedDict}(key, v::KeySet{<:Any,T}) = key in keys(v.dict.d.d)
4 changes: 2 additions & 2 deletions src/delegate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ macro delegate(source, targets)
fieldname = unquote(source.args[2])
funcnames = targets.args
n = length(funcnames)
fdefs = Vector{Any}(n)
fdefs = Vector{Any}(uninitialized, n)
for i in 1:n
funcname = esc(funcnames[i])
fdefs[i] = quote
Expand All @@ -30,7 +30,7 @@ macro delegate_return_parent(source, targets)
fieldname = unquote(source.args[2])
funcnames = targets.args
n = length(funcnames)
fdefs = Vector{Any}(n)
fdefs = Vector{Any}(uninitialized, n)
for i in 1:n
funcname = esc(funcnames[i])
fdefs[i] = quote
Expand Down
2 changes: 1 addition & 1 deletion src/deque.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mutable struct DequeBlock{T}
next::DequeBlock{T} # ref to next block

function DequeBlock{T}(capa::Int, front::Int) where T
data = Vector{T}(capa)
data = Vector{T}(uninitialized, capa)
blk = new{T}(data, capa, front, front-1)
blk.prev = blk
blk.next = blk
Expand Down
4 changes: 2 additions & 2 deletions src/heaps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ include("heaps/arrays_as_heaps.jl")

function extract_all!(h::AbstractHeap{VT}) where VT
n = length(h)
r = Vector{VT}(n)
r = Vector{VT}(uninitialized, n)
for i = 1 : n
r[i] = pop!(h)
end
Expand All @@ -80,7 +80,7 @@ end

function extract_all_rev!(h::AbstractHeap{VT}) where VT
n = length(h)
r = Vector{VT}(n)
r = Vector{VT}(uninitialized, n)
for i = 1 : n
r[n + 1 - i] = pop!(h)
end
Expand Down
2 changes: 1 addition & 1 deletion src/heaps/binary_heap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ mutable struct BinaryHeap{T,Comp} <: AbstractHeap{T}
valtree::Vector{T}

function BinaryHeap{T,Comp}(comp::Comp) where {T,Comp}
new{T,Comp}(comp, Vector{T}(0))
new{T,Comp}(comp, Vector{T}())
end

function BinaryHeap{T,Comp}(comp::Comp, xs) where {T,Comp} # xs is an iterable collection of values
Expand Down
8 changes: 4 additions & 4 deletions src/heaps/mutable_binary_heap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ function _make_mutable_binary_heap(comp::Comp, ty::Type{T}, values) where {Comp,
# make a static binary index tree from a list of values

n = length(values)
nodes = Vector{MutableBinaryHeapNode{T}}(n)
nodemap = Vector{Int}(n)
nodes = Vector{MutableBinaryHeapNode{T}}(uninitialized, n)
nodemap = Vector{Int}(uninitialized, n)

i::Int = 0
for v in values
Expand Down Expand Up @@ -156,8 +156,8 @@ mutable struct MutableBinaryHeap{VT, Comp} <: AbstractMutableHeap{VT,Int}
node_map::Vector{Int}

function MutableBinaryHeap{VT, Comp}(comp::Comp) where {VT, Comp}
nodes = Vector{MutableBinaryHeapNode{VT}}(0)
node_map = Vector{Int}(0)
nodes = Vector{MutableBinaryHeapNode{VT}}()
node_map = Vector{Int}()
new{VT, Comp}(comp, nodes, node_map)
end

Expand Down
4 changes: 2 additions & 2 deletions src/int_set.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ end
mutable struct IntSet
bits::BitVector
inverse::Bool
IntSet() = new(fill!(BitVector(256), false), false)
IntSet() = new(falses(256), false)
end
IntSet(itr) = union!(IntSet(), itr)

Expand Down Expand Up @@ -63,7 +63,7 @@ function _matchlength!(b::BitArray, newlen::Integer)
len = length(b)
len > newlen && return splice!(b, newlen+1:len)
len < newlen && _resize0!(b, newlen)
return BitVector(0)
return BitVector()
end

const _intset_bounds_err_msg = "elements of IntSet must be between 0 and typemax(Int)-1"
Expand Down
16 changes: 8 additions & 8 deletions src/ordered_dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Base: haskey, get, get!, getkey, delete!, push!, pop!, empty!,
setindex!, getindex, length, isempty, start,
next, done, keys, values, setdiff, setdiff!,
union, union!, intersect, filter, filter!,
hash, eltype, KeyIterator, ValueIterator, convert, copy,
hash, eltype, ValueIterator, convert, copy,
merge

"""
Expand All @@ -21,7 +21,7 @@ mutable struct OrderedDict{K,V} <: Associative{K,V}
dirty::Bool

function OrderedDict{K,V}() where {K,V}
new{K,V}(zeros(Int32,16), Vector{K}(0), Vector{V}(0), 0, false)
new{K,V}(zeros(Int32,16), Vector{K}(), Vector{V}(), 0, false)
end
function OrderedDict{K,V}(kv) where {K,V}
h = OrderedDict{K,V}()
Expand Down Expand Up @@ -56,8 +56,8 @@ copy(d::OrderedDict) = OrderedDict(d)
# OrderedDict{K,V}(kv::Tuple{Vararg{Tuple{K,V}}}) = OrderedDict{K,V}(kv)
# OrderedDict{K }(kv::Tuple{Vararg{Tuple{K,Any}}}) = OrderedDict{K,Any}(kv)
# OrderedDict{V }(kv::Tuple{Vararg{Tuple{Any,V}}}) = OrderedDict{Any,V}(kv)
_oldOrderedDict1 = "OrderedDict{V}(kv::Tuple{Vararg{Pair{TypeVar(:K),V}}}) = OrderedDict{Any,V}(kv)"
_newOrderedDict1 = "OrderedDict{V}(kv::Tuple{Vararg{Pair{K,V} where K}}) = OrderedDict{Any,V}(kv)"
_oldOrderedDict1 = "OrderedDict(kv::Tuple{Vararg{Pair{TypeVar(:K),V}}}) where {V} = OrderedDict{Any,V}(kv)"
_newOrderedDict1 = "OrderedDict(kv::Tuple{Vararg{Pair{K,V} where K}}) where {V} = OrderedDict{Any,V}(kv)"
OrderedDict(kv::Tuple{Vararg{Pair{K,V}}}) where {K,V} = OrderedDict{K,V}(kv)
OrderedDict(kv::Tuple{Vararg{Pair{K}}}) where {K} = OrderedDict{K,Any}(kv)
VERSION < v"0.6.0-dev.2123" ? _include_string(_oldOrderedDict1) : _include_string(_newOrderedDict1)
Expand All @@ -67,8 +67,8 @@ OrderedDict(kv::AbstractArray{Tuple{K,V}}) where {K,V} = OrderedDict{K,V}(kv)
OrderedDict(kv::AbstractArray{Pair{K,V}}) where {K,V} = OrderedDict{K,V}(kv)
OrderedDict(kv::Associative{K,V}) where {K,V} = OrderedDict{K,V}(kv)

_oldOrderedDict2 = "OrderedDict{V}(ps::Pair{TypeVar(:K),V}...,) = OrderedDict{Any,V}(ps)"
_newOrderedDict2 = "OrderedDict{V}(ps::(Pair{K,V} where K)...,) = OrderedDict{Any,V}(ps)"
_oldOrderedDict2 = "OrderedDict(ps::Pair{TypeVar(:K),V}...,) where {V} = OrderedDict{Any,V}(ps)"
_newOrderedDict2 = "OrderedDict(ps::(Pair{K,V} where K)...,) where {V} = OrderedDict{Any,V}(ps)"
OrderedDict(ps::Pair{K,V}...) where {K,V} = OrderedDict{K,V}(ps)
OrderedDict(ps::Pair{K}...,) where {K} = OrderedDict{K,Any}(ps)
VERSION < v"0.6.0-dev.2123" ? _include_string(_oldOrderedDict2) : _include_string(_newOrderedDict2)
Expand Down Expand Up @@ -376,7 +376,7 @@ function get(default::Base.Callable, h::OrderedDict{K,V}, key) where {K,V}
end

haskey(h::OrderedDict, key) = (ht_keyindex(h, key, true) >= 0)
in(key, v::KeyIterator{T}) where {T<:OrderedDict} = (ht_keyindex(v.dict, key, true) >= 0)
in(key, v::KeySet{<:Any,T}) where {T<:OrderedDict} = (ht_keyindex(v.dict, key, true) >= 0)

function getkey(h::OrderedDict{K,V}, key, default) where {K,V}
index = ht_keyindex(h, key, true)
Expand Down Expand Up @@ -429,7 +429,7 @@ end
done(t::OrderedDict, i) = done(t.keys, i)
next(t::OrderedDict, i) = (Pair(t.keys[i],t.vals[i]), i+1)

next(v::KeyIterator{T}, i) where {T<:OrderedDict} = (v.dict.keys[i], i+1)
next(v::KeySet{<:Any,T}, i) where {T<:OrderedDict} = (v.dict.keys[i], i+1)
next(v::ValueIterator{T}, i) where {T<:OrderedDict} = (v.dict.vals[i], i+1)

function merge(d::OrderedDict, others::Associative...)
Expand Down
6 changes: 3 additions & 3 deletions src/priorityqueue.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ mutable struct PriorityQueue{K,V,O<:Ordering} <: Associative{K,V}
index::Dict{K, Int}

function PriorityQueue{K,V,O}(o::O) where {K,V,O<:Ordering}
new{K,V,O}(Vector{Pair{K,V}}(0), o, Dict{K, Int}())
new{K,V,O}(Vector{Pair{K,V}}(), o, Dict{K, Int}())
end

function PriorityQueue{K,V,O}(o::O, itr) where {K,V,O<:Ordering}
xs = Vector{Pair{K,V}}(length(itr))
xs = Vector{Pair{K,V}}(uninitialized, length(itr))
index = Dict{K, Int}()
for (i, (k, v)) in enumerate(itr)
xs[i] = Pair{K,V}(k, v)
Expand Down Expand Up @@ -225,7 +225,7 @@ function enqueue!(pq::PriorityQueue{K,V}, pair::Pair{K,V}) where {K,V}
push!(pq.xs, pair)
pq.index[key] = length(pq)
percolate_up!(pq, length(pq))

return pq
end

Expand Down
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Base.Test
using Compat.Test
using DataStructures
const IntSet = DataStructures.IntSet
using Primes
using Primes, Compat

@test isempty(detect_ambiguities(Base, Core, DataStructures))

Expand Down
4 changes: 2 additions & 2 deletions test/test_mutable_binheap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function heap_values(h::MutableBinaryHeap{VT,Comp}) where {VT,Comp}
n = length(h)
nodes = h.nodes
@assert length(nodes) == n
vs = Vector{VT}(n)
vs = Vector{VT}(uninitialized, n)
for i = 1 : n
vs[i] = nodes[i].value
end
Expand All @@ -17,7 +17,7 @@ function list_values(h::MutableBinaryHeap{VT,Comp}) where {VT,Comp}
n = length(h)
nodes = h.nodes
nodemap = h.node_map
vs = Vector{VT}(0)
vs = Vector{VT}()
for i = 1 : length(nodemap)
id = nodemap[i]
if id > 0
Expand Down
2 changes: 1 addition & 1 deletion test/test_ordered_dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@

let _d = OrderedDict([("a", 0)])
v = [k for k in filter(x->length(x)==1, collect(keys(_d)))]
@test isa(v, Vector{String}) || isa(v, Vector{ASCIIString})
@test isa(v, Vector{String})
end

let d = OrderedDict(((1, 2), (3, 4))),
Expand Down
6 changes: 3 additions & 3 deletions test/test_ordered_set.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@

# find
s = OrderedSet([1,3,5,7])
@test findfirst(s,1) == 1
@test findfirst(s,7) == 4
@test findfirst(s,2) == 0
@test findfirst(equalto(1), s) == 1
@test findfirst(equalto(7), s) == 4
@test findfirst(equalto(2), s) == 0

# setdiff
@test isequal(setdiff(OrderedSet([1,2,3]), OrderedSet()), OrderedSet([1,2,3]))
Expand Down
Loading

0 comments on commit fd742b0

Please sign in to comment.