Ejemplo n.º 1
0
 /**
  * Performs the logical XOR of this {@code BitSet} with another {@code BitSet}.
  * The values of this {@code BitSet} are changed accordingly.
  *
  * @param bs
  *            {@code BitSet} to XOR with.
  * @see #or
  * @see #and
  */
 public void xor(BitSet bs)
 {
     int bsActualLen = bs.getActualArrayLength();
     if (bsActualLen > bits.Length) {
         long[] tempBits = new long[bsActualLen];
         java.lang.SystemJ.arraycopy(bs.bits, 0, tempBits, 0, bs.actualArrayLength);
         for (int i = 0; i < actualArrayLength; i++) {
             tempBits[i] ^= bits[i];
         }
         bits = tempBits;
         actualArrayLength = bsActualLen;
         isLengthActual = !((actualArrayLength > 0) && (bits[actualArrayLength - 1] == 0));
     } else {
         long[] bsBits = bs.bits;
         for (int i = 0; i < bsActualLen; i++) {
             bits[i] ^= bsBits[i];
         }
         if (bsActualLen > actualArrayLength) {
             actualArrayLength = bsActualLen;
             isLengthActual = true;
         }
     }
     needClear();
 }
Ejemplo n.º 2
0
        /**
         * Clears all bits in the receiver which are also set in the parameter
         * {@code BitSet}. The values of this {@code BitSet} are changed accordingly.
         *
         * @param bs
         *            {@code BitSet} to ANDNOT with.
         */
        public void andNot(BitSet bs)
        {
            long[] bsBits = bs.bits;
            if (!needClearJ) {
                return;
            }
            int range = actualArrayLength < bs.actualArrayLength ? actualArrayLength
                    : bs.actualArrayLength;
            for (int i = 0; i < range; i++) {
                bits[i] &= ~bsBits[i];
            }

            if (actualArrayLength < range) {
                actualArrayLength = range;
            }
            isLengthActual = !((actualArrayLength > 0) && (bits[actualArrayLength - 1] == 0));
        }
Ejemplo n.º 3
0
        /**
         * Checks if these two {@code BitSet}s have at least one bit set to true in the same
         * position.
         *
         * @param bs
         *            {@code BitSet} used to calculate the intersection.
         * @return {@code true} if bs intersects with this {@code BitSet},
         *         {@code false} otherwise.
         */
        public bool intersects(BitSet bs)
        {
            long[] bsBits = bs.bits;
            int length1 = actualArrayLength, length2 = bs.actualArrayLength;

            if (length1 <= length2) {
                for (int i = 0; i < length1; i++) {
                    if ((bits[i] & bsBits[i]) != 0L) {
                        return true;
                    }
                }
            } else {
                for (int i = 0; i < length2; i++) {
                    if ((bits[i] & bsBits[i]) != 0L) {
                        return true;
                    }
                }
            }

            return false;
        }
Ejemplo n.º 4
0
 /**
  * Performs the logical AND of this {@code BitSet} with another
  * {@code BitSet}. The values of this {@code BitSet} are changed accordingly.
  *
  * @param bs
  *            {@code BitSet} to AND with.
  * @see #or
  * @see #xor
  */
 public void and(BitSet bs)
 {
     long[] bsBits = bs.bits;
     if (!needClearJ) {
         return;
     }
     int length1 = actualArrayLength, length2 = bs.actualArrayLength;
     if (length1 <= length2) {
         for (int i = 0; i < length1; i++) {
             bits[i] &= bsBits[i];
         }
     } else {
         for (int i = 0; i < length2; i++) {
             bits[i] &= bsBits[i];
         }
         for (int i = length2; i < length1; i++) {
             bits[i] = 0;
         }
         actualArrayLength = length2;
     }
     isLengthActual = !((actualArrayLength > 0) && (bits[actualArrayLength - 1] == 0));
 }