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<