diff --git a/bitset.go b/bitset.go index cf11581..eae861d 100644 --- a/bitset.go +++ b/bitset.go @@ -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) { diff --git a/bitset_test.go b/bitset_test.go index c313f41..cf957ae 100644 --- a/bitset_test.go +++ b/bitset_test.go @@ -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()