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

libs/bits: store the number of non-zero bits in a private field #2849

Open
cason opened this issue Apr 18, 2024 · 0 comments
Open

libs/bits: store the number of non-zero bits in a private field #2849

cason opened this issue Apr 18, 2024 · 0 comments
Labels
enhancement New feature or request libs

Comments

@cason
Copy link
Contributor

cason commented Apr 18, 2024

In #2841, part of the changes associate to find out how many bits, in the bit array/set, are set to zero.

Currently, this is achieved by the getTrueIndices() []int, or the faster replacement getNumTrueIndices() int.

We can have the number of bits set (==1) as a private field, updated as follows:

  • SetIndex adds or subtracts 1
  • copy() can be adapted easily
  • IsEmpty() and IsFull() become trivial
  • Update(), I don't even know the point, same as copy()
  • UnmarshalJSON() uses SetIndex, so nothing new here
  • FromProto() can have this field initialized with a private method (the one added here)

Originally posted by @cason in #2841 (comment)

@cason cason added enhancement New feature or request libs labels Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request libs
Projects
Status: Todo
Development

No branches or pull requests

1 participant