Skip to content

Commit 56a125b

Browse files
committed
fix deprecations for 0.7
- use uninitialized for array constructors - parse -> Meta.parse - findfirst(x, v) -> findfirst(equalto(v), x) - some syntax deprecation warnings for parametric methods
1 parent 71e6001 commit 56a125b

18 files changed

+53
-48
lines changed

REQUIRE

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
julia 0.6
2+
Compat 0.39

src/DataStructures.jl

+12-8
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ module DataStructures
5252

5353
import Base: eachindex, keytype, valtype
5454

55-
_include_string(str) = eval(parse(str))
55+
@static if VERSION < v"0.7.0-DEV.2437"
56+
_include_string(str) = eval(parse(str))
57+
else
58+
_include_string(str) = eval(Meta.parse(str))
59+
end
5660

5761
include("delegate.jl")
5862

@@ -106,13 +110,13 @@ module DataStructures
106110
# Remove when Julia 0.7 (or whatever version is after v0.6) is released
107111
@deprecate DefaultDictBase(default, ks::AbstractArray, vs::AbstractArray) DefaultDictBase(default, zip(ks, vs))
108112
@deprecate DefaultDictBase(default, ks, vs) DefaultDictBase(default, zip(ks, vs))
109-
@deprecate DefaultDictBase{K,V}(::Type{K}, ::Type{V}, default) DefaultDictBase{K,V}(default)
113+
@deprecate DefaultDictBase(::Type{K}, ::Type{V}, default) where {K,V} DefaultDictBase{K,V}(default)
110114

111115
@deprecate DefaultDict(default, ks, vs) DefaultDict(default, zip(ks, vs))
112-
@deprecate DefaultDict{K,V}(::Type{K}, ::Type{V}, default) DefaultDict{K,V}(default)
116+
@deprecate DefaultDict(::Type{K}, ::Type{V}, default) where {K,V} DefaultDict{K,V}(default)
113117

114118
@deprecate DefaultOrderedDict(default, ks, vs) DefaultOrderedDict(default, zip(ks, vs))
115-
@deprecate DefaultOrderedDict{K,V}(::Type{K}, ::Type{V}, default) DefaultOrderedDict{K,V}(default)
119+
@deprecate DefaultOrderedDict(::Type{K}, ::Type{V}, default) where {K,V} DefaultOrderedDict{K,V}(default)
116120

117121
function SortedMultiDict(ks::AbstractVector{K},
118122
vs::AbstractVector{V},
@@ -124,10 +128,10 @@ module DataStructures
124128
SortedMultiDict(o, zip(ks,vs))
125129
end
126130

127-
@deprecate PriorityQueue{K,V}(::Type{K}, ::Type{V}) PriorityQueue{K,V}()
128-
@deprecate PriorityQueue{K,V}(::Type{K}, ::Type{V}, o::Ordering) PriorityQueue{K,V,typeof(o)}(o)
131+
@deprecate PriorityQueue(::Type{K}, ::Type{V}) where {K,V} PriorityQueue{K,V}()
132+
@deprecate PriorityQueue(::Type{K}, ::Type{V}, o::Ordering) where {K,V} PriorityQueue{K,V,typeof(o)}(o)
129133
@deprecate (PriorityQueue{K,V,ForwardOrdering}() where {K,V}) PriorityQueue{K,V}()
130-
134+
131135
function PriorityQueue(ks::AbstractVector{K},
132136
vs::AbstractVector{V},
133137
o::Ordering=Forward) where {K,V}
@@ -137,5 +141,5 @@ module DataStructures
137141
end
138142
PriorityQueue(o, zip(ks,vs))
139143
end
140-
144+
141145
end

src/balanced_tree.jl

+6-6
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,15 @@ mutable struct BalancedTree23{K, D, Ord <: Ordering}
125125
deletionchild::Array{Int,1}
126126
deletionleftkey::Array{K,1}
127127
function BalancedTree23{K,D,Ord}(ord1::Ord) where {K,D,Ord<:Ordering}
128-
tree1 = Vector{TreeNode{K}}(1)
128+
tree1 = Vector{TreeNode{K}}(uninitialized, 1)
129129
initializeTree!(tree1)
130-
data1 = Vector{KDRec{K,D}}(2)
130+
data1 = Vector{KDRec{K,D}}(uninitialized, 2)
131131
initializeData!(data1)
132132
u1 = IntSet()
133133
push!(u1, 1, 2)
134-
new{K,D,Ord}(ord1, data1, tree1, 1, 1, Vector{Int}(0), Vector{Int}(0),
134+
new{K,D,Ord}(ord1, data1, tree1, 1, 1, Vector{Int}(), Vector{Int}(),
135135
u1,
136-
Vector{Int}(3), Vector{K}(3))
136+
Vector{Int}(uninitialized, 3), Vector{K}(uninitialized, 3))
137137
end
138138
end
139139

@@ -243,8 +243,8 @@ function empty!(t::BalancedTree23)
243243
initializeTree!(t.tree)
244244
t.depth = 1
245245
t.rootloc = 1
246-
t.freetreeinds = Vector{Int}(0)
247-
t.freedatainds = Vector{Int}(0)
246+
t.freetreeinds = Vector{Int}()
247+
t.freedatainds = Vector{Int}()
248248
empty!(t.useddatacells)
249249
push!(t.useddatacells, 1, 2)
250250
nothing

src/circ_deque.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ mutable struct CircularDeque{T}
1111
last::Int
1212
end
1313

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

1616
Base.length(D::CircularDeque) = D.n
1717
Base.eltype(::Type{CircularDeque{T}}) where {T} = T

src/classified_collections.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ classified_lists(K::Type, V::Type) = ClassifiedCollections(K, Vector{V})
1616
classified_sets(K::Type, V::Type) = ClassifiedCollections(K, Set{V})
1717
classified_counters(K::Type, T::Type) = ClassifiedCollections(K, Accumulator{T, Int})
1818

19-
_create_empty(::Type{Vector{T}}) where {T} = Vector{T}(0)
19+
_create_empty(::Type{Vector{T}}) where {T} = Vector{T}()
2020
_create_empty(::Type{Set{T}}) where {T} = Set{T}()
2121
_create_empty(::Type{Accumulator{T,V}}) where {T,V} = Accumulator(T, V)
2222

src/delegate.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ macro delegate(source, targets)
1414
fieldname = unquote(source.args[2])
1515
funcnames = targets.args
1616
n = length(funcnames)
17-
fdefs = Vector{Any}(n)
17+
fdefs = Vector{Any}(uninitialized, n)
1818
for i in 1:n
1919
funcname = esc(funcnames[i])
2020
fdefs[i] = quote
@@ -30,7 +30,7 @@ macro delegate_return_parent(source, targets)
3030
fieldname = unquote(source.args[2])
3131
funcnames = targets.args
3232
n = length(funcnames)
33-
fdefs = Vector{Any}(n)
33+
fdefs = Vector{Any}(uninitialized, n)
3434
for i in 1:n
3535
funcname = esc(funcnames[i])
3636
fdefs[i] = quote

src/deque.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ mutable struct DequeBlock{T}
1414
next::DequeBlock{T} # ref to next block
1515

1616
function DequeBlock{T}(capa::Int, front::Int) where T
17-
data = Vector{T}(capa)
17+
data = Vector{T}(uninitialized, capa)
1818
blk = new{T}(data, capa, front, front-1)
1919
blk.prev = blk
2020
blk.next = blk

src/heaps.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ include("heaps/arrays_as_heaps.jl")
7171

7272
function extract_all!(h::AbstractHeap{VT}) where VT
7373
n = length(h)
74-
r = Vector{VT}(n)
74+
r = Vector{VT}(uninitialized, n)
7575
for i = 1 : n
7676
r[i] = pop!(h)
7777
end
@@ -80,7 +80,7 @@ end
8080

8181
function extract_all_rev!(h::AbstractHeap{VT}) where VT
8282
n = length(h)
83-
r = Vector{VT}(n)
83+
r = Vector{VT}(uninitialized, n)
8484
for i = 1 : n
8585
r[n + 1 - i] = pop!(h)
8686
end

src/heaps/binary_heap.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ mutable struct BinaryHeap{T,Comp} <: AbstractHeap{T}
107107
valtree::Vector{T}
108108

109109
function BinaryHeap{T,Comp}(comp::Comp) where {T,Comp}
110-
new{T,Comp}(comp, Vector{T}(0))
110+
new{T,Comp}(comp, Vector{T}())
111111
end
112112

113113
function BinaryHeap{T,Comp}(comp::Comp, xs) where {T,Comp} # xs is an iterable collection of values

src/heaps/mutable_binary_heap.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ function _make_mutable_binary_heap(comp::Comp, ty::Type{T}, values) where {Comp,
127127
# make a static binary index tree from a list of values
128128

129129
n = length(values)
130-
nodes = Vector{MutableBinaryHeapNode{T}}(n)
131-
nodemap = Vector{Int}(n)
130+
nodes = Vector{MutableBinaryHeapNode{T}}(uninitialized, n)
131+
nodemap = Vector{Int}(uninitialized, n)
132132

133133
i::Int = 0
134134
for v in values

src/int_set.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ end
1414
mutable struct IntSet
1515
bits::BitVector
1616
inverse::Bool
17-
IntSet() = new(fill!(BitVector(256), false), false)
17+
IntSet() = new(falses(256), false)
1818
end
1919
IntSet(itr) = union!(IntSet(), itr)
2020

src/ordered_dict.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ mutable struct OrderedDict{K,V} <: Associative{K,V}
2121
dirty::Bool
2222

2323
function OrderedDict{K,V}() where {K,V}
24-
new{K,V}(zeros(Int32,16), Vector{K}(0), Vector{V}(0), 0, false)
24+
new{K,V}(zeros(Int32,16), Vector{K}(), Vector{V}(), 0, false)
2525
end
2626
function OrderedDict{K,V}(kv) where {K,V}
2727
h = OrderedDict{K,V}()
@@ -56,8 +56,8 @@ copy(d::OrderedDict) = OrderedDict(d)
5656
# OrderedDict{K,V}(kv::Tuple{Vararg{Tuple{K,V}}}) = OrderedDict{K,V}(kv)
5757
# OrderedDict{K }(kv::Tuple{Vararg{Tuple{K,Any}}}) = OrderedDict{K,Any}(kv)
5858
# OrderedDict{V }(kv::Tuple{Vararg{Tuple{Any,V}}}) = OrderedDict{Any,V}(kv)
59-
_oldOrderedDict1 = "OrderedDict{V}(kv::Tuple{Vararg{Pair{TypeVar(:K),V}}}) = OrderedDict{Any,V}(kv)"
60-
_newOrderedDict1 = "OrderedDict{V}(kv::Tuple{Vararg{Pair{K,V} where K}}) = OrderedDict{Any,V}(kv)"
59+
_oldOrderedDict1 = "OrderedDict(kv::Tuple{Vararg{Pair{TypeVar(:K),V}}}) where {V} = OrderedDict{Any,V}(kv)"
60+
_newOrderedDict1 = "OrderedDict(kv::Tuple{Vararg{Pair{K,V} where K}}) where {V} = OrderedDict{Any,V}(kv)"
6161
OrderedDict(kv::Tuple{Vararg{Pair{K,V}}}) where {K,V} = OrderedDict{K,V}(kv)
6262
OrderedDict(kv::Tuple{Vararg{Pair{K}}}) where {K} = OrderedDict{K,Any}(kv)
6363
VERSION < v"0.6.0-dev.2123" ? _include_string(_oldOrderedDict1) : _include_string(_newOrderedDict1)
@@ -67,8 +67,8 @@ OrderedDict(kv::AbstractArray{Tuple{K,V}}) where {K,V} = OrderedDict{K,V}(kv)
6767
OrderedDict(kv::AbstractArray{Pair{K,V}}) where {K,V} = OrderedDict{K,V}(kv)
6868
OrderedDict(kv::Associative{K,V}) where {K,V} = OrderedDict{K,V}(kv)
6969

70-
_oldOrderedDict2 = "OrderedDict{V}(ps::Pair{TypeVar(:K),V}...,) = OrderedDict{Any,V}(ps)"
71-
_newOrderedDict2 = "OrderedDict{V}(ps::(Pair{K,V} where K)...,) = OrderedDict{Any,V}(ps)"
70+
_oldOrderedDict2 = "OrderedDict(ps::Pair{TypeVar(:K),V}...,) where {V} = OrderedDict{Any,V}(ps)"
71+
_newOrderedDict2 = "OrderedDict(ps::(Pair{K,V} where K)...,) where {V} = OrderedDict{Any,V}(ps)"
7272
OrderedDict(ps::Pair{K,V}...) where {K,V} = OrderedDict{K,V}(ps)
7373
OrderedDict(ps::Pair{K}...,) where {K} = OrderedDict{K,Any}(ps)
7474
VERSION < v"0.6.0-dev.2123" ? _include_string(_oldOrderedDict2) : _include_string(_newOrderedDict2)

src/priorityqueue.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ mutable struct PriorityQueue{K,V,O<:Ordering} <: Associative{K,V}
3232
index::Dict{K, Int}
3333

3434
function PriorityQueue{K,V,O}(o::O) where {K,V,O<:Ordering}
35-
new{K,V,O}(Vector{Pair{K,V}}(0), o, Dict{K, Int}())
35+
new{K,V,O}(Vector{Pair{K,V}}(), o, Dict{K, Int}())
3636
end
3737

3838
function PriorityQueue{K,V,O}(o::O, itr) where {K,V,O<:Ordering}
39-
xs = Vector{Pair{K,V}}(length(itr))
39+
xs = Vector{Pair{K,V}}(uninitialized, length(itr))
4040
index = Dict{K, Int}()
4141
for (i, (k, v)) in enumerate(itr)
4242
xs[i] = Pair{K,V}(k, v)
@@ -225,7 +225,7 @@ function enqueue!(pq::PriorityQueue{K,V}, pair::Pair{K,V}) where {K,V}
225225
push!(pq.xs, pair)
226226
pq.index[key] = length(pq)
227227
percolate_up!(pq, length(pq))
228-
228+
229229
return pq
230230
end
231231

test/runtests.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Base.Test
1+
using Compat.Test
22
using DataStructures
33
const IntSet = DataStructures.IntSet
44
using Primes

test/test_mutable_binheap.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function heap_values(h::MutableBinaryHeap{VT,Comp}) where {VT,Comp}
66
n = length(h)
77
nodes = h.nodes
88
@assert length(nodes) == n
9-
vs = Vector{VT}(n)
9+
vs = Vector{VT}(uninitialized, n)
1010
for i = 1 : n
1111
vs[i] = nodes[i].value
1212
end
@@ -17,7 +17,7 @@ function list_values(h::MutableBinaryHeap{VT,Comp}) where {VT,Comp}
1717
n = length(h)
1818
nodes = h.nodes
1919
nodemap = h.node_map
20-
vs = Vector{VT}(0)
20+
vs = Vector{VT}()
2121
for i = 1 : length(nodemap)
2222
id = nodemap[i]
2323
if id > 0

test/test_ordered_set.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@
136136

137137
# find
138138
s = OrderedSet([1,3,5,7])
139-
@test findfirst(s,1) == 1
140-
@test findfirst(s,7) == 4
141-
@test findfirst(s,2) == 0
139+
@test findfirst(equalto(1), s) == 1
140+
@test findfirst(equalto(7), s) == 4
141+
@test findfirst(equalto(2), s) == 0
142142

143143
# setdiff
144144
@test isequal(setdiff(OrderedSet([1,2,3]), OrderedSet()), OrderedSet([1,2,3]))

test/test_priority_queue.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function test_issorted!(pq::PriorityQueue, priorities, rev=false)
1414
@test priorities[last] <= priorities[value]
1515
else
1616
@test priorities[value] <= priorities[last]
17-
end
17+
end
1818
value = last
1919
end
2020
end
@@ -87,15 +87,15 @@ end
8787

8888
pq11 = PriorityQueue(Pair{Char}['a'=>1,'b'=>2])
8989
@test peek(pq11) == ('a'=>1)
90-
90+
9191
# duplicate key => ArgumentError
9292
@test_throws ArgumentError PriorityQueue('a'=>1, 'a'=>2)
9393

9494
# Not a pair/tuple => ArguentError
9595
@test_throws ArgumentError PriorityQueue(['a'])
9696
@test_throws ArgumentError PriorityQueue(Reverse, ['a'])
9797
@test_throws ArgumentError PriorityQueue{Char,Int}(Base.Order.Reverse, ['a'])
98-
98+
9999
# Silly test
100100
@test_throws ArgumentError PriorityQueue(Reverse, Reverse)
101101

@@ -139,7 +139,7 @@ end
139139
enqueue!(pq, kv)
140140
end
141141
test_issorted!(pq, priorities)
142-
142+
143143
# enqueing values via enqueue!
144144
pq = PriorityQueue()
145145
for (k, v) in priorities
@@ -199,7 +199,7 @@ end
199199
xs = heapify(10:-1:1)
200200
@test issorted([heappop!(xs) for _ in 1:10])
201201

202-
xs = Vector{Int}(0)
202+
xs = Vector{Int}()
203203
for priority in values(priorities)
204204
heappush!(xs, priority)
205205
end

test/test_sorted_containers.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ function checkcorrectness(t::DataStructures.BalancedTree23{K,D,Ord},
9696
dsz = size(t.data, 1)
9797
tsz = size(t.tree, 1)
9898
r = t.rootloc
99-
bfstreenodes = Vector{Int}(0)
99+
bfstreenodes = Vector{Int}()
100100
tdpth = t.depth
101101
intree = IntSet()
102-
levstart = Vector{Int}(tdpth)
102+
levstart = Vector{Int}(uninitialized, tdpth)
103103
push!(bfstreenodes, r)
104104
levstart[1] = 1
105105
push!(intree, r)
@@ -132,8 +132,8 @@ function checkcorrectness(t::DataStructures.BalancedTree23{K,D,Ord},
132132
end
133133
bfstreesize = size(bfstreenodes, 1)
134134
dataused = IntSet()
135-
minkeys = Vector{K}(bfstreesize)
136-
maxkeys = Vector{K}(bfstreesize)
135+
minkeys = Vector{K}(uninitialized, bfstreesize)
136+
maxkeys = Vector{K}(uninitialized, bfstreesize)
137137
for s = levstart[tdpth] : bfstreesize
138138
anc = bfstreenodes[s]
139139
c1 = t.tree[anc].child1

0 commit comments

Comments
 (0)