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 various bugs in DiscordBitSet #772

Merged
merged 1 commit into from
Feb 26, 2023
Merged

Fix various bugs in DiscordBitSet #772

merged 1 commit into from
Feb 26, 2023

Conversation

lukellmann
Copy link
Member

@lukellmann lukellmann commented Feb 23, 2023

  • WIDTH was defined to the width of a Byte not a Long, resulting in bugs in size, get and set

  • binary just did some completely wrong things that I can't really describe

  • hashCode could return different values for equal DiscordBitSets (when they had different amounts of trailing zeros in the data array), breaking its general contract

  • equals was comparing this with this and not this with other, which resulted in any two DiscordBitSets considered equal

  • contains would erroneously return false if other did have more trailing zeros but would otherwise be contained

  • set wasn't growing data correctly and also didn't unset bits properly

@lukellmann
Copy link
Member Author

please tell me if you happen to find any other bugs or if you think my fixes still include bugs

@DRSchlaubi DRSchlaubi removed their request for review February 24, 2023 13:43
@DRSchlaubi
Copy link
Member

Don't know enough about this to review this properly

@HopeBaron
Copy link
Member

The re-write is perfectly fine much easier to read as well.
But the initial reason we used a byte size is to save ourselves from allocating non-necessary bits

@lukellmann
Copy link
Member Author

But the initial reason we used a byte size is to save ourselves from allocating non-necessary bits

yeah but since the implementation uses a LongArray rn, setting WIDTH to Byte.SIZE_BITS was simply wrong

@HopeBaron
Copy link
Member

You are right, let's just keep it long then

* WIDTH was defined to the width of a Byte not a Long, resulting in bugs
  in size, get and set

* binary just did some completely wrong things that I can't really
  describe

* hashCode could return different values for equal DiscordBitSets
  (when they had different amounts of trailing zeros in the data array),
  breaking its general contract

* equals was comparing this with this and not this with other, which
  resulted in any two DiscordBitSets considered equal

* contains would erroneously return false if other did have more
  trailing zeros but would otherwise be contained

* set wasn't growing data correctly and also didn't unset bits properly
@lukellmann
Copy link
Member Author

did some last small changes, see here

@HopeBaron
Copy link
Member

They look good, if there's nothing else you want to do on this PR we can merge

@lukellmann
Copy link
Member Author

i'm done here 👍

@HopeBaron HopeBaron merged commit 3f5cd17 into 0.8.x Feb 26, 2023
@lukellmann lukellmann deleted the fix/bitset branch February 26, 2023 17:35
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.

3 participants