Skip to content

Commit

Permalink
properly resize last chunk of chained vector on resize! (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
laborg authored Dec 12, 2024
1 parent a2976cb commit 96714b2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/chainedvector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,8 @@ function Base.resize!(A::ChainedVector{T, AT}, len) where {T, AT}
resize!(A.arrays, chunk)
resize!(A.inds, chunk)
# resize individual chunk
resize!(A.arrays[chunk], A.inds[chunk] - len)
A.inds[chunk] -= A.inds[chunk] - len
resize!(A.arrays[chunk], length(A.arrays[chunk]) - (A.inds[chunk] - len))
A.inds[chunk] = len
end
return A
end
Expand Down
14 changes: 14 additions & 0 deletions test/chainedvector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,20 @@ end
@test BitVector(x) == [true, false, true]
end

# https://github.com/JuliaData/SentinelArrays.jl/issues/110
@testset "Resizing ChainedVector" begin
c = ChainedVector([[:a],[:b1,:b2,:b3],[:c]])
@test length(resize!(c,6)) == 6
@test resize!(c,5) == [:a,:b1,:b2,:b3,:c]
@test resize!(c,4) == [:a,:b1,:b2,:b3]
@test resize!(c,3) == [:a,:b1,:b2]
@test resize!(c,2) == [:a,:b1]
@test resize!(c,1) == [:a]
@test resize!(c,0) == []

@test sum(unique!(ChainedVector([[1],[2],[3]]))) == 6
end

@testset "MissingVector resizing" begin
v = MissingVector(1)
@test isequal(push!(v, missing), [missing, missing])
Expand Down

0 comments on commit 96714b2

Please sign in to comment.