Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
bitset extendSetMaybe
// len(nil) == 0, and see no value in using cap, when explicitly tracking the length.
// Has some minor rammifications for other methods reliant on len(b.set) instead of b.length.
func (b *BitSet) extendSetMaybe(i uint) {
if i >= b.length { // if we need more bits, make 'em
nsize := (i + wordSize) / wordSize
if uint(len(b.set)) < nsize {
newset := make([]uint64, 2*nsize) // increase capacity 2x
copy(newset, b.set)
b.set = newset
}
b.length = i + 1
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment