Skip to content

Commit aa3460b

Browse files
committed
fix deprecations for 0.7
- use uninitialized for Array and BitArray constructors - parse -> Meta.parse - findfirst(x, v) -> findfirst(equalto(v), x) - some syntax deprecation warnings for parametric methods
1 parent 8aa166e commit aa3460b

19 files changed

+55
-52
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

+9-7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ module DataStructures
1616
union, intersect, symdiff, setdiff, issubset,
1717
find, searchsortedfirst, searchsortedlast, endof, in
1818

19+
import Compat.uninitialized
20+
1921
export Deque, Stack, Queue, CircularDeque
2022
export deque, enqueue!, dequeue!, dequeue_pair!, update!, reverse_iter
2123
export capacity, num_blocks, front, back, top, top_with_handle, sizehint!
@@ -106,13 +108,13 @@ module DataStructures
106108
# Remove when Julia 0.7 (or whatever version is after v0.6) is released
107109
@deprecate DefaultDictBase(default, ks::AbstractArray, vs::AbstractArray) DefaultDictBase(default, zip(ks, vs))
108110
@deprecate DefaultDictBase(default, ks, vs) DefaultDictBase(default, zip(ks, vs))
109-
@deprecate DefaultDictBase{K,V}(::Type{K}, ::Type{V}, default) DefaultDictBase{K,V}(default)
111+
@deprecate DefaultDictBase(::Type{K}, ::Type{V}, default) where {K,V} DefaultDictBase{K,V}(default)
110112

111113
@deprecate DefaultDict(default, ks, vs) DefaultDict(default, zip(ks, vs))
112-
@deprecate DefaultDict{K,V}(::Type{K}, ::Type{V}, default) DefaultDict{K,V}(default)
114+
@deprecate DefaultDict(::Type{K}, ::Type{V}, default) where {K,V} DefaultDict{K,V}(default)
113115

114116
@deprecate DefaultOrderedDict(default, ks, vs) DefaultOrderedDict(default, zip(ks, vs))
115-
@deprecate DefaultOrderedDict{K,V}(::Type{K}, ::Type{V}, default) DefaultOrderedDict{K,V}(default)
117+
@deprecate DefaultOrderedDict(::Type{K}, ::Type{V}, default) where {K,V} DefaultOrderedDict{K,V}(default)
116118

117119
function SortedMultiDict(ks::AbstractVector{K},
118120
vs::AbstractVector{V},
@@ -124,10 +126,10 @@ module DataStructures
124126
SortedMultiDict(o, zip(ks,vs))
125127
end
126128

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)
129+
@deprecate PriorityQueue(::Type{K}, ::Type{V}) where {K,V} PriorityQueue{K,V}()
130+
@deprecate PriorityQueue(::Type{K}, ::Type{V}, o::Ordering) where {K,V} PriorityQueue{K,V,typeof(o)}(o)
129131
@deprecate (PriorityQueue{K,V,ForwardOrdering}() where {K,V}) PriorityQueue{K,V}()
130-
132+
131133
function PriorityQueue(ks::AbstractVector{K},
132134
vs::AbstractVector{V},
133135
o::Ordering=Forward) where {K,V}
@@ -137,5 +139,5 @@ module DataStructures
137139
end
138140
PriorityQueue(o, zip(ks,vs))
139141
end
140-
142+
141143
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

+4-4
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
@@ -156,8 +156,8 @@ mutable struct MutableBinaryHeap{VT, Comp} <: AbstractMutableHeap{VT,Int}
156156
node_map::Vector{Int}
157157

158158
function MutableBinaryHeap{VT, Comp}(comp::Comp) where {VT, Comp}
159-
nodes = Vector{MutableBinaryHeapNode{VT}}(0)
160-
node_map = Vector{Int}(0)
159+
nodes = Vector{MutableBinaryHeapNode{VT}}()
160+
node_map = Vector{Int}()
161161
new{VT, Comp}(comp, nodes, node_map)
162162
end
163163

src/int_set.jl

+2-2
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

@@ -63,7 +63,7 @@ function _matchlength!(b::BitArray, newlen::Integer)
6363
len = length(b)
6464
len > newlen && return splice!(b, newlen+1:len)
6565
len < newlen && _resize0!(b, newlen)
66-
return BitVector(0)
66+
return BitVector()
6767
end
6868

6969
const _intset_bounds_err_msg = "elements of IntSet must be between 0 and typemax(Int)-1"

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

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

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

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_dict.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129

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

135135
let d = OrderedDict(((1, 2), (3, 4))),

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)