Skip to content

Commit

Permalink
Fix blocks in popfirst (#344)
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub committed Mar 21, 2024
1 parent ac4df2a commit f87ad0c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "BlockArrays"
uuid = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
version = "0.16.39"
version = "0.16.40"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand Down
7 changes: 3 additions & 4 deletions src/blockdeque.jl
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,12 @@ function Base.popfirst!(A::BlockVector)
isempty(A) && throw(Argument("array must be nonempty"))
_squash_firsts!(A)
x = popfirst!(A.blocks[1])
ax, = A.axes
lasts = blocklasts(A.axes[1])
if isempty(A.blocks[1])
popfirst!(A.blocks)
popfirst!(blocklasts(ax))
else
blocklasts(ax)[1] -= 1
popfirst!(lasts)
end
lasts .-= 1
return x
end

Expand Down
14 changes: 14 additions & 0 deletions test/test_blockdeque.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ using BlockArrays, Test
@test pop!(B) == 6
@test B == 1:5
@test !any(isempty, blocks(B))
@test blocksizes(B,1) == [1,2,2]
end
end

Expand All @@ -176,5 +177,18 @@ using BlockArrays, Test
end
@test A == []
@test B == 1:5

A = BlockArray([1:6;], [2,2,2])
@test popfirst!(A) == 1
@test A == 2:6
@test blocksizes(A,1) == [1,2,2]

@testset "empty blocks" begin
B = BlockArray([1:6;], [0,0,1,2,3])
@test popfirst!(B) == 1
@test B == 2:6
@test blocksizes(B,1) == [2,3]
@test !any(isempty, blocks(B))
end
end
end

2 comments on commit f87ad0c

@jishnub
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/103322

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.16.40 -m "<description of version>" f87ad0cc8e3b562614e92dba0dd21990906d3076
git push origin v0.16.40

Please sign in to comment.