Skip to content

Commit

Permalink
Merge pull request #888 from eulerkochy/fix_deque
Browse files Browse the repository at this point in the history
Empty head block's data when the block is reset
  • Loading branch information
eulerkochy authored Jan 5, 2024
2 parents 2cd8f52 + 6dc9f8a commit 83ecd27
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)
resize!(blk.data, 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 83ecd27

Please sign in to comment.