Example #1
0
		//** see {@link andNot} */
		public virtual void  AndNot(OpenBitSet other)
		{
			Remove(other);
		}
Example #2
0
		// some BitSet compatability methods
		
		//** see {@link intersect} */
		public virtual void  And(OpenBitSet other)
		{
			Intersect(other);
		}
Example #3
0
		//** see {@link union} */
		public virtual void  Or(OpenBitSet other)
		{
			Union(other);
		}
Example #4
0
		/// <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];
			}
		}
Example #5
0
		/// <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;
		}
Example #6
0
		/// <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();
		}
Example #7
0
		/// <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;
		}
Example #8
0
		/// <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;
		}
Example #9
0
		/// <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;
		}
Example #10
0
 //** see {@link andNot} */
 public virtual void  AndNot(OpenBitSet other)
 {
     Remove(other);
 }
Example #11
0
		/// <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));
		}
Example #12
0
 //** see {@link union} */
 public virtual void  Or(OpenBitSet other)
 {
     Union(other);
 }
Example #13
0
        // some BitSet compatability methods

        //** see {@link intersect} */
        public virtual void  And(OpenBitSet other)
        {
            Intersect(other);
        }
Example #14
0
 /// <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)));
 }
Example #15
0
		/// <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;
		}
Example #16
0
		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);
			}
		}
Example #17
0
		public OpenBitSetIterator(OpenBitSet obs):this(obs.GetBits(), obs.GetNumWords())
		{
		}
Example #18
0
 public OpenBitSetIterator(OpenBitSet obs) : this(obs.GetBits(), obs.GetNumWords())
 {
 }