Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix resize! on ChainedVector #111

Merged
merged 1 commit into from
Dec 12, 2024
Merged

Fix resize! on ChainedVector #111

merged 1 commit into from
Dec 12, 2024

Conversation

laborg
Copy link
Contributor

@laborg laborg commented Dec 11, 2024

Fix #110

The last chunk wasn't handled properly when resizing, leading to errors downstream in sort, unique! and so on.

@@ -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))
Copy link
Contributor

Choose a reason for hiding this comment

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

An alternative (unsure what is more readable):

Suggested change
resize!(A.arrays[chunk], length(A.arrays[chunk]) - (A.inds[chunk] - len))
resize!(A.arrays[chunk], chunk == 1 ? len : len - A.inds[chunk - 1])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I prefer branchless code and length should be O(1) in most cases... But its your call.

Copy link
Member

@quinnj quinnj left a comment

Choose a reason for hiding this comment

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

Thanks!

@quinnj quinnj merged commit 96714b2 into JuliaData:main Dec 12, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Correctness issues and errors after sorting
3 participants