diff --git a/REQUIRE b/REQUIRE index 137767a42..1cfa2a03b 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1 +1,2 @@ julia 0.6 +Compat 0.39 diff --git a/src/DataStructures.jl b/src/DataStructures.jl index a17ebc5ca..d0e52046c 100644 --- a/src/DataStructures.jl +++ b/src/DataStructures.jl @@ -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") @@ -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}, @@ -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} @@ -137,5 +141,5 @@ module DataStructures end PriorityQueue(o, zip(ks,vs)) end - + end diff --git a/src/balanced_tree.jl b/src/balanced_tree.jl index 18811efa3..b43c25a35 100644 --- a/src/balanced_tree.jl +++ b/src/balanced_tree.jl @@ -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 @@ -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 diff --git a/src/circ_deque.jl b/src/circ_deque.jl index deb48b629..131d66989 100644 --- a/src/circ_deque.jl +++ b/src/circ_deque.jl @@ -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 diff --git a/src/classified_collections.jl b/src/classified_collections.jl index 0c1eea6a0..a41a6ae43 100644 --- a/src/classified_collections.jl +++ b/src/classified_collections.jl @@ -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) diff --git a/src/delegate.jl b/src/delegate.jl index 08a66d160..274dbc47b 100644 --- a/src/delegate.jl +++ b/src/delegate.jl @@ -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 @@ -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 diff --git a/src/deque.jl b/src/deque.jl index 34673dade..b974f26a7 100644 --- a/src/deque.jl +++ b/src/deque.jl @@ -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 diff --git a/src/heaps.jl b/src/heaps.jl index a89e04cb6..c56410d78 100644 --- a/src/heaps.jl +++ b/src/heaps.jl @@ -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 @@ -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 diff --git a/src/heaps/binary_heap.jl b/src/heaps/binary_heap.jl index 7bd4db321..baad627f1 100644 --- a/src/heaps/binary_heap.jl +++ b/src/heaps/binary_heap.jl @@ -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 diff --git a/src/heaps/mutable_binary_heap.jl b/src/heaps/mutable_binary_heap.jl index e158466ec..af90143d0 100644 --- a/src/heaps/mutable_binary_heap.jl +++ b/src/heaps/mutable_binary_heap.jl @@ -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 diff --git a/src/int_set.jl b/src/int_set.jl index cc597b12a..5f2e2d2c5 100644 --- a/src/int_set.jl +++ b/src/int_set.jl @@ -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) diff --git a/src/ordered_dict.jl b/src/ordered_dict.jl index 034dd78c5..59fc6fffb 100644 --- a/src/ordered_dict.jl +++ b/src/ordered_dict.jl @@ -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}() @@ -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) @@ -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) diff --git a/src/priorityqueue.jl b/src/priorityqueue.jl index 0f553365f..f17b8c8af 100644 --- a/src/priorityqueue.jl +++ b/src/priorityqueue.jl @@ -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) @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 8b0e5dcd5..d3b66ffcb 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,4 +1,4 @@ -using Base.Test +using Compat.Test using DataStructures const IntSet = DataStructures.IntSet using Primes diff --git a/test/test_mutable_binheap.jl b/test/test_mutable_binheap.jl index 4c5c18266..430db0243 100644 --- a/test/test_mutable_binheap.jl +++ b/test/test_mutable_binheap.jl @@ -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 @@ -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 diff --git a/test/test_ordered_set.jl b/test/test_ordered_set.jl index 7856fe967..639c346b1 100644 --- a/test/test_ordered_set.jl +++ b/test/test_ordered_set.jl @@ -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])) diff --git a/test/test_priority_queue.jl b/test/test_priority_queue.jl index e435612d7..8c8e7f068 100644 --- a/test/test_priority_queue.jl +++ b/test/test_priority_queue.jl @@ -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 @@ -87,7 +87,7 @@ 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) @@ -95,7 +95,7 @@ end @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) @@ -139,7 +139,7 @@ end enqueue!(pq, kv) end test_issorted!(pq, priorities) - + # enqueing values via enqueue! pq = PriorityQueue() for (k, v) in priorities @@ -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 diff --git a/test/test_sorted_containers.jl b/test/test_sorted_containers.jl index ee22dfc5f..72527b374 100644 --- a/test/test_sorted_containers.jl +++ b/test/test_sorted_containers.jl @@ -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) @@ -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