Skip to content

Commit

Permalink
Merge pull request #188 from gaissmai/fb-words
Browse files Browse the repository at this point in the history
Bytes is misleading, use Words instead of
  • Loading branch information
lemire authored Dec 7, 2024
2 parents 4051f18 + 08f82ab commit 76add66
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions bitset.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,19 @@ func FromWithLength(length uint, set []uint64) *BitSet {
// Bytes returns the bitset as array of 64-bit words, giving direct access to the internal representation.
// It is not a copy, so changes to the returned slice will affect the bitset.
// It is meant for advanced users.
//
// Deprecated: Bytes is deprecated. Use [bitset.Words] instead.
func (b *BitSet) Bytes() []uint64 {
return b.set
}

// Words returns the bitset as array of 64-bit words, giving direct access to the internal representation.
// It is not a copy, so changes to the returned slice will affect the bitset.
// It is meant for advanced users.
func (b *BitSet) Words() []uint64 {
return b.set
}

// wordsNeeded calculates the number of words needed for i bits
func wordsNeeded(i uint) int {
if i > (Cap() - wordSize + 1) {
Expand Down
16 changes: 16 additions & 0 deletions bitset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1482,6 +1482,22 @@ func TestFrom(t *testing.T) {
}
}

func TestWords(t *testing.T) {
b := new(BitSet)
c := b.Words()
outType := fmt.Sprintf("%T", c)
expType := "[]uint64"
if outType != expType {
t.Error("Expecting type: ", expType, ", gotf:", outType)
return
}
if len(c) != 0 {
t.Error("The slice should be empty")
return
}
}

// Bytes is deprecated
func TestBytes(t *testing.T) {
b := new(BitSet)
c := b.Bytes()
Expand Down

0 comments on commit 76add66

Please sign in to comment.