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

Add GetSetBits and Count to BitArray #221

Merged
merged 9 commits into from
May 18, 2023
Merged

Conversation

danielway-wk
Copy link
Contributor

@danielway-wk danielway-wk commented May 17, 2023

This adds two new functions to the BitArray interface for efficient access to set bits.

GetSetBits returns the position of bits set in the array. It is provided a position to start from and will fill the buffer with as many set bits as fit. Its implementation is based on TrailingZeros64 from math/bits.

Example usage:

ba := newBitArray(10)
ba.SetBit(1)
ba.SetBit(4)
ba.SetBit(8)

buffer := make([]uint64, 0, 2)
assert.Equal(t, []uint64{1, 4}, ba.GetSetBits(0, buffer))
assert.Equal(t, []uint64{8}, ba.GetSetBits(5, buffer))

Count returns the total number of bits set in the array. Its implementation is based on OnesCount64 from math/bits.

Example usage:

ba := newBitArray(10)
ba.SetBit(1)
ba.SetBit(4)
ba.SetBit(8)

assert.Equal(t, 3, ba.Count())

ba.ClearBit(4)
assert.Equal(t, 2, ba.Count())

ba.Reset()
assert.Equal(t, 0, ba.Count())

@aviary3-wk
Copy link

Security Insights

No security relevant content was detected by automated scans.

Action Items

  • Review PR for security impact; comment "security review required" if needed or unsure
  • Verify aviary.yaml coverage of security relevant code

Questions or Comments? Reach out on Slack: #support-infosec.

@danielway-wk danielway-wk marked this pull request as ready for review May 17, 2023 16:23
dustinhiatt-wf
dustinhiatt-wf previously approved these changes May 17, 2023
bitarray/bitarray.go Show resolved Hide resolved
bitarray/bitarray.go Show resolved Hide resolved
@dustinhiatt-wf
Copy link
Contributor

@Workiva/release-management-p

@dustinhiatt-wf dustinhiatt-wf merged commit 68e77ee into master May 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants