Skip to content

Commit

Permalink
Fix problem with deque clear!
Browse files Browse the repository at this point in the history
  • Loading branch information
Koustav Chowdhury authored and Koustav Chowdhury committed Dec 31, 2023
1 parent 2cd8f52 commit eaea160
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/deque.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ isrear(blk::DequeBlock) = blk.next === blk
# reset the block to empty, and position

function reset!(blk::DequeBlock{T}, front::Int) where T
empty!(blk.data)
blk.data = Vector{T}(undef, blk.capa)
blk.front = front
blk.back = front - 1
blk.prev = blk
Expand Down
15 changes: 15 additions & 0 deletions test/test_deque.jl
Original file line number Diff line number Diff line change
Expand Up @@ -196,5 +196,20 @@
@test length(sprint(dump,q)) >= 0
@test typeof(empty!(q)) === typeof(Deque{Int}())
@test isempty(q)
@test num_blocks(q) == 1
@test q.head === q.rear
@test sizeof(q.head.data) == q.head.capa * sizeof(eltype(q))
end

@testset "push! after empty!" begin
q = Deque{Int}(1)
push!(q,1)
push!(q,2)
empty!(q)
push!(q,3)
@test length(q) == 1
@test first(q) == 3
@test last(q) == 3
@test num_blocks(q) == 1
end
end # @testset Deque

0 comments on commit eaea160

Please sign in to comment.