Skip to content

Commit 4a54802

Browse files
committed
Define BitArray.GetSetBits
1 parent c466da2 commit 4a54802

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

bitarray/bitarray.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,12 @@ func (ba *bitArray) GetBit(k uint64) (bool, error) {
116116
return result, nil
117117
}
118118

119-
//ClearBit will unset a bit at the given index if it is set.
119+
// GetSetBits gets the position of bits set in the array.
120+
func (ba *bitArray) GetSetBits(_ uint64, buffer []uint64) []uint64 {
121+
return buffer[:0]
122+
}
123+
124+
// ClearBit will unset a bit at the given index if it is set.
120125
func (ba *bitArray) ClearBit(k uint64) error {
121126
if k >= ba.Capacity() {
122127
return OutOfRangeError(k)

bitarray/interface.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ type BitArray interface {
3636
// function returns an error if the position is out
3737
// of range. A sparse bit array never returns an error.
3838
GetBit(k uint64) (bool, error)
39+
// GetSetBits gets the position of bits set in the array. Will
40+
// return as many set bits as can fit in the provided buffer
41+
// starting from the specified position in the array.
42+
GetSetBits(from uint64, buffer []uint64) []uint64
3943
// ClearBit clears the bit at the given position. This
4044
// function returns an error if the position is out
4145
// of range. A sparse bit array never returns an error.

bitarray/sparse_bitarray.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ func (sba *sparseBitArray) GetBit(k uint64) (bool, error) {
127127
return sba.blocks[i].get(position), nil
128128
}
129129

130+
// GetSetBits gets the position of bits set in the array.
131+
func (sba *sparseBitArray) GetSetBits(_ uint64, buffer []uint64) []uint64 {
132+
return buffer[:0]
133+
}
134+
130135
// ToNums converts this sparse bitarray to a list of numbers contained
131136
// within it.
132137
func (sba *sparseBitArray) ToNums() []uint64 {

0 commit comments

Comments
 (0)