From 86a5c462c07a021fa2448e6df272365d046699ab Mon Sep 17 00:00:00 2001 From: Karl Gaissmaier Date: Mon, 16 Dec 2024 21:29:46 +0100 Subject: [PATCH] impl. AppendTo and AsSlice --- bitset.go | 46 ++++++++++++++++++++++-- bitset_test.go | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 142 insertions(+), 2 deletions(-) diff --git a/bitset.go b/bitset.go index 4339fea..291d0cd 100644 --- a/bitset.go +++ b/bitset.go @@ -520,6 +520,45 @@ func (b *BitSet) DeleteAt(i uint) *BitSet { return b } +// AppendTo appends all set bits to buf and returns the (maybe extended) buf. +// In case of allocation failure, the function will panic. +// +// See also [BitSet.AsSlice] and [BitSet.NextSetMany]. +func (b *BitSet) AppendTo(buf []uint) []uint { + for idx, word := range b.set { + for word != 0 { + buf = append(buf, uint(idx<