/// <summary>
/// If the given <seealso cref="FixedBitSet"/> is large enough to hold {@code numBits},
/// returns the given bits, otherwise returns a new <seealso cref="FixedBitSet"/> which
/// can hold the requested number of bits.
///
/// <p>
/// <b>NOTE:</b> the returned bitset reuses the underlying {@code long[]} of
/// the given {@code bits} if possible. Also, calling <seealso cref="#length()"/> on the
/// returned bits may return a value greater than {@code numBits}.
/// </summary>
public static FixedBitSet EnsureCapacity(FixedBitSet bits, int numBits)
{
if (numBits < bits.Length())
{
return(bits);
}
else
{
int numWords = Bits2words(numBits);
long[] arr = bits.Bits;
if (numWords >= arr.Length)
{
arr = ArrayUtil.Grow(arr, numWords + 1);
}
return(new FixedBitSet(arr, arr.Length << 6));
}
}