diff --git a/bitset.go b/bitset.go index 23958ef..ebc7178 100644 --- a/bitset.go +++ b/bitset.go @@ -1418,18 +1418,13 @@ func (b *BitSet) Select(index uint) uint { // top detects the top bit set func (b *BitSet) top() (uint, bool) { - panicIfNull(b) - - idx := len(b.set) - 1 - for ; idx >= 0 && b.set[idx] == 0; idx-- { - } - - // no set bits - if idx < 0 { - return 0, false + for idx := len(b.set) - 1; idx >= 0; idx-- { + if word := b.set[idx]; word != 0 { + return uint(idx<