Skip to content

Add GetSetBits and Count to BitArray#221

Merged
dustinhiatt-wf merged 9 commits intomasterfrom
add-bitarray-getsetbits
May 18, 2023
Merged

Add GetSetBits and Count to BitArray#221
dustinhiatt-wf merged 9 commits intomasterfrom
add-bitarray-getsetbits

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
@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