Ejemplo n.º 1
0
		/// <summary>
		/// Performs a logical <b>XOR</b> of this bit set with the bit set
		/// argument. This bit set is modified so that a bit in it has the
		/// value {@code true} if and only if one of the following
		/// statements holds:
		/// <ul>
		/// <li>The bit initially has the value {@code true}, and the corresponding bit in the argument has the value {@code false}.
		/// <li>The bit initially has the value {@code false}, and the corresponding bit in the argument has the value {@code true}.
		/// </ul>
		/// </summary>
		/// <param name="set"> a bit set </param>
		public virtual void xor(SimpleBitSet set)
		{
			int wordsInCommon = Math.Min(wordsInUse, set.wordsInUse);

			if (wordsInUse < set.wordsInUse)
			{
				ensureCapacity(set.wordsInUse);
				wordsInUse = set.wordsInUse;
			}

			// Perform logical XOR on words in common
			for (int i = 0; i < wordsInCommon; i++)
			{
				if (words[i] != set.words[i])
				{
					words[i] = SETTED_VAL;
				}
				else
				{
					words[i] = UNSETTED_VAL;
				}
			}

			// Copy any remaining words
			if (wordsInCommon < set.wordsInUse)
			{
				this.arraycopy(set.words, wordsInCommon, words, wordsInCommon, set.wordsInUse - wordsInCommon);
			}

			recalculateWordsInUse();
			checkInvariants();
		}
Ejemplo n.º 2
0
		/// <summary>
		/// Performs a logical <b>AND</b> of this target bit set with the
		/// argument bit set. This bit set is modified so that each bit in it
		/// has the value {@code true} if and only if it both initially
		/// had the value {@code true} and the corresponding bit in the
		/// bit set argument also had the value {@code true}.
		/// </summary>
		/// <param name="set"> a bit set </param>
		public virtual void and(SimpleBitSet set)
		{
			if (this == set)
			{
				return;
			}

			while (wordsInUse > set.wordsInUse)
			{
				words[--wordsInUse] = UNSETTED_VAL;
			}

			// Perform logical AND on words in common
			for (int i = 0; i < wordsInUse; i++)
			{
				words[i] &= set.words[i];
			}

			recalculateWordsInUse();
			checkInvariants();
		}
Ejemplo n.º 3
0
		/// <summary>
		/// Performs a logical <b>OR</b> of this bit set with the bit set
		/// argument. This bit set is modified so that a bit in it has the
		/// value {@code true} if and only if it either already had the
		/// value {@code true} or the corresponding bit in the bit set
		/// argument has the value {@code true}.
		/// </summary>
		/// <param name="set"> a bit set </param>
		public virtual void or(SimpleBitSet set)
		{
			if (this == set)
			{
				return;
			}

			int wordsInCommon = Math.Min(wordsInUse, set.wordsInUse);

			if (wordsInUse < set.wordsInUse)
			{
				ensureCapacity(set.wordsInUse);
				wordsInUse = set.wordsInUse;
			}

			// Perform logical OR on words in common
			for (int i = 0; i < wordsInCommon; i++)
			{
				words[i] |= set.words[i];
			}

			// Copy any remaining words
			if (wordsInCommon < set.wordsInUse)
			{
				arraycopy(set.words, wordsInCommon, words, wordsInCommon, wordsInUse - wordsInCommon);
			}

			// recalculateWordsInUse() is unnecessary
			checkInvariants();
		}
Ejemplo n.º 4
0
		/// <summary>
		/// Returns true if the specified {@code BitSet} has any bits set to {@code true} that are also set to {@code true} in this {@code BitSet}.
		/// </summary>
		/// <param name="set"> {@code BitSet} to intersect with </param>
		/// <returns> boolean indicating whether this {@code BitSet} intersects
		///         the specified {@code BitSet}
		/// @since 1.4 </returns>
		public virtual bool intersects(SimpleBitSet set)
		{
			for (int i = Math.Min(wordsInUse, set.wordsInUse) - 1; i >= 0; i--)
			{
				if ((words[i] & set.words[i]) != 0)
				{
					return true;
				}
			}
			return false;
		}