/// <summary> /// this = this AND NOT other </summary> public void AndNot(Int64BitSet other) { int pos = Math.Min(numWords, other.bits.Length); while (--pos >= 0) { bits[pos] &= ~other.bits[pos]; } }
/// <summary> /// this = this XOR other </summary> public void Xor(Int64BitSet other) { Debug.Assert(other.numWords <= numWords, "numWords=" + numWords + ", other.numWords=" + other.numWords); int pos = Math.Min(numWords, other.numWords); while (--pos >= 0) { bits[pos] ^= other.bits[pos]; } }
/// <summary> /// this = this AND other </summary> public void And(Int64BitSet other) { int pos = Math.Min(numWords, other.numWords); while (--pos >= 0) { bits[pos] &= other.bits[pos]; } if (numWords > other.numWords) { Arrays.Fill(bits, other.numWords, numWords, 0L); } }
/// <summary> /// Returns <c>true</c> if the sets have any elements in common </summary> public bool Intersects(Int64BitSet other) { int pos = Math.Min(numWords, other.numWords); while (--pos >= 0) { if ((bits[pos] & other.bits[pos]) != 0) { return(true); } } return(false); }
/// <summary> /// this = this XOR other </summary> public void Xor(Int64BitSet other) { if (Debugging.AssertsEnabled) { Debugging.Assert(other.numWords <= numWords, "numWords={0}, other.numWords={1}", numWords, other.numWords); } int pos = Math.Min(numWords, other.numWords); while (--pos >= 0) { bits[pos] ^= other.bits[pos]; } }
/// <summary> /// this = this OR other </summary> public void Or(Int64BitSet other) { if (Debugging.AssertsEnabled) { Debugging.Assert(other.numWords <= numWords, () => "numWords=" + numWords + ", other.numWords=" + other.numWords); } int pos = Math.Min(numWords, other.numWords); while (--pos >= 0) { bits[pos] |= other.bits[pos]; } }
/// <summary> /// If the given <see cref="Int64BitSet"/> is large enough to hold /// <paramref name="numBits"/>, returns the given <paramref name="bits"/>, otherwise returns a new /// <see cref="Int64BitSet"/> which can hold the requested number of bits. /// /// <para/> /// <b>NOTE:</b> the returned bitset reuses the underlying <see cref="T:long[]"/> of /// the given <paramref name="bits"/> if possible. Also, reading <see cref="Length"/> on the /// returned bits may return a value greater than <paramref name="numBits"/>. /// </summary> public static Int64BitSet EnsureCapacity(Int64BitSet bits, long numBits) { if (numBits < bits.Length) { return(bits); } else { int numWords = Bits2words(numBits); long[] arr = bits.GetBits(); if (numWords >= arr.Length) { arr = ArrayUtil.Grow(arr, numWords + 1); } return(new Int64BitSet(arr, arr.Length << 6)); } }
/// <summary> /// Returns <c>true</c> if both sets have the same bits set </summary> public override bool Equals(object o) { if (this == o) { return(true); } if (!(o is Int64BitSet)) { return(false); } Int64BitSet other = (Int64BitSet)o; if (numBits != other.Length) { return(false); } return(Arrays.Equals(bits, other.bits)); }
public static long Cardinality(this Int64BitSet set) { return(set.Cardinality); }