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 constructors
  - parse -> Meta.parse
  - findfirst(x, v) -> findfirst(equalto(v), x)
  - some syntax deprecation warnings for parametric methods
  • Loading branch information
fredrikekre committed Dec 2, 2017
1 parent 71e6001 commit 56a125b
Show file tree
Hide file tree
Showing 18 changed files with 53 additions and 48 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
20 changes: 12 additions & 8 deletions src/DataStructures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,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 +110,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 +128,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 +141,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
4 changes: 2 additions & 2 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
2 changes: 1 addition & 1 deletion 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
10 changes: 5 additions & 5 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,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
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
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Base.Test
using Compat.Test
using DataStructures
const IntSet = DataStructures.IntSet
using Primes
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
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
8 changes: 4 additions & 4 deletions test/test_sorted_containers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ function checkcorrectness(t::DataStructures.BalancedTree23{K,D,Ord},
dsz = size(t.data, 1)
tsz = size(t.tree, 1)
r = t.rootloc
bfstreenodes = Vector{Int}(0)
bfstreenodes = Vector{Int}()
tdpth = t.depth
intree = IntSet()
levstart = Vector{Int}(tdpth)
levstart = Vector{Int}(uninitialized, tdpth)
push!(bfstreenodes, r)
levstart[1] = 1
push!(intree, r)
Expand Down Expand Up @@ -132,8 +132,8 @@ function checkcorrectness(t::DataStructures.BalancedTree23{K,D,Ord},
end
bfstreesize = size(bfstreenodes, 1)
dataused = IntSet()
minkeys = Vector{K}(bfstreesize)
maxkeys = Vector{K}(bfstreesize)
minkeys = Vector{K}(uninitialized, bfstreesize)
maxkeys = Vector{K}(uninitialized, bfstreesize)
for s = levstart[tdpth] : bfstreesize
anc = bfstreenodes[s]
c1 = t.tree[anc].child1
Expand Down

0 comments on commit 56a125b

Please sign in to comment.