Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/src/circ_deque.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Usage:
```julia
a = CircularDeque{Int}(n) # allocate a deque with maximum capacity n
isempty(a) # test whether the deque is empty
isfull(a) # test whether the deque is full
empty!(a) # reset the deque
capacity(a) # return capacity
length(a) # get the number of elements currently in the deque
Expand Down
7 changes: 7 additions & 0 deletions src/circ_deque.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ Return the capacity of the circular deque
"""
capacity(D::CircularDeque) = D.capacity

"""
isfull(D::CircularDeque)

Test whether the deque is full.
"""
isfull(D::CircularDeque) = length(D) == D.capacity

function Base.empty!(D::CircularDeque)
D.n = 0
D.first = 1
Expand Down
8 changes: 8 additions & 0 deletions test/test_circ_deque.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@
@test D[7-i] === 6
@test popfirst!(D) === i
end
empty!(D)
@test isfull(D) == false
for i = 1:4
push!(D, 1)
end
@test isfull(D) == false
push!(D, 1)
@test isfull(D) == true
end

@testset "pushfirst! works on an empty deque" begin
Expand Down