From bbefdf7ea2bc9fd5aabed17bcdf5e1bb329e7450 Mon Sep 17 00:00:00 2001 From: Lyndon White Date: Sat, 11 Jul 2020 18:32:11 +0100 Subject: [PATCH] remove deprecations, including lingering references to `top` --- docs/src/heaps.md | 6 +++--- src/default_dict.jl | 3 --- src/deprecations.jl | 13 +++---------- src/heaps.jl | 6 +++--- src/heaps/binary_heap.jl | 4 ++-- src/heaps/minmax_heap.jl | 6 +++--- src/heaps/mutable_binary_heap.jl | 10 +--------- src/multi_dict.jl | 2 -- src/sorted_dict.jl | 2 -- test/test_binheap.jl | 4 ++-- test/test_deque.jl | 5 ----- test/test_minmax_heap.jl | 6 ++---- test/test_mutable_binheap.jl | 14 ++------------ 13 files changed, 21 insertions(+), 60 deletions(-) diff --git a/docs/src/heaps.md b/docs/src/heaps.md index 01eab0930..0f7b7c4d3 100644 --- a/docs/src/heaps.md +++ b/docs/src/heaps.md @@ -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 ``` @@ -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`). diff --git a/src/default_dict.jl b/src/default_dict.jl index a9f600e26..64a3c4aee 100644 --- a/src/default_dict.jl +++ b/src/default_dict.jl @@ -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) @@ -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 diff --git a/src/deprecations.jl b/src/deprecations.jl index 3158d2093..276c2fedb 100644 --- a/src/deprecations.jl +++ b/src/deprecations.jl @@ -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) \ No newline at end of file +# 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! diff --git a/src/heaps.jl b/src/heaps.jl index 28a471cd3..f4d370521 100644 --- a/src/heaps.jl +++ b/src/heaps.jl @@ -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 @@ -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) diff --git a/src/heaps/binary_heap.jl b/src/heaps/binary_heap.jl index 0dcd1681a..15084c160 100644 --- a/src/heaps/binary_heap.jl +++ b/src/heaps/binary_heap.jl @@ -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) diff --git a/src/heaps/minmax_heap.jl b/src/heaps/minmax_heap.jl index 1b52fe468..f3d3cd5fc 100644 --- a/src/heaps/minmax_heap.jl +++ b/src/heaps/minmax_heap.jl @@ -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 diff --git a/src/heaps/mutable_binary_heap.jl b/src/heaps/mutable_binary_heap.jl index 8b1cc005e..5df4f74eb 100644 --- a/src/heaps/mutable_binary_heap.jl +++ b/src/heaps/mutable_binary_heap.jl @@ -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 @@ -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) diff --git a/src/multi_dict.jl b/src/multi_dict.jl index 7ac05b125..a78037b9d 100644 --- a/src/multi_dict.jl +++ b/src/multi_dict.jl @@ -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[] diff --git a/src/sorted_dict.jl b/src/sorted_dict.jl index 278cc13a8..324935e01 100644 --- a/src/sorted_dict.jl +++ b/src/sorted_dict.jl @@ -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 diff --git a/test/test_binheap.jl b/test/test_binheap.jl index 4631668be..685291735 100644 --- a/test/test_binheap.jl +++ b/test/test_binheap.jl @@ -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 @@ -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 diff --git a/test/test_deque.jl b/test/test_deque.jl index 6241823b0..8c35ba289 100644 --- a/test/test_deque.jl +++ b/test/test_deque.jl @@ -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 diff --git a/test/test_minmax_heap.jl b/test/test_minmax_heap.jl index e8a77165b..5a92be911 100644 --- a/test/test_minmax_heap.jl +++ b/test/test_minmax_heap.jl @@ -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 @@ -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) @@ -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) diff --git a/test/test_mutable_binheap.jl b/test/test_mutable_binheap.jl index a817da27e..7c0a0b542 100644 --- a/test/test_mutable_binheap.jl +++ b/test/test_mutable_binheap.jl @@ -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 @@ -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 @@ -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