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

Only use non-padding bits for ==/hash? #6

Open
Seelengrab opened this issue Jun 7, 2023 · 1 comment
Open

Only use non-padding bits for ==/hash? #6

Seelengrab opened this issue Jun 7, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@Seelengrab
Copy link
Owner

Seelengrab commented Jun 7, 2023

Currently, == and hash both just use the plain-bits, even if those contain padding bits (which have undefined value). This has the sideeffect of making two objects whose fields are equal unequal if their padding bits differ (which shouldn't matter). There are three possible paths:

  1. Mask out the padding bits, thereby getting a consistent value for comparison
  2. Explicitly iterate over the fields as declared, comparing equality for each
  3. Ignore the issue entirely and try to ensure that padding bits are always a consistent value, sidestepping the problem

1 has the advantage of being likely faster & easier to implement, while 2. is likely more correct, as it doesn't make us observe padding bits. 3. could be difficult to guarantee.

@Seelengrab Seelengrab added enhancement bug Something isn't working and removed enhancement labels Jun 7, 2023
@Seelengrab
Copy link
Owner Author

With some more thought on this, I've come to the conclusion that 3. is not going to work, because I'd like this to still work even if the padding bits change out under the guarantees provided by the constructors. The use case motivating this is bits with undefined values of microcontroller/hardware registers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant