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: BlockDecomposer #2128

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

fix: BlockDecomposer #2128

wants to merge 1 commit into from

Conversation

tmontaigu
Copy link
Contributor

The BlockDecomposer gave the possibility when the number of bits per block was not a multiple of the number of bits in the original integer to force the extra bits of the last block to a particular value.

However, the way this was done could only work when setting these bits to 1, when wanting to set them to 0 it would not work.

Good news is that we actually never wanted to set them to 0, but it should still be fixed for completeness, and allow other feature to be added without bugs

@cla-bot cla-bot bot added the cla-signed label Feb 28, 2025
@tmontaigu tmontaigu force-pushed the tm/blkdcmp branch 4 times, most recently from 2125b11 to 2ffefe7 Compare February 28, 2025 10:55
Copy link
Member

@IceTDrinker IceTDrinker left a comment

Choose a reason for hiding this comment

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

Question on what the block decomposer actually does

fn new_(value: T, bits_per_block: u32, limit: Option<T>, padding_bit: T) -> Self {
fn new_(value: T, bits_per_block: u32, limit: Option<T>, padding_bit: Option<u32>) -> Self {
if let Some(padding_bit) = padding_bit {
assert!(padding_bit <= 1);
Copy link
Member

Choose a reason for hiding this comment

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

how about a PaddingBit struct which holds an Option<?> with repr(transparent) and a new_one(), new_zero() function ?

? can be bool or u32 as you like

will avoid the assert to enforce the invariant, wdyt ?

you could even have consts like PADDING_BIT_ZERO, PADDING_BIT_ONE if you like

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 think bool would be enough

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 mean, would it be ok if only the padding_bit argument of the constructors is a bool ?

Copy link
Member

Choose a reason for hiding this comment

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

ah, don't you need the Option thing to discrimnate some specific case ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its only needed in the struct itself and in the private (new_) constructor as we use a different constructor if the user whishes to specify the padding

Copy link
Member

Choose a reason for hiding this comment

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

I just don't know if the bool is the best tool to express what the user wants, don't recall if this struct is pub or pub(crate)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The struct is pub

Copy link
Member

Choose a reason for hiding this comment

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

Then I don't feel like bool is the best to carry intent here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So you'd prefer a enum PaddingBitValue { Zero, One } and possibly None ?

Copy link
Member

Choose a reason for hiding this comment

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

Don’t you think ?

The BlockDecomposer gave the possibility when the number of bits per
block was not a multiple of the number of bits in the original integer
to force the extra bits of the last block to a particular value.

However, the way this was done could only work when setting these bits
to 1, when wanting to set them to 0 it would not work.

Good news is that we actually never wanted to set them to 0,
but it should still be fixed for completeness, and allow other
feature to be added without bugs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants