Skip to content

Commit eaea160

Browse files
Koustav ChowdhuryKoustav Chowdhury
authored andcommitted
Fix problem with deque clear!
1 parent 2cd8f52 commit eaea160

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/deque.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ isrear(blk::DequeBlock) = blk.next === blk
3838
# reset the block to empty, and position
3939

4040
function reset!(blk::DequeBlock{T}, front::Int) where T
41+
empty!(blk.data)
42+
blk.data = Vector{T}(undef, blk.capa)
4143
blk.front = front
4244
blk.back = front - 1
4345
blk.prev = blk

test/test_deque.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,5 +196,20 @@
196196
@test length(sprint(dump,q)) >= 0
197197
@test typeof(empty!(q)) === typeof(Deque{Int}())
198198
@test isempty(q)
199+
@test num_blocks(q) == 1
200+
@test q.head === q.rear
201+
@test sizeof(q.head.data) == q.head.capa * sizeof(eltype(q))
202+
end
203+
204+
@testset "push! after empty!" begin
205+
q = Deque{Int}(1)
206+
push!(q,1)
207+
push!(q,2)
208+
empty!(q)
209+
push!(q,3)
210+
@test length(q) == 1
211+
@test first(q) == 3
212+
@test last(q) == 3
213+
@test num_blocks(q) == 1
199214
end
200215
end # @testset Deque

0 commit comments

Comments
 (0)