From 5a829244ffd64e4120015ce1bf8285b0b6168d55 Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Thu, 9 Sep 2021 14:11:48 -0400 Subject: [PATCH] Minor fix to Shrink. --- bitset.go | 4 +++- bitset_test.go | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/bitset.go b/bitset.go index d688806..271ccdb 100644 --- a/bitset.go +++ b/bitset.go @@ -254,7 +254,9 @@ func (b *BitSet) Shrink(lastbitindex uint) *BitSet { copy(shrunk, b.set[:idx]) b.set = shrunk b.length = length - b.set[idx-1] &= (allBits >> (uint64(64) - uint64(length&(wordSize-1)))) + if length < 64 { + b.set[idx-1] &= (allBits >> (uint64(64) - uint64(length&(wordSize-1)))) + } return b } diff --git a/bitset_test.go b/bitset_test.go index f386d4e..7346b44 100644 --- a/bitset_test.go +++ b/bitset_test.go @@ -564,6 +564,13 @@ func TestAll(t *testing.T) { } func TestShrink(t *testing.T) { + bs := New(10) + bs.Set(0) + bs.Shrink(63) + if !bs.Test(0) { + t.Error("0 should be set") + return + } b := New(0) b.Set(0)