Skip to content

Commit a662631

Browse files
committed
Rename append_nocopy! to blockappend!, clarify its behavior
1 parent 2ad7c61 commit a662631

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/blockdeque.jl

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Base.append!(dest::BlockVector, sources...; alias::Bool = false) =
1616

1717
function Base.append!(dest::BlockVector, src; alias::Bool = false)
1818
if _blocktype(dest) === _blocktype(src) && alias
19-
return append_nocopy!(dest, src)
19+
return blockappend!(dest, src)
2020
else
2121
return append_copy!(dest, src)
2222
end
@@ -27,20 +27,27 @@ _blocktype(::T) where {T<:AbstractArray} = T
2727
_blocktype(::BlockArray{<:Any,<:Any,<:AbstractArray{T}}) where {T<:AbstractArray} = T
2828
_blocktype(::PseudoBlockArray{<:Any,<:Any,T}) where {T<:AbstractArray} = T
2929

30-
function append_nocopy!(dest::BlockVector{<:Any,T}, src::BlockVector{<:Any,T}) where {T}
30+
"""
31+
blockappend!(dest::BlockVector, src)
32+
33+
Append blocks from `src` to `dest`. When `src` is a vector of the same type
34+
as the blocks of `dest`, or a `PseudoBlockVector` with the same underlying
35+
array type, a single vector block is appended to `dest`.
36+
"""
37+
function blockappend!(dest::BlockVector{<:Any,T}, src::BlockVector{<:Any,T}) where {T}
3138
isempty(src) && return dest
3239
append!(dest.blocks, src.blocks)
3340
offset = last(dest.axes[1]) + 1 - src.axes[1].first
3441
append!(dest.axes[1].lasts, (n + offset for n in src.axes[1].lasts))
3542
return dest
3643
end
3744

38-
append_nocopy!(
45+
blockappend!(
3946
dest::BlockVector{<:Any,<:AbstractArray{T}},
4047
src::PseudoBlockVector{<:Any,T},
41-
) where {T} = append_nocopy!(dest, src.blocks)
48+
) where {T} = blockappend!(dest, src.blocks)
4249

43-
function append_nocopy!(dest::BlockVector{<:Any,<:AbstractArray{T}}, src::T) where {T}
50+
function blockappend!(dest::BlockVector{<:Any,<:AbstractArray{T}}, src::T) where {T}
4451
isempty(src) && return dest
4552
push!(dest.blocks, src)
4653
push!(dest.axes[1].lasts, last(dest.axes[1]) + length(src))

test/test_blockdeque.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ using BlockArrays, Test
2525

2626
@test append!(dest, src; alias = alias) === dest
2727
@test dest == 1:9
28+
29+
@test dest[Block(1)] == [1, 2, 3]
30+
if alias && compatible
31+
@test dest[Block(2)] == [4, 5]
32+
if srctype === :BlockVector
33+
@test dest[Block(3)] == [6, 7]
34+
@test dest[Block(4)] == [8, 9]
35+
else
36+
@test dest[Block(3)] == [6, 7, 8, 9]
37+
end
38+
else
39+
@test dest[Block(2)] == 4:9
40+
end
41+
2842
src[1] = 666
2943
if alias && compatible
3044
@test dest[6] == 666

0 commit comments

Comments
 (0)