Skip to content

Commit 45ac251

Browse files
committed
Deprecate dequeue!(::PriorityQueue[, key])
in favor of Base.popfirst!(pq) and Base.popat!(pq, key).
1 parent 49552a8 commit 45ac251

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

src/DataStructures.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module DataStructures
1515
export complement, complement!
1616

1717
export Deque, Stack, Queue, CircularDeque
18-
export dequeue!, dequeue_pair!, update!
18+
export dequeue_pair!, update!
1919
export capacity, num_blocks, top_with_handle, sizehint!
2020

2121
export Accumulator, counter, reset!, inc!, dec!

src/deprecations.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ Base.@deprecate_binding IntDisjointSets IntDisjointSet
1212
@deprecate enqueue!(q::PriorityQueue, x) Base.push!(q, x)
1313
@deprecate enqueue!(q::PriorityQueue, k, v) Base.push!(q, k=>v)
1414
@deprecate dequeue!(q::Queue) Base.popfirst!(q)
15+
@deprecate dequeue!(q::PriorityQueue) Base.popfirst!(q)
16+
@deprecate dequeue!(q::PriorityQueue, x) Base.popat!(q, x)

src/priorityqueue.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ If an order is not given, the priority queue is min-ordered using
1212
the default comparison for `V`.
1313
1414
A `PriorityQueue` acts like a `Dict`, mapping values to their
15-
priorities, with the addition of a `dequeue!` function to remove the
16-
lowest priority element.
15+
priorities. New elements are added using `push!` and retrieved
16+
using `popfirst!` or `popat!` based on their priority.
1717
1818
```jldoctest
1919
julia> PriorityQueue(Base.Order.Forward, "a" => 2, "b" => 3, "c" => 1)
@@ -242,7 +242,7 @@ end
242242
Base.push!(pq::PriorityQueue{K,V}, kv::Pair) where {K,V} = push!(pq, Pair{K,V}(kv.first, kv.second))
243243

244244
"""
245-
dequeue!(pq)
245+
popfirst!(pq)
246246
247247
Remove and return the lowest priority key from a priority queue.
248248
@@ -253,7 +253,7 @@ PriorityQueue{String, Int64, Base.Order.ForwardOrdering} with 3 entries:
253253
"a" => 2
254254
"b" => 3
255255
256-
julia> dequeue!(a)
256+
julia> popfirst!(a)
257257
"c"
258258
259259
julia> a
@@ -262,9 +262,9 @@ PriorityQueue{String, Int64, Base.Order.ForwardOrdering} with 2 entries:
262262
"b" => 3
263263
```
264264
"""
265-
dequeue!(pq::PriorityQueue) = dequeue_pair!(pq).first
265+
Base.popfirst!(pq::PriorityQueue) = dequeue_pair!(pq).first
266266

267-
dequeue!(pq::PriorityQueue, key) = dequeue_pair!(pq, key).first
267+
Base.popat!(pq::PriorityQueue, key) = dequeue_pair!(pq, key).first
268268

269269
"""
270270
dequeue_pair!(pq)

test/test_priority_queue.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import Base.Order.Reverse
77

88
# Test dequeing in sorted order.
99
function test_issorted!(pq::PriorityQueue, priorities, rev=false)
10-
last = dequeue!(pq)
10+
last = popfirst!(pq)
1111
while !isempty(pq)
12-
value = dequeue!(pq)
12+
value = popfirst!(pq)
1313
if !rev
1414
@test priorities[last] <= priorities[value]
1515
else
@@ -23,7 +23,7 @@ import Base.Order.Reverse
2323
i = 0
2424
while !isempty(pq)
2525
krqst = keys[i+=1]
26-
krcvd = dequeue!(pq, krqst)
26+
krcvd = popat!(pq, krqst)
2727
@test krcvd == krqst
2828
end
2929
end
@@ -110,13 +110,13 @@ import Base.Order.Reverse
110110
@testset "PriorityQueueMethods" begin
111111
pq1 = PriorityQueue('a'=>1, 'b'=>2)
112112

113-
@testset "peek/get/dequeue!/get!" begin
113+
@testset "peek/get/popfirst!/get!" begin
114114
@test peek(pq1) == ('a'=>1)
115115
@test get(pq1, 'a', 0) == 1
116116
@test get(pq1, 'c', 0) == 0
117117
@test get!(pq1, 'b', 20) == 2
118-
@test dequeue!(pq1) == 'a'
119-
@test dequeue!(pq1) == 'b'
118+
@test popfirst!(pq1) == 'a'
119+
@test popfirst!(pq1) == 'b'
120120
@test get!(pq1, 'c', 0) == 0
121121
@test peek(pq1) == ('c'=>0)
122122
@test get!(pq1, 'c', 3) == 0
@@ -190,15 +190,15 @@ import Base.Order.Reverse
190190

191191
@testset "dequeuing" begin
192192
pq = PriorityQueue(priorities)
193-
@test_throws KeyError dequeue!(pq, 0)
193+
@test_throws KeyError popat!(pq, 0)
194194

195-
@test 10 == dequeue!(pq, 10)
195+
@test 10 == popat!(pq, 10)
196196
while !isempty(pq)
197-
@test 10 != dequeue!(pq)
197+
@test 10 != popfirst!(pq)
198198
end
199199

200200
pq = PriorityQueue(1.0 => 1)
201-
@test dequeue!(pq, 1.0f0) isa Float64
201+
@test popat!(pq, 1.0f0) isa Float64
202202
end
203203

204204
@testset "dequeuing pair" begin

0 commit comments

Comments
 (0)