Skip to content

Commit

Permalink
Manually implement push! and append!
Browse files Browse the repository at this point in the history
  • Loading branch information
Vexatos committed Apr 18, 2024
1 parent 137bf28 commit 51dcce5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/CircularArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ CircularMatrix(def::T, size::NTuple{2, Integer}) where T = CircularMatrix{T}(fil

Base.empty(::CircularVector{T}, ::Type{U}=T) where {T,U} = CircularVector{U}(U[])
Base.empty!(a::CircularVector) = (empty!(parent(a)); a)
# push!, append! can be used by `resize!` method.
Base.push!(a::CircularVector, x...) = (push!(parent(a), x...); a)
Base.append!(a::CircularVector, items) = (append!(parent(a), items); a)
Base.resize!(a::CircularVector, nl::Integer) = (resize!(parent(a), nl); a)
Base.pop!(a::CircularVector) = pop!(parent(a))
Base.sizehint!(a::CircularVector, sz::Integer) = (sizehint!(parent(a), sz); a)
Expand Down
8 changes: 4 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ end
end

@testset "sizehint!" begin
A = CircularVector([1,2,3,4,5,6,7])
resize!(A, 1)
sizehint!(A, 1)
@test length(A) == 1
v = CircularVector([1,2,3,4,5,6,7])
resize!(v, 1)
sizehint!(v, 1)
@test length(v) == 1
end

@testset "deleteat!" begin
Expand Down

0 comments on commit 51dcce5

Please sign in to comment.