/** Returns the bit at the given index and sets it in one go. * @param index the index of the bit * @return whether the bit was set before invocation * @throws ArrayIndexOutOfBoundsException if index < 0 */ public boolean getAndSet (int index) { final int word = index >>> 6; checkCapacity(word); long oldBits = bits[word]; bits[word] |= 1L << (index & 0x3F); return bits[word] == oldBits; }
/** @param index the index of the bit to set * @throws ArrayIndexOutOfBoundsException if index < 0 */ public void set (int index) { final int word = index >>> 6; checkCapacity(word); bits[word] |= 1L << (index & 0x3F); }
/** @param index the index of the bit to set * @throws ArrayIndexOutOfBoundsException if index < 0 */ public void set (int index) { final int word = index >>> 6; checkCapacity(word); bits[word] |= 1L << (index & 0x3F); }
/** Creates a bit set whose initial size is large enough to explicitly represent bits with indices in the range 0 through * nbits-1. * @param nbits the initial size of the bit set */ public Bits (int nbits) { checkCapacity(nbits >>> 6); }
/** Returns the bit at the given index and sets it in one go. * @param index the index of the bit * @return whether the bit was set before invocation * @throws ArrayIndexOutOfBoundsException if index < 0 */ public boolean getAndSet (int index) { final int word = index >>> 6; checkCapacity(word); long oldBits = bits[word]; bits[word] |= 1L << (index & 0x3F); return bits[word] == oldBits; }
/** @param index the index of the bit to flip */ public void flip (int index) { final int word = index >>> 6; checkCapacity(word); bits[word] ^= 1L << (index & 0x3F); }
/** Creates a bit set whose initial size is large enough to explicitly represent bits with indices in the range 0 through * nbits-1. * @param nbits the initial size of the bit set */ public Bits (int nbits) { checkCapacity(nbits >>> 6); }
/** @param index the index of the bit to flip */ public void flip (int index) { final int word = index >>> 6; checkCapacity(word); bits[word] ^= 1L << (index & 0x3F); }
/** 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 true if and only if it either already had the value true or the corresponding bit in the bit set argument has the * value true. * @param other a bit set */ public void or (Bits other) { int commonWords = Math.min(bits.length, other.bits.length); for (int i = 0; commonWords > i; i++) { bits[i] |= other.bits[i]; } if (commonWords < other.bits.length) { checkCapacity(other.bits.length); for (int i = commonWords, s = other.bits.length; s > i; i++) { bits[i] = other.bits[i]; } } }
/** 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 true if and only if it either already had the value true or the corresponding bit in the bit set argument has the * value true. * @param other a bit set */ public void or (Bits other) { int commonWords = Math.min(bits.length, other.bits.length); for (int i = 0; commonWords > i; i++) { bits[i] |= other.bits[i]; } if (commonWords < other.bits.length) { checkCapacity(other.bits.length); for (int i = commonWords, s = other.bits.length; s > i; i++) { bits[i] = other.bits[i]; } } }
/** 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 true if and only if one of the following statements holds: * <ul> * <li>The bit initially has the value true, and the corresponding bit in the argument has the value false.</li> * <li>The bit initially has the value false, and the corresponding bit in the argument has the value true.</li> * </ul> * @param other */ public void xor (Bits other) { int commonWords = Math.min(bits.length, other.bits.length); for (int i = 0; commonWords > i; i++) { bits[i] ^= other.bits[i]; } if (commonWords < other.bits.length) { checkCapacity(other.bits.length); for (int i = commonWords, s = other.bits.length; s > i; i++) { bits[i] = other.bits[i]; } } }
/** 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 true if and only if one of the following statements holds: * <ul> * <li>The bit initially has the value true, and the corresponding bit in the argument has the value false.</li> * <li>The bit initially has the value false, and the corresponding bit in the argument has the value true.</li> * </ul> * @param other */ public void xor (Bits other) { int commonWords = Math.min(bits.length, other.bits.length); for (int i = 0; commonWords > i; i++) { bits[i] ^= other.bits[i]; } if (commonWords < other.bits.length) { checkCapacity(other.bits.length); for (int i = commonWords, s = other.bits.length; s > i; i++) { bits[i] = other.bits[i]; } } }
/** @param index the index of the bit to flip */ public void flip (int index) { final int word = index >>> 6; checkCapacity(word); bits[word] ^= 1L << (index & 0x3F); }
/** Creates a bit set whose initial size is large enough to explicitly represent bits with indices in the range 0 through * nbits-1. * @param nbits the initial size of the bit set */ public Bits (int nbits) { checkCapacity(nbits >>> 6); }
/** Returns the bit at the given index and sets it in one go. * @param index the index of the bit * @return whether the bit was set before invocation * @throws ArrayIndexOutOfBoundsException if index < 0 */ public boolean getAndSet (int index) { final int word = index >>> 6; checkCapacity(word); long oldBits = bits[word]; bits[word] |= 1L << (index & 0x3F); return bits[word] == oldBits; }
/** @param index the index of the bit to set * @throws ArrayIndexOutOfBoundsException if index < 0 */ public void set (int index) { final int word = index >>> 6; checkCapacity(word); bits[word] |= 1L << (index & 0x3F); }
/** 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 true if and only if it either already had the value true or the corresponding bit in the bit set argument has the * value true. * @param other a bit set */ public void or (Bits other) { int commonWords = Math.min(bits.length, other.bits.length); for (int i = 0; commonWords > i; i++) { bits[i] |= other.bits[i]; } if (commonWords < other.bits.length) { checkCapacity(other.bits.length); for (int i = commonWords, s = other.bits.length; s > i; i++) { bits[i] = other.bits[i]; } } }
/** 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 true if and only if one of the following statements holds: * <ul> * <li>The bit initially has the value true, and the corresponding bit in the argument has the value false.</li> * <li>The bit initially has the value false, and the corresponding bit in the argument has the value true.</li> * </ul> * @param other */ public void xor (Bits other) { int commonWords = Math.min(bits.length, other.bits.length); for (int i = 0; commonWords > i; i++) { bits[i] ^= other.bits[i]; } if (commonWords < other.bits.length) { checkCapacity(other.bits.length); for (int i = commonWords, s = other.bits.length; s > i; i++) { bits[i] = other.bits[i]; } } }