From 2aab8ab54ab1efb481e6a545b4aafc5de8ae6d54 Mon Sep 17 00:00:00 2001 From: "Yoga14s\\CXIN" Date: Sat, 9 Apr 2022 10:22:54 +0800 Subject: [PATCH 1/3] add `isfull` for `CircularDeque` --- src/circ_deque.jl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/circ_deque.jl b/src/circ_deque.jl index 3159d7d6a..4d7640415 100644 --- a/src/circ_deque.jl +++ b/src/circ_deque.jl @@ -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 From c5f76829522eb2281bd16d7c4ff5049b8ba32a33 Mon Sep 17 00:00:00 2001 From: "Yoga14s\\CXIN" Date: Sat, 9 Apr 2022 10:29:13 +0800 Subject: [PATCH 2/3] add some tests for `CircularDeque`'s `isfull` --- test/test_circ_deque.jl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/test_circ_deque.jl b/test/test_circ_deque.jl index adf3ddd6d..3ff729b10 100644 --- a/test/test_circ_deque.jl +++ b/test/test_circ_deque.jl @@ -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 From dff446a236461cded28c2c0298c7f11fb8ce8fcd Mon Sep 17 00:00:00 2001 From: "Yoga14s\\CXIN" Date: Sat, 9 Apr 2022 10:30:32 +0800 Subject: [PATCH 3/3] Update docs --- docs/src/circ_deque.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/src/circ_deque.md b/docs/src/circ_deque.md index d39062a33..eb9697085 100644 --- a/docs/src/circ_deque.md +++ b/docs/src/circ_deque.md @@ -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