diff --git a/src/balanced_tree.jl b/src/balanced_tree.jl index 77940231f..da92b622d 100644 --- a/src/balanced_tree.jl +++ b/src/balanced_tree.jl @@ -25,7 +25,7 @@ ## data nodes. -@compat immutable KDRec{K,D} +immutable KDRec{K,D} parent::Int k::K d::D @@ -47,7 +47,7 @@ end ## If this is a leaf, then it is the key of child3. ## Again, there are two constructors for the same reason mentioned above. -@compat immutable TreeNode{K} +immutable TreeNode{K} child1::Int child2::Int child3::Int @@ -111,7 +111,7 @@ end ## deletionchild and deletionleftkey are two work-arrays ## for the delete function. -@compat type BalancedTree23{K, D, Ord <: Ordering} +type BalancedTree23{K, D, Ord <: Ordering} ord::Ord data::Array{KDRec{K,D}, 1} tree::Array{TreeNode{K}, 1} @@ -146,19 +146,19 @@ end ## if the node is a leaf and its right child is the end ## of the sorted order. -@inline function cmp2_nonleaf(o::Ordering, +@inline function cmp2_nonleaf(o::Ordering, treenode::TreeNode, - k) - lt(o, k, treenode.splitkey1)? 1 : 2 + k) + lt(o, k, treenode.splitkey1) ? 1 : 2 end -@inline function cmp2_leaf(o::Ordering, +@inline function cmp2_leaf(o::Ordering, treenode::TreeNode, - k) - (treenode.child2 == 2) || - lt(o, k, treenode.splitkey1)? 1 : 2 + k) + (treenode.child2 == 2) || + lt(o, k, treenode.splitkey1) ? 1 : 2 end @@ -172,17 +172,17 @@ end @inline function cmp3_nonleaf(o::Ordering, treenode::TreeNode, - k) - lt(o, k, treenode.splitkey1)? 1 : - lt(o, k, treenode.splitkey2)? 2 : 3 + k) + lt(o, k, treenode.splitkey1) ? 1 : + lt(o, k, treenode.splitkey2) ? 2 : 3 end @inline function cmp3_leaf(o::Ordering, treenode::TreeNode, - k) - lt(o, k, treenode.splitkey1)? 1 : - (treenode.child3 == 2 || lt(o, k, treenode.splitkey2))? 2 : 3 + k) + lt(o, k, treenode.splitkey1) ? 1 : + (treenode.child3 == 2 || lt(o, k, treenode.splitkey2)) ? 2 : 3 end @@ -193,17 +193,17 @@ end ## if the node is a leaf and its right child is the end ## of the sorted order. -@inline function cmp2le_nonleaf(o::Ordering, +@inline function cmp2le_nonleaf(o::Ordering, treenode::TreeNode, k) - !lt(o,treenode.splitkey1,k)? 1 : 2 + !lt(o,treenode.splitkey1,k) ? 1 : 2 end -@inline function cmp2le_leaf(o::Ordering, +@inline function cmp2le_leaf(o::Ordering, treenode::TreeNode, k) - treenode.child2 == 2 || !lt(o,treenode.splitkey1,k)? 1 : 2 + treenode.child2 == 2 || !lt(o,treenode.splitkey1,k) ? 1 : 2 end @@ -211,7 +211,7 @@ end ## Function cmp3le checks a tree node with three children ## against a given key, and returns 1 if the given key is -## less than or equal to the node's splitkey1, 2 if less than or equal +## less than or equal to the node's splitkey1, 2 if less than or equal ## to splitkey2, or ## 3 else. Special case ## if the node is a leaf and its right child is the end @@ -220,15 +220,15 @@ end @inline function cmp3le_nonleaf(o::Ordering, treenode::TreeNode, k) - !lt(o,treenode.splitkey1, k)? 1 : - !lt(o,treenode.splitkey2, k)? 2 : 3 + !lt(o,treenode.splitkey1, k) ? 1 : + !lt(o,treenode.splitkey2, k) ? 2 : 3 end @inline function cmp3le_leaf(o::Ordering, treenode::TreeNode, k) - !lt(o,treenode.splitkey1,k)? 1 : - (treenode.child3 == 2 || !lt(o,treenode.splitkey2, k))? 2 : 3 + !lt(o,treenode.splitkey1,k) ? 1 : + (treenode.child3 == 2 || !lt(o,treenode.splitkey2, k)) ? 2 : 3 end @@ -258,7 +258,7 @@ eq(::ReverseOrdering{ForwardOrdering}, a, b) = isequal(a,b) eq(o::Ordering, a, b) = !lt(o, a, b) && !lt(o, b, a) -## The findkey function finds the index of a (key,data) pair in the tree +## The findkey function finds the index of a (key,data) pair in the tree ## where the given key lives (if it is present), or ## if the key is not present, to the lower bound for the key, ## i.e., the data item that comes immediately before it. @@ -270,18 +270,18 @@ function findkey(t::BalancedTree23, k) curnode = t.rootloc for depthcount = 1 : t.depth - 1 @inbounds thisnode = t.tree[curnode] - cmp = thisnode.child3 == 0? + cmp = thisnode.child3 == 0 ? cmp2_nonleaf(t.ord, thisnode, k) : cmp3_nonleaf(t.ord, thisnode, k) - curnode = cmp == 1? thisnode.child1 : - cmp == 2? thisnode.child2 : thisnode.child3 + curnode = cmp == 1 ? thisnode.child1 : + cmp == 2 ? thisnode.child2 : thisnode.child3 end @inbounds thisnode = t.tree[curnode] - cmp = thisnode.child3 == 0? + cmp = thisnode.child3 == 0 ? cmp2_leaf(t.ord, thisnode, k) : cmp3_leaf(t.ord, thisnode, k) - curnode = cmp == 1? thisnode.child1 : - cmp == 2? thisnode.child2 : thisnode.child3 + curnode = cmp == 1 ? thisnode.child1 : + cmp == 2 ? thisnode.child2 : thisnode.child3 @inbounds return curnode, (curnode > 2 && eq(t.ord, t.data[curnode].k, k)) end @@ -295,25 +295,25 @@ function findkeyless(t::BalancedTree23, k) curnode = t.rootloc for depthcount = 1 : t.depth - 1 @inbounds thisnode = t.tree[curnode] - cmp = thisnode.child3 == 0? + cmp = thisnode.child3 == 0 ? cmp2le_nonleaf(t.ord, thisnode, k) : cmp3le_nonleaf(t.ord, thisnode, k) - curnode = cmp == 1? thisnode.child1 : - cmp == 2? thisnode.child2 : thisnode.child3 + curnode = cmp == 1 ? thisnode.child1 : + cmp == 2 ? thisnode.child2 : thisnode.child3 end @inbounds thisnode = t.tree[curnode] - cmp = thisnode.child3 == 0? + cmp = thisnode.child3 == 0 ? cmp2le_leaf(t.ord, thisnode, k) : cmp3le_leaf(t.ord, thisnode, k) - curnode = cmp == 1? thisnode.child1 : - cmp == 2? thisnode.child2 : thisnode.child3 + curnode = cmp == 1 ? thisnode.child1 : + cmp == 2 ? thisnode.child2 : thisnode.child3 curnode end ## The following are helper routines for the insert! and delete! functions. -## They replace the 'parent' field of either an internal tree node or +## They replace the 'parent' field of either an internal tree node or ## a data node at the bottom tree level. function replaceparent!{K,D}(data::Array{KDRec{K,D},1}, whichind::Int, newparent::Int) @@ -324,7 +324,7 @@ end function replaceparent!{K}(tree::Array{TreeNode{K},1}, whichind::Int, newparent::Int) tree[whichind] = TreeNode{K}(tree[whichind].child1, tree[whichind].child2, tree[whichind].child3, newparent, - tree[whichind].splitkey1, + tree[whichind].splitkey1, tree[whichind].splitkey2) nothing end @@ -352,23 +352,23 @@ end ## Function insert! inserts a new data item into the tree. ## The arguments are the (K,D) pair to insert. ## The return values are a bool and an index. The -## bool indicates whether the insertion inserted a new record (true) or +## bool indicates whether the insertion inserted a new record (true) or ## whether it replaced an existing record (false). ## The index returned is the subscript in t.data where the ## inserted value sits. -## "allowdups" (i.e., "allow duplicate keys") means that no check is +## "allowdups" (i.e., "allow duplicate keys") means that no check is ## done whether the iterm ## is already in the tree, so insertion of a new item always succeeds. function insert!{K,D,Ord <: Ordering}(t::BalancedTree23{K,D,Ord}, k, d, allowdups::Bool) - + ## First we find the greatest data node that is <= k. leafind, exactfound = findkey(t, k) parent = t.data[leafind].parent ## The following code is necessary because in the case of a ## brand new tree, the initial tree and data entries were incompletely - ## initialized by the constructor. In this case, the call to insert! + ## initialized by the constructor. In this case, the call to insert! ## underway carries ## valid K and D values, so these valid values may now be ## stored in the dummy placeholder nodes so that they no @@ -382,7 +382,7 @@ function insert!{K,D,Ord <: Ordering}(t::BalancedTree23{K,D,Ord}, k, d, allowdup t.data[1] = KDRec{K,D}(t.data[1].parent, k, d) t.data[2] = KDRec{K,D}(t.data[2].parent, k, d) end - + ## If we have found exactly k in the tree, then we ## replace the data associated with k and return. @@ -409,11 +409,11 @@ function insert!{K,D,Ord <: Ordering}(t::BalancedTree23{K,D,Ord}, k, d, allowdup curdepth = depth ## This loop ascends the tree (i.e., follows the path from a leaf to the root) - ## starting from the parent p1 of + ## starting from the parent p1 of ## where the new key k would go. For each 3-node we encounter ## during the ascent, we add a new child, which requires splitting ## the 3-node into two 2-nodes. Then we keep going until we hit the root. - ## If we encounter a 2-node, then the ascent can stop; we can + ## If we encounter a 2-node, then the ascent can stop; we can ## change the 2-node to a 3-node with the new child. Invariants ## during this loop are: ## p1: the parent node (a tree node index) where the insertion must occur @@ -429,11 +429,11 @@ function insert!{K,D,Ord <: Ordering}(t::BalancedTree23{K,D,Ord}, k, d, allowdup ## Node p1 index a 3-node. There are three cases for how to ## insert new child. All three cases involve splitting the ## existing node (oldtreenode, numbered p1) into - ## two new nodes. One keeps the index p1; the other has + ## two new nodes. One keeps the index p1; the other has ## has a new index called newparentnum. - - cmp = isleaf? cmp3_leaf(ord, oldtreenode, minkeynewchild) : + + cmp = isleaf ? cmp3_leaf(ord, oldtreenode, minkeynewchild) : cmp3_nonleaf(ord, oldtreenode, minkeynewchild) if cmp == 1 @@ -441,7 +441,7 @@ function insert!{K,D,Ord <: Ordering}(t::BalancedTree23{K,D,Ord}, k, d, allowdup oldtreenode.parent, minkeynewchild, minkeynewchild) righttreenodenew = TreeNode{K}(oldtreenode.child2, oldtreenode.child3, 0, - oldtreenode.parent, oldtreenode.splitkey2, + oldtreenode.parent, oldtreenode.splitkey2, oldtreenode.splitkey2) minkeynewchild = oldtreenode.splitkey1 whichp = 1 @@ -468,7 +468,7 @@ function insert!{K,D,Ord <: Ordering}(t::BalancedTree23{K,D,Ord}, k, d, allowdup t.tree[p1] = lefttreenodenew newparentnum = push_or_reuse!(t.tree, t.freetreeinds, righttreenodenew) if isleaf - par = (whichp == 1)? p1 : newparentnum + par = (whichp == 1) ? p1 : newparentnum # fix the parent of the new datanode. replaceparent!(t.data, newind, par) push!(t.useddatacells, newind) @@ -496,20 +496,20 @@ function insert!{K,D,Ord <: Ordering}(t::BalancedTree23{K,D,Ord}, k, d, allowdup ## big loop terminated either because a 2-node was reached ## (splitroot == false) or we went up the whole tree seeing - ## only 3-nodes (splitroot == true). + ## only 3-nodes (splitroot == true). if !splitroot - + ## If our ascent reached a 2-node, then we convert it to ## a 3-node by giving it a child3 field that is >0. ## Encountering a 2-node halts the ascent up the tree. isleaf = curdepth == depth oldtreenode = t.tree[p1] - cmpres = isleaf? cmp2_leaf(ord, oldtreenode, minkeynewchild) : + cmpres = isleaf ? cmp2_leaf(ord, oldtreenode, minkeynewchild) : cmp2_nonleaf(ord, oldtreenode, minkeynewchild) - t.tree[p1] = cmpres == 1? + t.tree[p1] = cmpres == 1 ? TreeNode{K}(oldtreenode.child1, newchild, oldtreenode.child2, oldtreenode.parent, minkeynewchild, oldtreenode.splitkey1) : @@ -520,7 +520,7 @@ function insert!{K,D,Ord <: Ordering}(t::BalancedTree23{K,D,Ord}, k, d, allowdup replaceparent!(t.data, newind, p1) push!(t.useddatacells, newind) end - else + else ## Splitroot is set if the ascent of the tree encountered only 3-nodes. ## In this case, the root itself was replaced by two nodes, so we need ## a new root above those two. @@ -541,7 +541,7 @@ end ## nextloc0: returns the next item in the tree according to the ## sort order, given an index i (subscript of t.data) of a current -## item. +## item. ## The routine returns 2 if there is no next item (i.e., we started ## from the last one in the sorted order). @@ -579,7 +579,7 @@ end ## prevloc0: returns the previous item in the tree according to the ## sort order, given an index i (subscript of t.data) of a current -## item. +## item. ## The routine returns 1 if there is no previous item (i.e., we started ## from the first one in the sorted order). @@ -611,14 +611,14 @@ function prevloc0(t::BalancedTree23, i::Int) end p = prevchild c3 = t.tree[p].child3 - prevchild = c3 > 0? c3 : t.tree[p].child2 + prevchild = c3 > 0 ? c3 : t.tree[p].child2 depthp += 1 end end ## This function takes two indices into t.data and checks which ## one comes first in the sorted order by chasing them both -## up the tree until a common ancestor is found. +## up the tree until a common ancestor is found. ## The return value is -1 if i1 precedes i2, 0 if i1 == i2 ##, 1 if i2 precedes i1. @@ -656,10 +656,10 @@ function compareInd(t::BalancedTree23, i1::Int, i2::Int) p2 = t.tree[i2a].parent curdepth -= 1 end -end +end -## beginloc, endloc return the index (into t.data) of the first, last item in the +## beginloc, endloc return the index (into t.data) of the first, last item in the ## sorted order of the tree. beginloc works by going to the before-start marker ## (data node 1) and executing a next operation on it. endloc is the opposite. @@ -670,10 +670,10 @@ endloc(t::BalancedTree23) = prevloc0(t,2) ## delete! routine deletes an entry from the balanced tree. function delete!{K,D,Ord<:Ordering}(t::BalancedTree23{K,D,Ord}, it::Int) - + ## Put the cell indexed by 'it' into the deletion list. ## - ## Create the following data items maintained in the + ## Create the following data items maintained in the ## upcoming loop. ## ## p is a tree-node ancestor of the deleted node @@ -684,7 +684,7 @@ function delete!{K,D,Ord<:Ordering}(t::BalancedTree23{K,D,Ord}, it::Int) ## are stored in t.deletionleftkey[..] ## There is a special case for t.deletionleftkey[1]; the ## flag deletionleftkey1_valid indicates that the left key - ## for the immediate right neighbor of the + ## for the immediate right neighbor of the ## deleted node has not yet been been stored in the tree. ## Once it is stored, t.deletionleftkey[1] is no longer needed ## or used. @@ -720,14 +720,14 @@ function delete!{K,D,Ord<:Ordering}(t::BalancedTree23{K,D,Ord}, it::Int) curdepth = t.depth mustdeleteroot = false pparent = -1 - + ## The following loop ascends the tree and contracts nodes (reduces their ## number of children) as ## needed. If newchildcount == 2 or 3, then the ascent is terminated ## and a node is created with 2 or 3 children. ## If newchildcount == 1, then the ascent must continue since a tree ## node cannot have one child. - + while true pparent = t.tree[p].parent ## Simple cases when the new child count is 2 or 3 @@ -740,31 +740,31 @@ function delete!{K,D,Ord<:Ordering}(t::BalancedTree23{K,D,Ord}, it::Int) end if newchildcount == 3 t.tree[p] = TreeNode{K}(t.deletionchild[1], t.deletionchild[2], - t.deletionchild[3], pparent, + t.deletionchild[3], pparent, t.deletionleftkey[2], t.deletionleftkey[3]) break end # @assert(newchildcount == 1) ## For the rest of this loop, we cover the case ## that p has one child. - + ## If newchildcount == 1 and curdepth==1, this means that ## the root of the tree has only one child. In this case, we can ## delete the root and make its one child the new root (see below). - + if curdepth == 1 mustdeleteroot = true break end - + ## We now branch on three cases depending on whether p is child1, ## child2 or child3 of its parent. if t.tree[pparent].child1 == p rightsib = t.tree[pparent].child2 - - ## Here p is child1 and rightsib is child2. - ## If rightsib has 2 children, then p and + + ## Here p is child1 and rightsib is child2. + ## If rightsib has 2 children, then p and ## rightsib are merged into a single node ## that has three children. ## If rightsib has 3 children, then p and @@ -777,7 +777,7 @@ function delete!{K,D,Ord<:Ordering}(t::BalancedTree23{K,D,Ord}, it::Int) t.tree[p] = TreeNode{K}(t.deletionchild[1], rc1, rc2, pparent, - t.tree[pparent].splitkey1, + t.tree[pparent].splitkey1, t.tree[rightsib].splitkey1) if curdepth == t.depth replaceparent!(t.data, rc1, p) @@ -793,7 +793,7 @@ function delete!{K,D,Ord<:Ordering}(t::BalancedTree23{K,D,Ord}, it::Int) rc1 = t.tree[rightsib].child1 t.tree[p] = TreeNode{K}(t.deletionchild[1], rc1, 0, pparent, - t.tree[pparent].splitkey1, + t.tree[pparent].splitkey1, defaultKey) sk1 = t.tree[rightsib].splitkey1 t.tree[rightsib] = TreeNode{K}(t.tree[rightsib].child2, @@ -811,11 +811,11 @@ function delete!{K,D,Ord<:Ordering}(t::BalancedTree23{K,D,Ord}, it::Int) t.deletionchild[1] = p t.deletionchild[2] = rightsib t.deletionleftkey[2] = sk1 - end - + end + ## If pparent had a third child (besides p and rightsib) ## then we add this to t.deletionchild - + c3 = t.tree[pparent].child3 if c3 > 0 newchildcount += 1 @@ -824,9 +824,9 @@ function delete!{K,D,Ord<:Ordering}(t::BalancedTree23{K,D,Ord}, it::Int) end p = pparent elseif t.tree[pparent].child2 == p - - ## Here p is child2 and leftsib is child1. - ## If leftsib has 2 children, then p and + + ## Here p is child2 and leftsib is child1. + ## If leftsib has 2 children, then p and ## leftsib are merged into a single node ## that has three children. ## If leftsib has 3 children, then p and @@ -834,8 +834,8 @@ function delete!{K,D,Ord<:Ordering}(t::BalancedTree23{K,D,Ord}, it::Int) ## two children. leftsib = t.tree[pparent].child1 - lk = deletionleftkey1_valid? - t.deletionleftkey[1] : + lk = deletionleftkey1_valid ? + t.deletionleftkey[1] : t.tree[pparent].splitkey1 if t.tree[leftsib].child3 == 0 lc1 = t.tree[leftsib].child1 @@ -875,10 +875,10 @@ function delete!{K,D,Ord<:Ordering}(t::BalancedTree23{K,D,Ord}, it::Int) t.deletionchild[2] = p t.deletionleftkey[2] = sk2 end - + ## If pparent had a third child (besides p and leftsib) ## then we add this to t.deletionchild - + c3 = t.tree[pparent].child3 if c3 > 0 newchildcount += 1 @@ -889,17 +889,17 @@ function delete!{K,D,Ord<:Ordering}(t::BalancedTree23{K,D,Ord}, it::Int) deletionleftkey1_valid = false else ## Here p is child3 and leftsib is child2. - ## If leftsib has 2 children, then p and + ## If leftsib has 2 children, then p and ## leftsib are merged into a single node ## that has three children. ## If leftsib has 3 children, then p and ## leftsib are reformed so that each has ## two children. - + # @assert(t.tree[pparent].child3 == p) leftsib = t.tree[pparent].child2 - lk = deletionleftkey1_valid? - t.deletionleftkey[1] : + lk = deletionleftkey1_valid ? + t.deletionleftkey[1] : t.tree[pparent].splitkey2 if t.tree[leftsib].child3 == 0 lc1 = t.tree[leftsib].child1 diff --git a/src/circ_deque.jl b/src/circ_deque.jl index ecbf0c5dc..2a7d085e3 100644 --- a/src/circ_deque.jl +++ b/src/circ_deque.jl @@ -11,7 +11,7 @@ type CircularDeque{T} last::Int end -@compat (::Type{CircularDeque{T}}){T}(n::Int) = CircularDeque(Vector{T}(n), n, 0, 1, n) +(::Type{CircularDeque{T}}){T}(n::Int) = CircularDeque(Vector{T}(n), n, 0, 1, n) Base.length(D::CircularDeque) = D.n Base.eltype{T}(::Type{CircularDeque{T}}) = T @@ -27,17 +27,17 @@ end Base.isempty(D::CircularDeque) = D.n == 0 @inline function front(D::CircularDeque) - @compat @boundscheck D.n > 0 || throw(BoundsError()) + @boundscheck D.n > 0 || throw(BoundsError()) D.buffer[D.first] end @inline function back(D::CircularDeque) - @compat @boundscheck D.n > 0 || throw(BoundsError()) + @boundscheck D.n > 0 || throw(BoundsError()) D.buffer[D.last] end @inline function Base.push!(D::CircularDeque, v) - @compat @boundscheck D.n < D.capacity || throw(BoundsError()) # prevent overflow + @boundscheck D.n < D.capacity || throw(BoundsError()) # prevent overflow D.n += 1 tmp = D.last+1 D.last = ifelse(tmp > D.capacity, 1, tmp) # wraparound @@ -54,7 +54,7 @@ end end @inline function Base.unshift!(D::CircularDeque, v) - @compat @boundscheck D.n < D.capacity || throw(BoundsError()) + @boundscheck D.n < D.capacity || throw(BoundsError()) D.n += 1 tmp = D.first - 1 D.first = ifelse(tmp < 1, D.capacity, tmp) @@ -81,7 +81,7 @@ end end @inline function Base.getindex(D::CircularDeque, i::Integer) - @compat @boundscheck 1 <= i <= D.n || throw(BoundsError()) + @boundscheck 1 <= i <= D.n || throw(BoundsError()) return _unsafe_getindex(D, i) end diff --git a/src/circular_buffer.jl b/src/circular_buffer.jl index 782ab8f03..011aaed53 100644 --- a/src/circular_buffer.jl +++ b/src/circular_buffer.jl @@ -1,7 +1,7 @@ """ New items are pushed to the back of the list, overwriting values in a circular fashion. """ -@compat type CircularBuffer{T} <: AbstractVector{T} +type CircularBuffer{T} <: AbstractVector{T} capacity::Int first::Int buffer::Vector{T} diff --git a/src/default_dict.jl b/src/default_dict.jl index ebe989265..9d1e344d8 100644 --- a/src/default_dict.jl +++ b/src/default_dict.jl @@ -14,7 +14,7 @@ # subclassed. # -@compat immutable DefaultDictBase{K,V,F,D} <: Associative{K,V} +immutable DefaultDictBase{K,V,F,D} <: Associative{K,V} default::F d::D @@ -44,7 +44,7 @@ DefaultDictBase{K,V,F}(default::F, ps::Pair{K,V}...) = DefaultDictBase{K,V,F,Dic DefaultDictBase{F,D<:Associative}(default::F, d::D) = (K=keytype(d); V=valtype(d); DefaultDictBase{K,V,F,D}(default, d)) # Constructor for DefaultDictBase{Int,Float64}(0.0) -@compat (::Type{DefaultDictBase{K,V}}){K,V,F}(default::F) = DefaultDictBase{K,V,F,Dict{K,V}}(default) +(::Type{DefaultDictBase{K,V}}){K,V,F}(default::F) = DefaultDictBase{K,V,F,Dict{K,V}}(default) # Functions @@ -82,7 +82,7 @@ end for _Dict in [:Dict, :OrderedDict] DefaultDict = Symbol("Default"*string(_Dict)) @eval begin - @compat immutable $DefaultDict{K,V,F} <: Associative{K,V} + immutable $DefaultDict{K,V,F} <: Associative{K,V} d::DefaultDictBase{K,V,F,$_Dict{K,V}} (::Type{$DefaultDict{K,V,F}}){K,V,F}(x, ps::Pair{K,V}...) = @@ -109,8 +109,8 @@ for _Dict in [:Dict, :OrderedDict] $DefaultDict{F}(default::F, d::Associative) = ((K,V)= (Base.keytype(d), Base.valtype(d)); $DefaultDict{K,V,F}(default, $_Dict(d))) # Constructor syntax: DefaultDictBase{Int,Float64}(default) - @compat (::Type{$DefaultDict{K,V}}){K,V}() = throw(ArgumentError("$DefaultDict: no default specified")) - @compat (::Type{$DefaultDict{K,V}}){K,V,F}(default::F) = $DefaultDict{K,V,F}(default) + (::Type{$DefaultDict{K,V}}){K,V}() = throw(ArgumentError("$DefaultDict: no default specified")) + (::Type{$DefaultDict{K,V}}){K,V,F}(default::F) = $DefaultDict{K,V,F}(default) ## Functions diff --git a/src/deque.jl b/src/deque.jl index 84c7c9630..d37e49c7d 100644 --- a/src/deque.jl +++ b/src/deque.jl @@ -5,7 +5,7 @@ # ####################################### -@compat type DequeBlock{T} +type DequeBlock{T} data::Vector{T} # only data[front:back] is valid capa::Int front::Int @@ -58,7 +58,7 @@ end const DEFAULT_DEQUEUE_BLOCKSIZE = 1024 -@compat type Deque{T} +type Deque{T} nblocks::Int blksize::Int len::Int diff --git a/src/disjoint_set.jl b/src/disjoint_set.jl index 40b640ab7..eba54a63f 100644 --- a/src/disjoint_set.jl +++ b/src/disjoint_set.jl @@ -105,7 +105,7 @@ end # ############################################################ -@compat type DisjointSets{T} +type DisjointSets{T} intmap::Dict{T,Int} revmap::Vector{T} internal::IntDisjointSets diff --git a/src/heaps/binary_heap.jl b/src/heaps/binary_heap.jl index ca1388699..b4be1bcf3 100644 --- a/src/heaps/binary_heap.jl +++ b/src/heaps/binary_heap.jl @@ -102,7 +102,7 @@ end # ################################################# -@compat type BinaryHeap{T,Comp} <: AbstractHeap{T} +type BinaryHeap{T,Comp} <: AbstractHeap{T} comparer::Comp valtree::Vector{T} diff --git a/src/heaps/mutable_binary_heap.jl b/src/heaps/mutable_binary_heap.jl index 5ef24263e..6c94b195e 100644 --- a/src/heaps/mutable_binary_heap.jl +++ b/src/heaps/mutable_binary_heap.jl @@ -150,7 +150,7 @@ end # ################################################# -@compat type MutableBinaryHeap{VT, Comp} <: AbstractMutableHeap{VT,Int} +type MutableBinaryHeap{VT, Comp} <: AbstractMutableHeap{VT,Int} comparer::Comp nodes::Vector{MutableBinaryHeapNode{VT}} node_map::Vector{Int} diff --git a/src/multi_dict.jl b/src/multi_dict.jl index 291d9a0dc..0a318499a 100644 --- a/src/multi_dict.jl +++ b/src/multi_dict.jl @@ -5,7 +5,7 @@ import Base: haskey, get, get!, getkey, delete!, pop!, empty!, next, done, keys, values, copy, similar, push!, count, size, eltype -@compat immutable MultiDict{K,V} +immutable MultiDict{K,V} d::Dict{K,Vector{V}} (::Type{MultiDict{K,V}}){K,V}() = new{K,V}(Dict{K,Vector{V}}()) @@ -85,11 +85,9 @@ function pop!(d::MultiDict, key, default) end pop!(d::MultiDict, key) = pop!(d, key, Base.secret_table_token) -if VERSION >= v"0.4.0-dev+980" - push!(d::MultiDict, kv::Pair) = insert!(d, kv[1], kv[2]) - #push!(d::MultiDict, kv::Pair, kv2::Pair) = (push!(d.d, kv, kv2); d) - #push!(d::MultiDict, kv::Pair, kv2::Pair, kv3::Pair...) = (push!(d.d, kv, kv2, kv3...); d) -end +push!(d::MultiDict, kv::Pair) = insert!(d, kv[1], kv[2]) +#push!(d::MultiDict, kv::Pair, kv2::Pair) = (push!(d.d, kv, kv2); d) +#push!(d::MultiDict, kv::Pair, kv2::Pair, kv3::Pair...) = (push!(d.d, kv, kv2, kv3...); d) push!(d::MultiDict, kv) = insert!(d, kv[1], kv[2]) #push!(d::MultiDict, kv, kv2...) = (push!(d.d, kv, kv2...); d) diff --git a/src/ordered_dict.jl b/src/ordered_dict.jl index 8f912f3c0..d9b4dd01c 100644 --- a/src/ordered_dict.jl +++ b/src/ordered_dict.jl @@ -13,7 +13,7 @@ import Base: haskey, get, get!, getkey, delete!, push!, pop!, empty!, `OrderedDict`s are simply dictionaries whose entries have a particular order. The order refers to insertion order, which allows deterministic iteration over the dictionary or set. """ -@compat type OrderedDict{K,V} <: Associative{K,V} +type OrderedDict{K,V} <: Associative{K,V} slots::Array{Int32,1} keys::Array{K,1} vals::Array{V,1} diff --git a/src/ordered_set.jl b/src/ordered_set.jl index d9a384141..606175a58 100644 --- a/src/ordered_set.jl +++ b/src/ordered_set.jl @@ -5,7 +5,7 @@ # TODO: Most of these functions should be removed once AbstractSet is introduced there # (see https://github.com/JuliaLang/julia/issues/5533) -@compat immutable OrderedSet{T} +immutable OrderedSet{T} dict::OrderedDict{T,Void} (::Type{OrderedSet{T}}){T}() = new{T}(OrderedDict{T,Void}()) diff --git a/src/priorityqueue.jl b/src/priorityqueue.jl index a6f0089b2..9c2d88a96 100644 --- a/src/priorityqueue.jl +++ b/src/priorityqueue.jl @@ -23,7 +23,7 @@ PriorityQueue{String,Int64,Base.Order.ForwardOrdering} with 3 entries: "a" => 2 ``` """ -@compat type PriorityQueue{K,V,O<:Ordering} <: Associative{K,V} +type PriorityQueue{K,V,O<:Ordering} <: Associative{K,V} # Binary heap of (element, priority) pairs. xs::Array{Pair{K,V}, 1} o::O diff --git a/src/sorted_dict.jl b/src/sorted_dict.jl index 22ea57aa0..e55e0bacf 100644 --- a/src/sorted_dict.jl +++ b/src/sorted_dict.jl @@ -1,7 +1,7 @@ ## A SortedDict is a wrapper around balancedTree with ## methods similiar to those of Julia container Dict. -@compat type SortedDict{K, D, Ord <: Ordering} <: Associative{K,D} +type SortedDict{K, D, Ord <: Ordering} <: Associative{K,D} bt::BalancedTree23{K,D,Ord} ## Base constructors @@ -36,8 +36,8 @@ SortedDict{Ord <: Ordering}(o::Ord) = SortedDict{Any,Any,Ord}(o) # TODO: fix SortedDict(1=>1, 2=>2.0) SortedDict(ps::Pair...) = SortedDict(Forward, ps) SortedDict(o::Ordering, ps::Pair...) = SortedDict(o, ps) -@compat (::Type{SortedDict{K,D}}){K,D}(ps::Pair...) = SortedDict{K,D,ForwardOrdering}(Forward, ps) -@compat (::Type{SortedDict{K,D}}){K,D,Ord<:Ordering}(o::Ord, ps::Pair...) = SortedDict{K,D,Ord}(o, ps) +(::Type{SortedDict{K,D}}){K,D}(ps::Pair...) = SortedDict{K,D,ForwardOrdering}(Forward, ps) +(::Type{SortedDict{K,D}}){K,D,Ord<:Ordering}(o::Ord, ps::Pair...) = SortedDict{K,D,Ord}(o, ps) # Construction from Associatives SortedDict{K,D,Ord<:Ordering}(o::Ord, d::Associative{K,D}) = SortedDict{K,D,Ord}(o, d) @@ -46,8 +46,8 @@ SortedDict{K,D,Ord<:Ordering}(o::Ord, d::Associative{K,D}) = SortedDict{K,D,Ord} # Construction specifying Key/Value types # e.g., SortedDict{Int,Float64}([1=>1, 2=>2.0]) -@compat (::Type{SortedDict{K,D}}){K,D}(kv) = SortedDict{K,D}(Forward, kv) -@compat function (::Type{SortedDict{K,D}}){K,D,Ord<:Ordering}(o::Ord, kv) +(::Type{SortedDict{K,D}}){K,D}(kv) = SortedDict{K,D}(Forward, kv) +function (::Type{SortedDict{K,D}}){K,D,Ord<:Ordering}(o::Ord, kv) try SortedDict{K,D,Ord}(o, kv) catch e @@ -129,7 +129,7 @@ end @inline function find(m::SortedDict, k_) ll, exactfound = findkey(m.bt, convert(keytype(m),k_)) - IntSemiToken(exactfound? ll : 2) + IntSemiToken(exactfound ? ll : 2) end ## This function inserts an item into the tree. @@ -196,7 +196,7 @@ end @inline function get{K,D,Ord <: Ordering}(m::SortedDict{K,D,Ord}, k_, default_) i, exactfound = findkey(m.bt, convert(K,k_)) - return exactfound? m.bt.data[i].d : convert(D,default_) + return exactfound ? m.bt.data[i].d : convert(D,default_) end @@ -215,7 +215,7 @@ end function getkey{K,D,Ord <: Ordering}(m::SortedDict{K,D,Ord}, k_, default_) i, exactfound = findkey(m.bt, convert(K,k_)) - exactfound? m.bt.data[i].k : convert(K, default_) + exactfound ? m.bt.data[i].k : convert(K, default_) end ## Function delete! deletes an item at a given diff --git a/src/sorted_multi_dict.jl b/src/sorted_multi_dict.jl index 78ab35acd..e3c01f4c8 100644 --- a/src/sorted_multi_dict.jl +++ b/src/sorted_multi_dict.jl @@ -2,7 +2,7 @@ ## Unlike SortedDict, a key in SortedMultiDict can ## refer to multiple data entries. -@compat type SortedMultiDict{K, D, Ord <: Ordering} +type SortedMultiDict{K, D, Ord <: Ordering} bt::BalancedTree23{K,D,Ord} ## Base constructors @@ -34,8 +34,8 @@ SortedMultiDict{O<:Ordering}(o::O) = SortedMultiDict{Any,Any,O}(o) # Construction from Pairs SortedMultiDict(ps::Pair...) = SortedMultiDict(Forward, ps) SortedMultiDict(o::Ordering, ps::Pair...) = SortedMultiDict(o, ps) -@compat (::Type{SortedMultiDict{K,D}}){K,D}(ps::Pair...) = SortedMultiDict{K,D,ForwardOrdering}(Forward, ps) -@compat (::Type{SortedMultiDict{K,D}}){K,D,Ord<:Ordering}(o::Ord, ps::Pair...) = SortedMultiDict{K,D,Ord}(o, ps) +(::Type{SortedMultiDict{K,D}}){K,D}(ps::Pair...) = SortedMultiDict{K,D,ForwardOrdering}(Forward, ps) +(::Type{SortedMultiDict{K,D}}){K,D,Ord<:Ordering}(o::Ord, ps::Pair...) = SortedMultiDict{K,D,Ord}(o, ps) # Construction from Associatives SortedMultiDict{K,D,Ord<:Ordering}(o::Ord, d::Associative{K,D}) = SortedMultiDict{K,D,Ord}(o, d) @@ -44,8 +44,8 @@ SortedMultiDict{K,D,Ord<:Ordering}(o::Ord, d::Associative{K,D}) = SortedMultiDic # Construction specifying Key/Value types # e.g., SortedMultiDict{Int,Float64}([1=>1, 2=>2.0]) -@compat (::Type{SortedMultiDict{K,D}}){K,D}(kv) = SortedMultiDict{K,D}(Forward, kv) -@compat function (::Type{SortedMultiDict{K,D}}){K,D,Ord<:Ordering}(o::Ord, kv) +(::Type{SortedMultiDict{K,D}}){K,D}(kv) = SortedMultiDict{K,D}(Forward, kv) +function (::Type{SortedMultiDict{K,D}}){K,D,Ord<:Ordering}(o::Ord, kv) try SortedMultiDict{K,D,Ord}(o, kv) catch e diff --git a/src/sorted_set.jl b/src/sorted_set.jl index 8956e3282..78eef6f34 100644 --- a/src/sorted_set.jl +++ b/src/sorted_set.jl @@ -2,7 +2,7 @@ ## methods similiar to those of the julia Set. -@compat type SortedSet{K, Ord <: Ordering} +type SortedSet{K, Ord <: Ordering} bt::BalancedTree23{K,Void,Ord} function (::Type{SortedSet{K,Ord}}){K,Ord<:Ordering}(o::Ord=Forward, iter=[]) @@ -25,14 +25,14 @@ SortedSet(o1::Ordering,o2::Ordering) = SortedSet(o::Ordering, iter) = sortedset_with_eltype(o, iter, eltype(iter)) SortedSet(iter, o::Ordering=Forward) = sortedset_with_eltype(o, iter, eltype(iter)) -@compat (::Type{SortedSet{K}}){K}() = SortedSet{K,ForwardOrdering}(Forward) -@compat (::Type{SortedSet{K}}){K,O<:Ordering}(o::O) = SortedSet{K,O}(o) +(::Type{SortedSet{K}}){K}() = SortedSet{K,ForwardOrdering}(Forward) +(::Type{SortedSet{K}}){K,O<:Ordering}(o::O) = SortedSet{K,O}(o) # To address ambiguity warnings on Julia v0.4 -@compat (::Type{SortedSet{K}}){K}(o1::Ordering,o2::Ordering) = +(::Type{SortedSet{K}}){K}(o1::Ordering,o2::Ordering) = throw(ArgumentError("SortedSet with two parameters must be called with an Ordering and an interable")) -@compat (::Type{SortedSet{K}}){K}(o::Ordering, iter) = sortedset_with_eltype(o, iter, K) -@compat (::Type{SortedSet{K}}){K}(iter, o::Ordering=Forward) = sortedset_with_eltype(o, iter, K) +(::Type{SortedSet{K}}){K}(o::Ordering, iter) = sortedset_with_eltype(o, iter, K) +(::Type{SortedSet{K}}){K}(iter, o::Ordering=Forward) = sortedset_with_eltype(o, iter, K) sortedset_with_eltype{K,Ord}(o::Ord, iter, ::Type{K}) = SortedSet{K,Ord}(o, iter) @@ -47,7 +47,7 @@ const SetSemiToken = IntSemiToken @inline function find(m::SortedSet, k_) ll, exactfound = findkey(m.bt, convert(keytype(m),k_)) - IntSemiToken(exactfound? ll : 2) + IntSemiToken(exactfound ? ll : 2) end diff --git a/src/tokens2.jl b/src/tokens2.jl index f73107ccd..0c1fc3133 100644 --- a/src/tokens2.jl +++ b/src/tokens2.jl @@ -62,9 +62,9 @@ end @inline status(ii::Token) = - !(ii[2].address in ii[1].bt.useddatacells)? 0 : - ii[2].address == 1? 2 : - ii[2].address == 2? 3 : 1 + !(ii[2].address in ii[1].bt.useddatacells) ? 0 : + ii[2].address == 1 ? 2 : + ii[2].address == 2 ? 3 : 1 """ compare(m::SAContainer, s::IntSemiToken, t::IntSemiToken) diff --git a/src/trie.jl b/src/trie.jl index c1987cf07..8fb230a3d 100644 --- a/src/trie.jl +++ b/src/trie.jl @@ -1,4 +1,4 @@ -@compat type Trie{T} +type Trie{T} value::T children::Dict{Char,Trie{T}} is_key::Bool @@ -126,6 +126,4 @@ function done(it::TrieIterator, state) end path(t::Trie, str::AbstractString) = TrieIterator(t, str) -if VERSION >= v"0.5.0-dev+3294" - Base.iteratorsize(::Type{TrieIterator}) = Base.SizeUnknown() -end +Base.iteratorsize(::Type{TrieIterator}) = Base.SizeUnknown() diff --git a/test/REQUIRE b/test/REQUIRE index a51cfef3e..42870a216 100644 --- a/test/REQUIRE +++ b/test/REQUIRE @@ -1,3 +1 @@ -BaseTestNext Primes 0.1.1 -Compat 0.9.5 diff --git a/test/runtests.jl b/test/runtests.jl index f95976219..95383721d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,15 +1,9 @@ -if VERSION >= v"0.5.0-dev+7720" - using Base.Test -else - using BaseTestNext - const Test = BaseTestNext -end +using Base.Test using DataStructures const IntSet = DataStructures.IntSet -import Compat: String using Primes -if VERSION >= v"0.5.0" && VERSION < v"0.6.0-dev" +if VERSION < v"0.6.0-dev" @test isempty(detect_ambiguities(Base, Core, DataStructures)) end diff --git a/test/test_accumulator.jl b/test/test_accumulator.jl index c0ff2ef18..71b523c18 100644 --- a/test/test_accumulator.jl +++ b/test/test_accumulator.jl @@ -1,7 +1,7 @@ # Test of accumulators -ct = counter(Compat.ASCIIString) -@assert isa(ct, Accumulator{Compat.ASCIIString,Int}) +ct = counter(String) +@assert isa(ct, Accumulator{String,Int}) @test ct["abc"] == 0 @test !haskey(ct, "abc") @@ -29,7 +29,7 @@ push!(ct, "b", 0x3) @test sum(ct) == 6 ct2 = counter(["a", "a", "b", "b", "a", "c", "c"]) -@test isa(ct2, Accumulator{Compat.ASCIIString,Int}) +@test isa(ct2, Accumulator{String,Int}) @test haskey(ct2, "a") @test haskey(ct2, "b") @test haskey(ct2, "c") @@ -43,14 +43,14 @@ push!(ct, ct2) @test ct["c"] == 2 ct3 = counter(Dict([("a",10), ("b",20)])) -@test isa(ct3, Accumulator{Compat.ASCIIString,Int}) +@test isa(ct3, Accumulator{String,Int}) @test haskey(ct3, "a") @test haskey(ct3, "b") @test ct3["a"] == 10 @test ct3["b"] == 20 ctm = merge(ct2, ct3) -@test isa(ctm, Accumulator{Compat.ASCIIString,Int}) +@test isa(ctm, Accumulator{String,Int}) @test haskey(ctm, "a") @test haskey(ctm, "b") @test haskey(ctm, "c") diff --git a/test/test_circ_deque.jl b/test/test_circ_deque.jl index 073bf6577..2a312cd5c 100644 --- a/test/test_circ_deque.jl +++ b/test/test_circ_deque.jl @@ -1,11 +1,5 @@ -using DataStructures, Compat -using Compat: String -if VERSION >= v"0.5.0-dev+7720" - using Base.Test -else - using BaseTestNext - const Test = BaseTestNext -end +using DataStructures +using Base.Test @testset "CircularDeque" begin D = CircularDeque{Int}(5) diff --git a/test/test_circular_buffer.jl b/test/test_circular_buffer.jl index 58886d454..97f031edb 100644 --- a/test/test_circular_buffer.jl +++ b/test/test_circular_buffer.jl @@ -1,21 +1,11 @@ using DataStructures -if VERSION >= v"0.5.0-dev+7720" - using Base.Test -else - using BaseTestNext - const Test = BaseTestNext -end +using Base.Test @testset "CircularBuffer" begin cb = CircularBuffer{Int}(5) @test length(cb) == 0 @test capacity(cb) == 5 - # throws ArgumentError on v0.4 and BoundsError on v0.5 (diverged at 0.5.0-dev+5230) - if VERSION >= v"0.5.0-dev+5230" - @test_throws BoundsError first(cb) - else - @test_throws ArgumentError first(cb) - end + @test_throws BoundsError first(cb) @test isempty(cb) == true @test isfull(cb) == false diff --git a/test/test_classified_collections.jl b/test/test_classified_collections.jl index 26f1490dd..e2112c938 100644 --- a/test/test_classified_collections.jl +++ b/test/test_classified_collections.jl @@ -1,16 +1,11 @@ # Test classified collections using DataStructures -if VERSION >= v"0.5.0-dev+7720" - using Base.Test -else - using BaseTestNext - const Test = BaseTestNext -end +using Base.Test # classified lists -c = classified_lists(Compat.ASCIIString, Int) +c = classified_lists(String, Int) push!(c, "low", 1) push!(c, "low", 2) @@ -26,14 +21,14 @@ push!(c, "high", 5) @test c["high"] == [4, 5] @test length(c) == 2 -@test sort(collect(keys(c))) == Compat.ASCIIString["high","low"] +@test sort(collect(keys(c))) == String["high","low"] pop!(c,"low") @test !haskey(c,"low") # classified sets -c = classified_sets(Compat.ASCIIString, Int) +c = classified_sets(String, Int) push!(c, "low", 1) push!(c, "low", 2) @@ -57,7 +52,7 @@ push!(c, "high", 5) # classified counters -c = classified_counters(Compat.ASCIIString, Float64) +c = classified_counters(String, Float64) push!(c, "low", 1.) push!(c, "low", 2.) diff --git a/test/test_deque.jl b/test/test_deque.jl index 2076aa74d..e6b1492b9 100644 --- a/test/test_deque.jl +++ b/test/test_deque.jl @@ -1,10 +1,5 @@ using DataStructures -if VERSION >= v"0.5.0-dev+7720" - using Base.Test -else - using BaseTestNext - const Test = BaseTestNext -end +using Base.Test # empty dequeue diff --git a/test/test_list.jl b/test/test_list.jl index 06f9288cd..2eb129b2a 100644 --- a/test/test_list.jl +++ b/test/test_list.jl @@ -43,7 +43,7 @@ l5 = map((x) -> x*2, l4) @test collect(l5) == [2; 4; 6] l5b = map((x) -> "$x", l5) -@test isa(l5b, Cons{Compat.ASCIIString}) +@test isa(l5b, Cons{String}) @test collect(l5b) == ["2"; "4"; "6"] l6 = filter((x) -> x < 6, l5) diff --git a/test/test_ordered_dict.jl b/test/test_ordered_dict.jl index ef5f947dd..129bd1158 100644 --- a/test/test_ordered_dict.jl +++ b/test/test_ordered_dict.jl @@ -2,7 +2,7 @@ @test isa(OrderedDict(), OrderedDict{Any,Any}) @test isa(OrderedDict([(1,2.0)]), OrderedDict{Int,Float64}) -@test isa(OrderedDict([("a",1),("b",2)]), OrderedDict{Compat.ASCIIString,Int}) +@test isa(OrderedDict([("a",1),("b",2)]), OrderedDict{String,Int}) @test isa(OrderedDict(Pair(1, 1.0)), OrderedDict{Int,Float64}) @test isa(OrderedDict(Pair(1, 1.0), Pair(2, 2.0)), OrderedDict{Int,Float64}) @test isa(OrderedDict(Pair(1, 1.0), Pair(2, 2.0), Pair(3, 3.0)), OrderedDict{Int,Float64}) @@ -199,7 +199,7 @@ end # issue #1821 let - d = OrderedDict{Compat.ASCIIString, Vector{Int}}() + d = OrderedDict{String, Vector{Int}}() d["a"] = [1, 2] @test_throws MethodError d["b"] = 1 @test isa(repr(d), AbstractString) # check that printable without error @@ -226,7 +226,7 @@ end data_in = [ (rand(1:1000), randstring(2)) for _ in 1:1001 ] # Populate the first dict -d1 = OrderedDict{Int, Compat.ASCIIString}() +d1 = OrderedDict{Int, String}() for (k,v) in data_in d1[k] = v end @@ -305,7 +305,7 @@ end let a = OrderedDict("foo" => 0.0, "bar" => 42.0) b = OrderedDict("フー" => 17, "バー" => 4711) - @test isa(merge(a, b), OrderedDict{Compat.UTF8String,Float64}) + @test isa(merge(a, b), OrderedDict{String,Float64}) end # issue 9295 diff --git a/test/test_ordered_set.jl b/test/test_ordered_set.jl index f393af035..98150b568 100644 --- a/test/test_ordered_set.jl +++ b/test/test_ordered_set.jl @@ -1,10 +1,5 @@ using DataStructures -if VERSION >= v"0.5.0-dev+7720" - using Base.Test -else - using BaseTestNext - const Test = BaseTestNext -end +using Base.Test # construction @@ -20,9 +15,9 @@ data_out = collect(s) @test length(data_out) == length(data_in) # hash -s1 = OrderedSet{Compat.ASCIIString}(["bar", "foo"]) -s2 = OrderedSet{Compat.ASCIIString}(["foo", "bar"]) -s3 = OrderedSet{Compat.ASCIIString}(["baz"]) +s1 = OrderedSet{String}(["bar", "foo"]) +s2 = OrderedSet{String}(["foo", "bar"]) +s3 = OrderedSet{String}(["baz"]) @test hash(s1) != hash(s2) @test hash(s1) != hash(s3) diff --git a/test/test_sorted_containers.jl b/test/test_sorted_containers.jl index 801b7aad3..0ad5acb26 100644 --- a/test/test_sorted_containers.jl +++ b/test/test_sorted_containers.jl @@ -1,10 +1,4 @@ -if VERSION >= v"0.5.0-dev+7720" - using Base.Test -else - using BaseTestNext - const Test = BaseTestNext -end - +using Base.Test using DataStructures import Base.Ordering import Base.Forward @@ -50,7 +44,7 @@ function fulldump(t::DataStructures.BalancedTree23) c1 = t.tree[ii].child1 c2 = t.tree[ii].child2 c3 = t.tree[ii].child3 - dt = (mydepth == dpth)? "child(data)" : "child(tree)" + dt = (mydepth == dpth) ? "child(data)" : "child(tree)" if c3 == 0 println("ii = $ii splitkey1 = /$sk1/ $dt.1 = $c1 $dt.2 = $c2 parent = $p") if !isleaf @@ -154,7 +148,7 @@ function checkcorrectness{K,D,Ord <: Ordering}(t::DataStructures.BalancedTree23{ end c2 = t.tree[anc].child2 c3 = t.tree[anc].child3 - lastchild = c3 > 0? c3 : c2 + lastchild = c3 > 0 ? c3 : c2 if s == bfstreesize if lastchild != 2 throw(ErrorException("Rightmost data descendant should be node 2")) @@ -284,8 +278,8 @@ end @testset "SortedDictBasic" begin # a few basic tests of SortedDict to start - m1 = SortedDict((Dict{Compat.ASCIIString,Compat.ASCIIString}()), Forward) - @test typeof(m1) == SortedDict{Compat.ASCIIString, Compat.ASCIIString, ForwardOrdering} + m1 = SortedDict((Dict{String,String}()), Forward) + @test typeof(m1) == SortedDict{String, String, ForwardOrdering} kdarray = ["hello", "jello", "alpha", "beta", "fortune", "random", "july", "wednesday"] checkcorrectness(m1.bt, false) @@ -553,7 +547,7 @@ end c1 = SortedDict(Dict("Eggplants"=>3, "Figs"=>9, "Apples"=>7)) - @test typeof(c1) == SortedDict{Compat.ASCIIString, Int, ForwardOrdering} + @test typeof(c1) == SortedDict{String, Int, ForwardOrdering} c2 = SortedDict(Dict("Eggplants"=>6, "Honeydews"=>19, "Melons"=>11)) @@ -1151,7 +1145,7 @@ end # test all the errors of sorted containers m = SortedDict(Dict("a" => 6, "bb" => 9)) @test_throws KeyError println(m["b"]) - m2 = SortedDict{Compat.ASCIIString,Int}() + m2 = SortedDict{String,Int}() @test_throws BoundsError println(first(m2)) @test_throws BoundsError println(last(m2)) state1 = start(m2) @@ -1163,7 +1157,7 @@ end @test_throws BoundsError start(exclusive(m,i1,i2)) @test_throws KeyError delete!(m,"a") @test_throws KeyError pop!(m,"a") - m3 = SortedDict((Dict{Compat.ASCIIString, Int}()), Reverse) + m3 = SortedDict((Dict{String, Int}()), Reverse) @test_throws ArgumentError isequal(m2, m3) @test_throws BoundsError m[i1] @test_throws BoundsError regress((m,beforestartsemitoken(m))) @@ -1210,7 +1204,7 @@ end ## Test use of alternative orderings in test5 keylist = ["Apple", "aPPle", "berry", "CHerry", "Dairy", "diary"] vallist = [6,9,-4,2,1,8] - m = SortedDict{Compat.ASCIIString,Int}() + m = SortedDict{String,Int}() for j = 1:6 m[keylist[j]] = vallist[j] end @@ -1223,7 +1217,7 @@ end p[2] == vallist[expectedord1[count]] end @test count == 6 - m2 = SortedDict((Dict{Compat.ASCIIString, Int}()), Reverse) + m2 = SortedDict((Dict{String, Int}()), Reverse) for j = 1 : 6 m2[keylist[j]] = vallist[j] end @@ -1236,7 +1230,7 @@ end p[2] == vallist[expectedord2[count]] end @test count == 6 - m3 = SortedDict((Dict{Compat.ASCIIString, Int}()), CaseInsensitive()) + m3 = SortedDict((Dict{String, Int}()), CaseInsensitive()) for j = 1 : 6 m3[keylist[j]] = vallist[j] end @@ -1252,11 +1246,11 @@ end end @test count == 5 m3empty = similar(m3) - @test eltype(m3empty) == Pair{Compat.ASCIIString, Int} && + @test eltype(m3empty) == Pair{String, Int} && orderobject(m3empty) == CaseInsensitive() && length(m3empty) == 0 && ordtype(m3empty) == CaseInsensitive && ordtype(typeof(m3empty)) == CaseInsensitive - m4 = SortedDict((Dict{Compat.ASCIIString,Int}()), Lt((x,y) -> isless(lowercase(x),lowercase(y)))) + m4 = SortedDict((Dict{String,Int}()), Lt((x,y) -> isless(lowercase(x),lowercase(y)))) for j = 1 : 6 m4[keylist[j]] = vallist[j] end @@ -1407,7 +1401,7 @@ end @test i1 == pastendsemitoken(factors) @test i2 == beforestartsemitoken(factors) m1 = SortedMultiDict("apples"=>2.0, "apples"=>1.0, "bananas"=>1.5) - @test typeof(m1) == SortedMultiDict{Compat.ASCIIString, Float64, ForwardOrdering} + @test typeof(m1) == SortedMultiDict{String, Float64, ForwardOrdering} checkcorrectness(m1.bt, true) m2 = SortedMultiDict("bananas"=>1.5, "apples"=>2.0, "apples"=>1.0) checkcorrectness(m2.bt, true) @@ -1434,7 +1428,7 @@ end m1 = SortedMultiDict(zip(["bananas", "apples", "cherries", "cherries", "oranges"], [1.0, 2.0, 3.0, 4.0, 5.0])) - @test typeof(m1) == SortedMultiDict{Compat.ASCIIString, Float64, ForwardOrdering} + @test typeof(m1) == SortedMultiDict{String, Float64, ForwardOrdering} m2 = SortedMultiDict(zip(["apples", "cherries", "cherries", "bananas", "plums"], [6.0, 7.0, 8.0, 9.0, 10.0])) m3 = SortedMultiDict(zip(["apples", "apples", "bananas", "bananas", @@ -1442,7 +1436,7 @@ end "oranges", "plums"], [2.0, 6.0, 1.0, 9.0, 3.0, 4.0, 7.0, 8.0, 5.0, 10.0])) m3empty = similar(m3) - @test (eltype(m3empty) == Pair{Compat.ASCIIString, Float64}) && + @test (eltype(m3empty) == Pair{String, Float64}) && orderobject(m3empty) == Forward && length(m3empty) == 0 m4 = merge(m1, m2) @@ -1499,10 +1493,8 @@ end @test typeof(SortedSet{Float64}(Reverse)) == SortedSet{Float64, ReverseOrdering{ForwardOrdering}} @test typeof(SortedSet([1,2,3])) == SortedSet{Int, ForwardOrdering} @test typeof(SortedSet{Float32}([1,2,3])) == SortedSet{Float32, ForwardOrdering} - if VERSION >= v"0.5" - @test typeof(SortedSet(Reverse, [1,2,3])) == SortedSet{Int, ReverseOrdering{ForwardOrdering}} - @test typeof(SortedSet{Float32}(Reverse, [1,2,3])) == SortedSet{Float32, ReverseOrdering{ForwardOrdering}} - end + @test typeof(SortedSet(Reverse, [1,2,3])) == SortedSet{Int, ReverseOrdering{ForwardOrdering}} + @test typeof(SortedSet{Float32}(Reverse, [1,2,3])) == SortedSet{Float32, ReverseOrdering{ForwardOrdering}} @test typeof(SortedSet([1,2,3], Reverse)) == SortedSet{Int, ReverseOrdering{ForwardOrdering}} @test typeof(SortedSet{Float32}([1,2,3], Reverse)) == SortedSet{Float32, ReverseOrdering{ForwardOrdering}} @@ -1606,24 +1598,24 @@ end empty!(m) @test isempty(m) m1 = SortedSet(["blue", "orange", "red"]) - @test typeof(m1) == SortedSet{Compat.ASCIIString, ForwardOrdering} + @test typeof(m1) == SortedSet{String, ForwardOrdering} m2 = SortedSet(["orange", "blue", "red"]) m3 = SortedSet(["orange", "yellow", "red"]) m3empty = similar(m3) - @test typeof(m3empty) == SortedSet{Compat.ASCIIString, ForwardOrdering} - @test eltype(m3empty) == Compat.ASCIIString && + @test typeof(m3empty) == SortedSet{String, ForwardOrdering} + @test eltype(m3empty) == String && length(m3empty) == 0 @test isequal(m1,m2) @test !isequal(m1,m3) @test !isequal(m1, SortedSet(["blue"])) m4 = packcopy(m3) - @test typeof(m4) == SortedSet{Compat.ASCIIString, ForwardOrdering} + @test typeof(m4) == SortedSet{String, ForwardOrdering} @test isequal(m3,m4) m5 = packdeepcopy(m4) - @test typeof(m5) == SortedSet{Compat.ASCIIString, ForwardOrdering} + @test typeof(m5) == SortedSet{String, ForwardOrdering} @test isequal(m3,m4) m6 = deepcopy(m5) - @test typeof(m6) == SortedSet{Compat.ASCIIString, ForwardOrdering} + @test typeof(m6) == SortedSet{String, ForwardOrdering} @test isequal(m3,m5) checkcorrectness(m1.bt, false) checkcorrectness(m2.bt, false) @@ -1632,38 +1624,38 @@ end checkcorrectness(m5.bt, false) checkcorrectness(m5.bt, false) m7 = union(m1, ["yellow"]) - @test typeof(m7) == SortedSet{Compat.ASCIIString, ForwardOrdering} + @test typeof(m7) == SortedSet{String, ForwardOrdering} m8 = union(m3, SortedSet(["blue"])) - @test typeof(m8) == SortedSet{Compat.ASCIIString, ForwardOrdering} + @test typeof(m8) == SortedSet{String, ForwardOrdering} @test isequal(m7,m8) @test !isequal(m1,m8) union!(m1, ["yellow"]) @test isequal(m1,m8) m8a = intersect(m8) - @test typeof(m8a) == SortedSet{Compat.ASCIIString, ForwardOrdering} + @test typeof(m8a) == SortedSet{String, ForwardOrdering} @test isequal(m8a,m8) m9 = intersect(m8, SortedSet(["yellow", "red", "white"])) - @test typeof(m9) == SortedSet{Compat.ASCIIString, ForwardOrdering} + @test typeof(m9) == SortedSet{String, ForwardOrdering} @test isequal(m9, SortedSet(["red", "yellow"])) m9a = intersect(m8, SortedSet(["yellow", "red", "white"]), m8) - @test typeof(m9a) == SortedSet{Compat.ASCIIString, ForwardOrdering} + @test typeof(m9a) == SortedSet{String, ForwardOrdering} @test isequal(m9a, SortedSet(["red", "yellow"])) m10 = symdiff(m8, SortedSet(["yellow", "red", "white"])) - @test typeof(m10) == SortedSet{Compat.ASCIIString, ForwardOrdering} + @test typeof(m10) == SortedSet{String, ForwardOrdering} @test isequal(m10, SortedSet(["white", "blue", "orange"])) m11 = symdiff(m8, SortedSet(["yellow", "red", "blue", "orange", "zinc"])) - @test typeof(m11) == SortedSet{Compat.ASCIIString, ForwardOrdering} + @test typeof(m11) == SortedSet{String, ForwardOrdering} @test isequal(m11, SortedSet(["zinc"])) m12 = symdiff(SortedSet(["yellow", "red", "blue", "orange", "zinc"]), m8) @test isequal(m12, SortedSet(["zinc"])) - @test typeof(m12) == SortedSet{Compat.ASCIIString, ForwardOrdering} + @test typeof(m12) == SortedSet{String, ForwardOrdering} m13 = setdiff(m8, SortedSet(["yellow", "red", "white"])) - @test typeof(m13) == SortedSet{Compat.ASCIIString, ForwardOrdering} + @test typeof(m13) == SortedSet{String, ForwardOrdering} @test isequal(m13, SortedSet(["blue", "orange"])) m14 = setdiff(m8, SortedSet(["blue"])) - @test typeof(m14) == SortedSet{Compat.ASCIIString, ForwardOrdering} + @test typeof(m14) == SortedSet{String, ForwardOrdering} @test isequal(m14, SortedSet(["orange", "yellow", "red"])) @test issubset(["yellow", "blue"], m8) @test !issubset(["blue", "green"], m8) @@ -1676,19 +1668,19 @@ end @testset "SortedDictConstructors" begin sd1 = SortedDict("w" => 64, "p" => 12) - @test typeof(sd1) == SortedDict{Compat.ASCIIString, Int, ForwardOrdering} + @test typeof(sd1) == SortedDict{String, Int, ForwardOrdering} @test length(sd1) == 2 && first(sd1) == ("p"=>12) && last(sd1) == ("w"=>64) sd2 = SortedDict(Reverse, "w" => 64, "p" => 12) - @test typeof(sd2) == SortedDict{Compat.ASCIIString, Int, ReverseOrdering{ForwardOrdering}} + @test typeof(sd2) == SortedDict{String, Int, ReverseOrdering{ForwardOrdering}} @test length(sd2) == 2 && last(sd2) == ("p"=>12) && first(sd2) == ("w"=>64) sd3 = SortedDict(("w"=>64, "p"=>12)) - @test typeof(sd3) == SortedDict{Compat.ASCIIString, Int, ForwardOrdering} + @test typeof(sd3) == SortedDict{String, Int, ForwardOrdering} @test length(sd3) == 2 && first(sd3) == ("p"=>12) && last(sd3) == ("w"=>64) sd4 = SortedDict(("w"=>64, "p"=>12), Reverse) - @test typeof(sd4) == SortedDict{Compat.ASCIIString, Int, ReverseOrdering{ForwardOrdering}} + @test typeof(sd4) == SortedDict{String, Int, ReverseOrdering{ForwardOrdering}} @test length(sd4) == 2 && last(sd4) == ("p"=>12) && first(sd4) == ("w"=>64) @@ -1703,19 +1695,19 @@ end @testset "SortedMultiDictConstructors" begin sm1 = SortedMultiDict("w" => 64, "p" => 12, "p" => 9) - @test typeof(sm1) == SortedMultiDict{Compat.ASCIIString, Int, ForwardOrdering} + @test typeof(sm1) == SortedMultiDict{String, Int, ForwardOrdering} @test length(sm1) == 3 && first(sm1) == ("p"=>12) && last(sm1) == ("w"=>64) sm2 = SortedMultiDict(Reverse, "w" => 64, "p" => 12, "p" => 9) - @test typeof(sm2) == SortedMultiDict{Compat.ASCIIString, Int, ReverseOrdering{ForwardOrdering}} + @test typeof(sm2) == SortedMultiDict{String, Int, ReverseOrdering{ForwardOrdering}} @test length(sm2) == 3 && last(sm2) == ("p"=>9) && first(sm2) == ("w"=>64) sm3 = SortedMultiDict(("w"=>64, "p"=>12, "p"=> 9)) - @test typeof(sm3) == SortedMultiDict{Compat.ASCIIString, Int, ForwardOrdering} + @test typeof(sm3) == SortedMultiDict{String, Int, ForwardOrdering} @test length(sm3) == 3 && first(sm3) == ("p"=>12) && last(sm3) == ("w"=>64) sm4 = SortedMultiDict(("w"=> 64, "p"=>12, "p"=>9), Reverse) - @test typeof(sm4) == SortedMultiDict{Compat.ASCIIString, Int, ReverseOrdering{ForwardOrdering}} + @test typeof(sm4) == SortedMultiDict{String, Int, ReverseOrdering{ForwardOrdering}} @test length(sm4) == 3 && last(sm4) == ("p"=>9) && first(sm4) == ("w"=>64) @@ -1735,8 +1727,8 @@ end # Testset function sorted_dict_timing1(numtrial::Int, expectedk::String, expectedd::String) NSTRINGPAIR = 50000 - m1 = SortedDict{Compat.ASCIIString,Compat.ASCIIString}() - strlist = Compat.ASCIIString[] + m1 = SortedDict{String,String}() + strlist = String[] open(seekfile("wordsScram.txt"), "r") do inio for j = 1 : NSTRINGPAIR * 2 push!(strlist, chomp(readline(inio))) @@ -1772,8 +1764,8 @@ end function sorted_dict_timing2(numtrial::Int, expectedk::String, expectedd::String) NSTRINGPAIR = 50000 - m1 = SortedDict((Dict{Compat.ASCIIString, Compat.ASCIIString}()), Lt(isless)) - strlist = Compat.ASCIIString[] + m1 = SortedDict((Dict{String, String}()), Lt(isless)) + strlist = String[] open(seekfile("wordsScram.txt"), "r") do inio for j = 1 : NSTRINGPAIR * 2 push!(strlist, chomp(readline(inio))) @@ -1818,8 +1810,8 @@ end function sorted_dict_timing3(numtrial::Int, expectedk::String, expectedd::String) NSTRINGPAIR = 50000 - m1 = SDConstruct((Dict{Compat.ASCIIString,Compat.ASCIIString}()), lt=isless) - strlist = Compat.ASCIIString[] + m1 = SDConstruct((Dict{String,String}()), lt=isless) + strlist = String[] open(seekfile("wordsScram.txt"), "r") do inio for j = 1 : NSTRINGPAIR * 2 push!(strlist, chomp(readline(inio))) diff --git a/test/test_sorting.jl b/test/test_sorting.jl index 1b93fb155..108a8be1e 100644 --- a/test/test_sorting.jl +++ b/test/test_sorting.jl @@ -1,10 +1,5 @@ using DataStructures -if VERSION >= v"0.5.0-dev+7720" - using Base.Test -else - using BaseTestNext - const Test = BaseTestNext -end +using Base.Test @testset "DictionarySorting" begin forward = OrderedDict(zip('a':'z', 26:-1:1))