Skip to content

Commit 49552a8

Browse files
committed
Deprecate enqueue!(::PriorityQueue, ...) in favor of Base.push!
1 parent f57330a commit 49552a8

File tree

4 files changed

+19
-24
lines changed

4 files changed

+19
-24
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 enqueue!, dequeue!, dequeue_pair!, update!
18+
export dequeue!, 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
@@ -9,4 +9,6 @@ Base.@deprecate_binding IntDisjointSets IntDisjointSet
99
@deprecate DisjointSets(xs...) DisjointSet(xs)
1010
# Enqueue and dequeue deprecations
1111
@deprecate enqueue!(q::Queue, x) Base.push!(q, x)
12+
@deprecate enqueue!(q::PriorityQueue, x) Base.push!(q, x)
13+
@deprecate enqueue!(q::PriorityQueue, k, v) Base.push!(q, k=>v)
1214
@deprecate dequeue!(q::Queue) Base.popfirst!(q)

src/priorityqueue.jl

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
PriorityQueue{K, V}([ord])
88
99
Construct a new [`PriorityQueue`](@ref), with keys of type
10-
`K` and values/priorites of type `V`.
10+
`K` and values/priorities of type `V`.
1111
If an order is not given, the priority queue is min-ordered using
1212
the default comparison for `V`.
1313
@@ -183,14 +183,14 @@ end
183183
function Base.get!(pq::PriorityQueue, key, default)
184184
i = get(pq.index, key, 0)
185185
if i == 0
186-
enqueue!(pq, key, default)
186+
push!(pq, key=>default)
187187
return default
188188
else
189189
return pq.xs[i].second
190190
end
191191
end
192192

193-
# Change the priority of an existing element, or equeue it if it isn't present.
193+
# Change the priority of an existing element, or enqueue it if it isn't present.
194194
function Base.setindex!(pq::PriorityQueue{K, V}, value, key) where {K,V}
195195
i = get(pq.index, key, 0)
196196
if i != 0
@@ -202,32 +202,32 @@ function Base.setindex!(pq::PriorityQueue{K, V}, value, key) where {K,V}
202202
percolate_up!(pq, i)
203203
end
204204
else
205-
enqueue!(pq, key, value)
205+
push!(pq, key=>value)
206206
end
207207
return value
208208
end
209209

210210
"""
211-
enqueue!(pq, k=>v)
211+
push!(pq, k=>v)
212212
213213
Insert the a key `k` into a priority queue `pq` with priority `v`.
214214
215215
```jldoctest
216-
julia> a = PriorityQueue(PriorityQueue("a"=>1, "b"=>2, "c"=>3))
216+
julia> a = PriorityQueue("a"=>1, "b"=>2, "c"=>3)
217217
PriorityQueue{String, Int64, Base.Order.ForwardOrdering} with 3 entries:
218218
"a" => 1
219219
"b" => 2
220220
"c" => 3
221221
222-
julia> enqueue!(a, "d"=>4)
222+
julia> push!(a, "d"=>4)
223223
PriorityQueue{String, Int64, Base.Order.ForwardOrdering} with 4 entries:
224224
"a" => 1
225225
"b" => 2
226226
"c" => 3
227227
"d" => 4
228228
```
229229
"""
230-
function enqueue!(pq::PriorityQueue{K,V}, pair::Pair{K,V}) where {K,V}
230+
function Base.push!(pq::PriorityQueue{K,V}, pair::Pair{K,V}) where {K,V}
231231
key = pair.first
232232
if haskey(pq, key)
233233
throw(ArgumentError("PriorityQueue keys must be unique"))
@@ -239,14 +239,7 @@ function enqueue!(pq::PriorityQueue{K,V}, pair::Pair{K,V}) where {K,V}
239239
return pq
240240
end
241241

242-
"""
243-
enqueue!(pq, k, v)
244-
245-
Insert the a key `k` into a priority queue `pq` with priority `v`.
246-
247-
"""
248-
enqueue!(pq::PriorityQueue, key, value) = enqueue!(pq, key=>value)
249-
enqueue!(pq::PriorityQueue{K,V}, kv) where {K,V} = enqueue!(pq, Pair{K,V}(kv.first, kv.second))
242+
Base.push!(pq::PriorityQueue{K,V}, kv::Pair) where {K,V} = push!(pq, Pair{K,V}(kv.first, kv.second))
250243

251244
"""
252245
dequeue!(pq)

test/test_priority_queue.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,30 +136,30 @@ import Base.Order.Reverse
136136
@testset "enqueue error throw" begin
137137
ks, vs = 1:n, rand(1:pmax, n)
138138
pq = PriorityQueue(zip(ks, vs))
139-
@test_throws ArgumentError enqueue!(pq, 1, 10)
139+
@test_throws ArgumentError push!(pq, 1=>10)
140140
end
141141

142142
@testset "Iteration" begin
143143
pq = PriorityQueue(priorities)
144144
pq2 = PriorityQueue()
145145
for kv in pq
146-
enqueue!(pq2, kv)
146+
push!(pq2, kv)
147147
end
148148
@test pq == pq2
149149
end
150150

151-
@testset "enqueing pairs via enqueue!" begin
151+
@testset "enqueing pairs via push!" begin
152152
pq = PriorityQueue()
153153
for kv in priorities
154-
enqueue!(pq, kv)
154+
push!(pq, kv)
155155
end
156156
test_issorted!(pq, priorities)
157157
end
158158

159-
@testset "enqueing values via enqueue!" begin
159+
@testset "enqueing values via push!" begin
160160
pq = PriorityQueue()
161161
for (k, v) in priorities
162-
enqueue!(pq, k, v)
162+
push!(pq, k=>v)
163163
end
164164
test_issorted!(pq, priorities)
165165
end
@@ -222,7 +222,7 @@ import Base.Order.Reverse
222222
@test !isempty(pq)
223223
empty!(pq)
224224
@test isempty(pq)
225-
enqueue!(pq, "a"=>2)
225+
push!(pq, "a"=>2)
226226
@test length(pq) == 1
227227
end
228228
end

0 commit comments

Comments
 (0)