Skip to content

Commit

Permalink
remove deprecations, including lingering references to top
Browse files Browse the repository at this point in the history
  • Loading branch information
oxinabox committed Aug 4, 2020
1 parent c3b0927 commit bbefdf7
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 60 deletions.
6 changes: 3 additions & 3 deletions docs/src/heaps.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ isempty(h) # returns whether the heap is empty

push!(h, v) # add a value to the heap

top(h) # return the top value of a heap
first(h) # return the first (top) value of a heap

pop!(h) # removes the top value, and returns it
pop!(h) # removes the first (top) value, and returns it

```

Expand Down Expand Up @@ -73,7 +73,7 @@ popmax!(h, k) # remove and return the largest k elements
popall!(h) # remove and return all the elements, sorted smallest to largest
popall!(h, o) # remove and return all the elements according to ordering o
```
The usual `top(h)` and `pop!(h)` are defined to be `minimum(h)` and `popmin!(h)`,
The usual `first(h)` and `pop!(h)` are defined to be `minimum(h)` and `popmin!(h)`,
respectively.

This package includes an implementation of a binary min-max heap (`BinaryMinMaxHeap`).
Expand Down
3 changes: 0 additions & 3 deletions src/default_dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ DefaultDictBase{K,V}(default::F; kwargs...) where {K,V,F} = DefaultDictBase{K,V,
@delegate_return_parent DefaultDictBase.d [ delete!, empty!, setindex!, sizehint! ]

empty(d::DefaultDictBase{K,V,F}) where {K,V,F} = DefaultDictBase{K,V,F}(d.default; passkey=d.passkey)
@deprecate similar(d::DefaultDictBase) empty(d)

getindex(d::DefaultDictBase, key) = get!(d.d, key, d.default)

Expand Down Expand Up @@ -144,8 +143,6 @@ for _Dict in [:Dict, :OrderedDict]

empty(d::$DefaultDict{K,V,F}) where {K,V,F} = $DefaultDict{K,V,F}(d.d.default)
in(key, v::Base.KeySet{K,T}) where {K,T<:$DefaultDict{K}} = key in keys(v.dict.d.d)

@deprecate similar(d::$DefaultDict) empty(d)
end
end

Expand Down
13 changes: 3 additions & 10 deletions src/deprecations.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
@deprecate front(x) first(x)
@deprecate back(x) last(x)
@deprecate top(x) first(x)
#@deprecate find_root find_root! # 2020-03-31 - deprecate in v0.18, or when Julia 1.5 is released.
export find_root
const find_root = find_root!

@deprecate deque(::Type{T}) where {T} Deque{T}()

@deprecate path(t::Trie, str::AbstractString) partial_path(t::Trie, str::AbstractString)
# 0.18 deprecations. Remove before releasing 0.19
@deprecate path(t::Trie, str::AbstractString) partial_path(t::Trie, str::AbstractString)
@deprecate find_root find_root!
6 changes: 3 additions & 3 deletions src/heaps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
#
# - sizehint!(h, s) set size hint to a heap
#
# - top(h) return the top value of a heap
# - first(h) return the first (top) value of a heap
#
# - pop!(h) removes the top value, and
# - pop!(h) removes the first (top) value, and
# returns it
#
# For mutable heaps, it should also support
Expand Down Expand Up @@ -113,7 +113,7 @@ function nextreme(comp::Comp, n::Int, arr::AbstractVector{T}) where {T, Comp}

for i = n + 1 : length(arr)
@inbounds xi = arr[i]
if compare(comp, top(buffer), xi)
if compare(comp, first(buffer), xi)
# This could use a pushpop method
pop!(buffer)
push!(buffer, xi)
Expand Down
4 changes: 2 additions & 2 deletions src/heaps/binary_heap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ function sizehint!(h::BinaryHeap, s::Integer)
end

"""
top(h::BinaryHeap)
first(h::BinaryHeap)
Returns the element at the top of the heap `h`.
"""
@inline top(h::BinaryHeap) = h.valtree[1]
@inline first(h::BinaryHeap) = h.valtree[1]

pop!(h::BinaryHeap{T}) where {T} = _binary_heap_pop!(h.comparer, h.valtree)
6 changes: 3 additions & 3 deletions src/heaps/minmax_heap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,11 @@ function push!(h::BinaryMinMaxHeap, v)
end

"""
top(h::BinaryMinMaxHeap)
first(h::BinaryMinMaxHeap)
Get the top (minimum) of the heap.
Get the first (minimum) of the heap.
"""
@inline top(h::BinaryMinMaxHeap) = minimum(h)
@inline first(h::BinaryMinMaxHeap) = minimum(h)

@inline function minimum(h::BinaryMinMaxHeap)
valtree = h.valtree
Expand Down
10 changes: 1 addition & 9 deletions src/heaps/mutable_binary_heap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,6 @@ const MutableBinaryMaxHeap{T} = MutableBinaryHeap{T, GreaterThan}
MutableBinaryMinHeap(xs::AbstractVector{T}) where T = MutableBinaryMinHeap{T}(xs)
MutableBinaryMaxHeap(xs::AbstractVector{T}) where T = MutableBinaryMaxHeap{T}(xs)

# deprecated constructors

@deprecate mutable_binary_minheap(::Type{T}) where {T} MutableBinaryMinHeap{T}()
@deprecate mutable_binary_minheap(xs::AbstractVector{T}) where {T} MutableBinaryMinHeap(xs)
@deprecate mutable_binary_maxheap(::Type{T}) where {T} MutableBinaryMaxHeap{T}()
@deprecate mutable_binary_maxheap(xs::AbstractVector{T}) where {T} MutableBinaryMaxHeap(xs)


function show(io::IO, h::MutableBinaryHeap)
print(io, "MutableBinaryHeap(")
nodes = h.nodes
Expand Down Expand Up @@ -227,7 +219,7 @@ function sizehint!(h::MutableBinaryHeap, s::Integer)
return h
end

@inline top(h::MutableBinaryHeap) = h.nodes[1].value
@inline first(h::MutableBinaryHeap) = h.nodes[1].value

"""
top_with_handle(h::MutableBinaryHeap)
Expand Down
2 changes: 0 additions & 2 deletions src/multi_dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ empty(d::MultiDict{K,V}) where {K,V} = MultiDict{K,V}()
delete!(d::MultiDict, key) = (delete!(d.d, key); d)
empty!(d::MultiDict) = (empty!(d.d); d)

@deprecate similar(d::MultiDict) empty(d)

function insert!(d::MultiDict{K,V}, k, v) where {K,V}
if !haskey(d.d, k)
d.d[k] = V[]
Expand Down
2 changes: 0 additions & 2 deletions src/sorted_dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,4 @@ empty). Time: O(1)
empty(m::SortedDict{K,D,Ord}) where {K,D,Ord<:Ordering} =
SortedDict{K,D,Ord}(orderobject(m))

@deprecate similar(m::SortedDict) empty(m)

isordered(::Type{T}) where {T<:SortedDict} = true
4 changes: 2 additions & 2 deletions test/test_binheap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@test length(h) == 10
@test !isempty(h)
@test top(h) == 1
@test first(h) == 1
@test isequal(h.valtree, [1, 2, 3, 4, 7, 9, 10, 14, 8, 16])
@test sizehint!(h, 100) === h
end
Expand All @@ -20,7 +20,7 @@

@test length(h) == 10
@test !isempty(h)
@test top(h) == 16
@test first(h) == 16
@test isequal(h.valtree, [16, 14, 10, 8, 7, 3, 9, 1, 4, 2])
@test sizehint!(h, 100) === h
end
Expand Down
5 changes: 0 additions & 5 deletions test/test_deque.jl
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,4 @@
@test typeof(empty!(q)) === typeof(Deque{Int}())
@test isempty(q)
end

@testset "deprecated constructors" begin
@test_deprecated deque(Int)
end

end # @testset Deque
6 changes: 2 additions & 4 deletions test/test_minmax_heap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ using Base.Order: Forward, Reverse
h = BinaryMinMaxHeap(vs)
@test length(h) == 10
@test !isempty(h)
@test top(h) == minimum(h) == 1
@test first(h) == minimum(h) == 1
@test maximum(h) == 20
@test is_minmax_heap(h.valtree)
end
Expand All @@ -48,7 +48,7 @@ using Base.Order: Forward, Reverse
@test isempty(h)

push!(h, 1)
@test top(h) == 1
@test first(h) == 1
push!(h, 2)
@test is_minmax_heap(h.valtree)
push!(h, 10)
Expand Down Expand Up @@ -163,10 +163,8 @@ using Base.Order: Forward, Reverse
h = BinaryMinMaxHeap{Int}()
@test_throws ArgumentError pop!(h)
@test_throws ArgumentError popmin!(h)

@test_throws ArgumentError popmax!(h)

@test_throws ArgumentError top(h)
@test_throws ArgumentError minimum(h)
@test_throws ArgumentError maximum(h)

Expand Down
14 changes: 2 additions & 12 deletions test/test_mutable_binheap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ end

@test length(h) == 10
@test !isempty(h)
@test top(h) == 1
@test first(h) == 1
@test isequal(list_values(h), vs)
@test isequal(heap_values(h), [1, 2, 3, 4, 7, 9, 10, 14, 8, 16])
@test sizehint!(h, 100) === h
Expand All @@ -79,7 +79,7 @@ end

@test length(h) == 10
@test !isempty(h)
@test top(h) == 16
@test first(h) == 16
@test isequal(list_values(h), vs)
@test isequal(heap_values(h), [16, 14, 10, 8, 7, 3, 9, 1, 4, 2])
@test sizehint!(h, 100) === h
Expand Down Expand Up @@ -262,14 +262,4 @@ end
update!(h, 2, 20)
@test isequal(heap_values(h), [0.5, 10.1, 3.0, 20.0])
end

# test deprecated constructors
@testset "deprecated constructors" begin
@test_deprecated mutable_binary_minheap(Int)
@test_deprecated mutable_binary_minheap([1., 2., 3.])
@test_deprecated mutable_binary_maxheap(Int)
@test_deprecated mutable_binary_maxheap([1., 2., 3.])
end


end # @testset MutableBinheap

0 comments on commit bbefdf7

Please sign in to comment.