Fixed bug when initialising bitv from init=true #11615
Merged
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.
This is my first patch so feedback appreciated!
Bug when initialising
bitv:Bitv::new(int,bool)
whenbool=true
. It created aBitv
with underlying representation!0u
rather than the actual desired bit layout ( e.g.11111111
instead of00001111
). This works OK because a size attribute is included which keeps access to legal bounds. However when usingBitvSet::from_bitv(Bitv)
, we then find thatbitvset.contains(i)
can return true wheni
should not in fact be in the set.The fix is to create the correct representation by treating various cases separately and using a bitshift
(1<<nbits) - 1
to generate correct number of1
s where necessary.