Skip to content

Commit

Permalink
Define BitArray.GetSetBits
Browse files Browse the repository at this point in the history
  • Loading branch information
danielway-wk committed May 15, 2023
1 parent c466da2 commit 4a54802
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion bitarray/bitarray.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,12 @@ func (ba *bitArray) GetBit(k uint64) (bool, error) {
return result, nil
}

//ClearBit will unset a bit at the given index if it is set.
// GetSetBits gets the position of bits set in the array.
func (ba *bitArray) GetSetBits(_ uint64, buffer []uint64) []uint64 {
return buffer[:0]
}

// ClearBit will unset a bit at the given index if it is set.
func (ba *bitArray) ClearBit(k uint64) error {
if k >= ba.Capacity() {
return OutOfRangeError(k)
Expand Down
4 changes: 4 additions & 0 deletions bitarray/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ type BitArray interface {
// function returns an error if the position is out
// of range. A sparse bit array never returns an error.
GetBit(k uint64) (bool, error)
// GetSetBits gets the position of bits set in the array. Will
// return as many set bits as can fit in the provided buffer
// starting from the specified position in the array.
GetSetBits(from uint64, buffer []uint64) []uint64
// ClearBit clears the bit at the given position. This
// function returns an error if the position is out
// of range. A sparse bit array never returns an error.
Expand Down
5 changes: 5 additions & 0 deletions bitarray/sparse_bitarray.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ func (sba *sparseBitArray) GetBit(k uint64) (bool, error) {
return sba.blocks[i].get(position), nil
}

// GetSetBits gets the position of bits set in the array.
func (sba *sparseBitArray) GetSetBits(_ uint64, buffer []uint64) []uint64 {
return buffer[:0]
}

// ToNums converts this sparse bitarray to a list of numbers contained
// within it.
func (sba *sparseBitArray) ToNums() []uint64 {
Expand Down

0 comments on commit 4a54802

Please sign in to comment.