Empty head block's data when the block is reset#888
Merged
eulerkochy merged 2 commits intoJuliaCollections:masterfrom Jan 5, 2024
Merged
Empty head block's data when the block is reset#888eulerkochy merged 2 commits intoJuliaCollections:masterfrom
eulerkochy merged 2 commits intoJuliaCollections:masterfrom
Conversation
oxinabox
reviewed
Jan 2, 2024
Comment on lines
+41
to
+42
| empty!(blk.data) | ||
| blk.data = Vector{T}(undef, blk.capa) |
Member
There was a problem hiding this comment.
Why empty it if its just going to be over written with a newly allocated array?
I would think just:
Suggested change
| empty!(blk.data) | |
| blk.data = Vector{T}(undef, blk.capa) | |
| empty!(blk.data) |
would be enough.
(and it's nonallocating)
Member
Author
There was a problem hiding this comment.
The underlying the assumption of a block is that it's data field will have already data field allocated with capa number of elements. Just emptying and not allocating block's data leads to the problem that once you have cleared the deque, you can't push elements into it again. That's why I've added new testset push! after empty! to check this scenario.
Member
There was a problem hiding this comment.
So we want:
Suggested change
| empty!(blk.data) | |
| blk.data = Vector{T}(undef, blk.capa) | |
| # Fill it with undefs/junk data back to capacity | |
| empty!(blk.data); resize!(blk.data, blk.capa) |
?
oxinabox
approved these changes
Jan 2, 2024
kpamnany
pushed a commit
to kpamnany/DataStructures.jl
that referenced
this pull request
Feb 16, 2024
Empty head block's data when the block is reset
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #884