/// <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)); } }
/// <summary> /// returns true if both sets have the same bits set </summary> public override bool Equals(object o) { if (this == o) { return(true); } if (!(o is FixedBitSet)) { return(false); } FixedBitSet other = (FixedBitSet)o; if (NumBits != other.Length()) { return(false); } return(Arrays.Equals(bits, other.bits)); }
/// <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); } }