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
  • Loading branch information
fredrikekre committed Dec 6, 2017
1 parent 8aa166e commit ef72847
Show file tree
Hide file tree
Showing 21 changed files with 60 additions and 75 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
18 changes: 9 additions & 9 deletions src/DataStructures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ module DataStructures
union, intersect, symdiff, setdiff, issubset,
find, searchsortedfirst, searchsortedlast, endof, in

import Compat.uninitialized

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,8 +54,6 @@ module DataStructures

import Base: eachindex, keytype, valtype

_include_string(str) = eval(parse(str))

include("delegate.jl")

include("deque.jl")
Expand Down Expand Up @@ -106,13 +106,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 +124,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 +137,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
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
18 changes: 7 additions & 11 deletions src/ordered_dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,23 +56,19 @@ 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)"
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)
OrderedDict(kv::Tuple{Vararg{Pair}}) = OrderedDict{Any,Any}(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)
OrderedDict(kv::Tuple{Vararg{Pair{K,V} where K}}) where {V} = OrderedDict{Any,V}(kv)
OrderedDict(kv::Tuple{Vararg{Pair}}) = OrderedDict{Any,Any}(kv)

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)"
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)
OrderedDict(ps::Pair...) = OrderedDict{Any,Any}(ps)
OrderedDict(ps::(Pair{K,V} where K)...,) where {V} = OrderedDict{Any,V}(ps)
OrderedDict(ps::Pair...) = OrderedDict{Any,Any}(ps)

function OrderedDict(kv)
try
Expand Down
12 changes: 4 additions & 8 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 @@ -104,11 +104,7 @@ _priority_queue_with_eltype(o::Ord, kv, ::Type ) where { Ord} = Pr

## TODO: It seems impossible (or at least very challenging) to create the eltype below.
## If deemed possible, please create a test and uncomment this definition.
# if VERSION < v"0.6.0-dev.2123"
# _priority_queue_with_eltype{ D,Ord}(o::Ord, ps, ::Type{Pair{TypeVar(:K),D}}) = PriorityQueue{Any, D,Ord}(o, ps)
# else
# _include_string("_priority_queue_with_eltype{ D,Ord}(o::Ord, ps, ::Type{Pair{K,V} where K}) = PriorityQueue{Any, D,Ord}(o, ps)")
# end
# _priority_queue_with_eltype{ D,Ord}(o::Ord, ps, ::Type{Pair{K,V} where K}) = PriorityQueue{Any, D,Ord}(o, ps)

length(pq::PriorityQueue) = length(pq.xs)
isempty(pq::PriorityQueue) = isempty(pq.xs)
Expand Down Expand Up @@ -225,7 +221,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
6 changes: 1 addition & 5 deletions src/sorted_dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,7 @@ _sorted_dict_with_eltype(o::Ord, kv, ::Type ) where { Ord} = Sorte

## TODO: It seems impossible (or at least very challenging) to create the eltype below.
## If deemed possible, please create a test and uncomment this definition.
# if VERSION < v"0.6.0-dev.2123"
# _sorted_dict_with_eltype{ D,Ord}(o::Ord, ps, ::Type{Pair{TypeVar(:K),D}}) = SortedDict{Any, D,Ord}(o, ps)
# else
# _include_string("_sorted_dict_with_eltype{ D,Ord}(o::Ord, ps, ::Type{Pair{K,D} where K}) = SortedDict{Any, D,Ord}(o, ps)")
# end
# _sorted_dict_with_eltype{ D,Ord}(o::Ord, ps, ::Type{Pair{K,D} where K}) = SortedDict{Any, D,Ord}(o, ps)

const SDSemiToken = IntSemiToken

Expand Down
6 changes: 1 addition & 5 deletions src/sorted_multi_dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,7 @@ _sorted_multidict_with_eltype(o::Ord, kv, ::Type ) where { Ord} =

## TODO: It seems impossible (or at least very challenging) to create the eltype below.
## If deemed possible, please create a test and uncomment this definition.
# if VERSION < v"0.6.0-dev.2123"
# _sorted_multi_dict_with_eltype{ D,Ord}(o::Ord, ps, ::Type{Pair{TypeVar(:K),D}}) = SortedMultiDict{Any, D,Ord}(o, ps)
# else
# _include_string("_sorted_multi_dict_with_eltype{ D,Ord}(o::Ord, ps, ::Type{Pair{K,D} where K}) = SortedMultiDict{Any, D,Ord}(o, ps)")
# end
# _sorted_multi_dict_with_eltype{ D,Ord}(o::Ord, ps, ::Type{Pair{K,D} where K}) = SortedMultiDict{Any, D,Ord}(o, ps)

const SMDSemiToken = IntSemiToken

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
10 changes: 5 additions & 5 deletions test/test_priority_queue.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function test_issorted!(pq::PriorityQueue, priorities, rev=false)
@test priorities[last] <= priorities[value]
else
@test priorities[value] <= priorities[last]
end
end
value = last
end
end
Expand Down Expand Up @@ -87,15 +87,15 @@ end

pq11 = PriorityQueue(Pair{Char}['a'=>1,'b'=>2])
@test peek(pq11) == ('a'=>1)

# duplicate key => ArgumentError
@test_throws ArgumentError PriorityQueue('a'=>1, 'a'=>2)

# Not a pair/tuple => ArguentError
@test_throws ArgumentError PriorityQueue(['a'])
@test_throws ArgumentError PriorityQueue(Reverse, ['a'])
@test_throws ArgumentError PriorityQueue{Char,Int}(Base.Order.Reverse, ['a'])

# Silly test
@test_throws ArgumentError PriorityQueue(Reverse, Reverse)

Expand Down Expand Up @@ -139,7 +139,7 @@ end
enqueue!(pq, kv)
end
test_issorted!(pq, priorities)

# enqueing values via enqueue!
pq = PriorityQueue()
for (k, v) in priorities
Expand Down Expand Up @@ -199,7 +199,7 @@ end
xs = heapify(10:-1:1)
@test issorted([heappop!(xs) for _ in 1:10])

xs = Vector{Int}(0)
xs = Vector{Int}()
for priority in values(priorities)
heappush!(xs, priority)
end
Expand Down
Loading

0 comments on commit ef72847

Please sign in to comment.