From 08f82ab5f1f2906e9eef9c5e8edd0c61d0855538 Mon Sep 17 00:00:00 2001 From: Karl Gaissmaier Date: Sat, 7 Dec 2024 21:38:23 +0100 Subject: [PATCH] Bytes is misleading, use Words instead of --- bitset.go | 9 +++++++++ bitset_test.go | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) 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()