//** see {@link andNot} */ public virtual void AndNot(OpenBitSet other) { Remove(other); }
// some BitSet compatability methods //** see {@link intersect} */ public virtual void And(OpenBitSet other) { Intersect(other); }
//** see {@link union} */ public virtual void Or(OpenBitSet other) { Union(other); }
/// <summary>Remove all elements set in other. this = this AND_NOT other </summary> public virtual void Remove(OpenBitSet other) { int idx = System.Math.Min(wlen, other.wlen); long[] thisArr = this.bits; long[] otherArr = other.bits; while (--idx >= 0) { thisArr[idx] &= ~ otherArr[idx]; } }
/// <summary>this = this XOR other </summary> public virtual void Xor(OpenBitSet other) { int newLen = System.Math.Max(wlen, other.wlen); EnsureCapacityWords(newLen); long[] thisArr = this.bits; long[] otherArr = other.bits; int pos = System.Math.Min(wlen, other.wlen); while (--pos >= 0) { thisArr[pos] ^= otherArr[pos]; } if (this.wlen < newLen) { Array.Copy(otherArr, this.wlen, thisArr, this.wlen, newLen - this.wlen); } this.wlen = newLen; }
/// <summary> Create a SortedVIntList from an OpenBitSet.</summary> /// <param name="bits"> A bit set representing a set of integers. /// </param> public SortedVIntList(OpenBitSet bits) { SortedVIntListBuilder builder = new SortedVIntListBuilder(this); int nextInt = bits.NextSetBit(0); while (nextInt != - 1) { builder.AddInt(nextInt); nextInt = bits.NextSetBit(nextInt + 1); } builder.Done(); }
/// <summary>this = this AND other </summary> public virtual void Intersect(OpenBitSet other) { int newLen = System.Math.Min(this.wlen, other.wlen); long[] thisArr = this.bits; long[] otherArr = other.bits; // testing against zero can be more efficient int pos = newLen; while (--pos >= 0) { thisArr[pos] &= otherArr[pos]; } if (this.wlen > newLen) { // fill zeros from the new shorter length to the old length for (int i = newLen; i < this.wlen; i++) bits[i] = 0L; } this.wlen = newLen; }
/// <summary>Returns the popcount or cardinality of "a and not b" /// or "intersection(a, not(b))". /// Neither set is modified. /// </summary> public static long AndNotCount(OpenBitSet a, OpenBitSet b) { long tot = BitUtil.Pop_andnot(a.bits, b.bits, 0, System.Math.Min(a.wlen, b.wlen)); if (a.wlen > b.wlen) { tot += BitUtil.Pop_array(a.bits, b.wlen, a.wlen - b.wlen); } return tot; }
/// <summary>Returns the popcount or cardinality of the exclusive-or of the two sets. /// Neither set is modified. /// </summary> public static long XorCount(OpenBitSet a, OpenBitSet b) { long tot = BitUtil.Pop_xor(a.bits, b.bits, 0, System.Math.Min(a.wlen, b.wlen)); if (a.wlen < b.wlen) { tot += BitUtil.Pop_array(b.bits, a.wlen, b.wlen - a.wlen); } else if (a.wlen > b.wlen) { tot += BitUtil.Pop_array(a.bits, b.wlen, a.wlen - b.wlen); } return tot; }
/// <summary>Returns the popcount or cardinality of the intersection of the two sets. /// Neither set is modified. /// </summary> public static long IntersectionCount(OpenBitSet a, OpenBitSet b) { return BitUtil.Pop_intersect(a.bits, b.bits, 0, System.Math.Min(a.wlen, b.wlen)); }
/// <summary>Returns the popcount or cardinality of the intersection of the two sets. /// Neither set is modified. /// </summary> public static long IntersectionCount(OpenBitSet a, OpenBitSet b) { return(BitUtil.Pop_intersect(a.bits, b.bits, 0, System.Math.Min(a.wlen, b.wlen))); }
/// <summary>returns true if the sets have any elements in common </summary> public virtual bool Intersects(OpenBitSet other) { int pos = System.Math.Min(this.wlen, other.wlen); long[] thisArr = this.bits; long[] otherArr = other.bits; while (--pos >= 0) { if ((thisArr[pos] & otherArr[pos]) != 0) return true; } return false; }
public virtual System.Object Clone() { try { OpenBitSet obs = new OpenBitSet((long[]) bits.Clone(), wlen); //obs.bits = new long[obs.bits.Length]; //obs.bits.CopyTo(obs.bits, 0); // hopefully an array clone is as fast(er) than arraycopy return obs; } catch (System.Exception e) { throw new System.SystemException(e.Message, e); } }
public OpenBitSetIterator(OpenBitSet obs):this(obs.GetBits(), obs.GetNumWords()) { }
public OpenBitSetIterator(OpenBitSet obs) : this(obs.GetBits(), obs.GetNumWords()) { }