コード例 #1
0
 @Override
 public DirectBitSet andNot(long longIndex, long value) {
   long l = bytes.readLong(longIndex << 3);
   long l2 = l & ~value;
   bytes.writeLong(longIndex << 3, l2);
   return this;
 }
コード例 #2
0
 @Override
 public DirectBitSet setAll() {
   for (long i = 0; i < longLength; i++) {
     bytes.writeLong(i << 3, ~0L);
   }
   return this;
 }
コード例 #3
0
  @Override
  public DirectBitSet flip(long fromIndex, long exclusiveToIndex) {
    long fromLongIndex = fromIndex >> 6;
    long toIndex = exclusiveToIndex - 1;
    long toLongIndex = toIndex >> 6;
    if (fromIndex < 0 || fromIndex > exclusiveToIndex || toLongIndex >= longLength)
      throw new IndexOutOfBoundsException();

    if (fromLongIndex != toLongIndex) {
      long firstFullLongIndex = fromLongIndex;
      if ((fromIndex & 0x3F) != 0) {
        long fromByteIndex = fromLongIndex << 3;
        long mask = (~0L) << fromIndex;
        long l = bytes.readLong(fromByteIndex);
        long l2 = l ^ mask;
        bytes.writeLong(fromByteIndex, l2);
        firstFullLongIndex++;
      }

      if ((exclusiveToIndex & 0x3F) == 0) {
        for (long i = firstFullLongIndex; i <= toLongIndex; i++) {
          bytes.writeLong(i << 3, ~bytes.readLong(i << 3));
        }
      } else {
        for (long i = firstFullLongIndex; i < toLongIndex; i++) {
          bytes.writeLong(i << 3, ~bytes.readLong(i << 3));
        }

        long toByteIndex = toLongIndex << 3;
        // >>> ~toIndex === >>> (63 - (toIndex & 0x3F))
        long mask = (~0L) >>> ~toIndex;
        long l = bytes.readLong(toByteIndex);
        long l2 = l ^ mask;
        bytes.writeLong(toByteIndex, l2);
      }
    } else {
      long byteIndex = fromLongIndex << 3;
      long mask = ((~0L) << fromIndex) & ((~0L) >>> ~toIndex);
      long l = bytes.readLong(byteIndex);
      long l2 = l ^ mask;
      bytes.writeLong(byteIndex, l2);
    }
    return this;
  }
コード例 #4
0
 @Override
 public DirectBitSet flip(long bitIndex) {
   long longIndex = bitIndex >> 6;
   if (bitIndex < 0 || longIndex >= longLength) throw new IndexOutOfBoundsException();
   long byteIndex = longIndex << 3;
   // only 6 lowest-order bits used, JLS 15.19
   long mask = 1L << bitIndex;
   long l = bytes.readLong(byteIndex);
   long l2 = l ^ mask;
   bytes.writeLong(byteIndex, l2);
   return this;
 }
コード例 #5
0
 @Override
 public DirectBitSet clear(long bitIndex) {
   long longIndex = bitIndex >> 6;
   if (bitIndex < 0 || longIndex >= longLength) throw new IndexOutOfBoundsException();
   long byteIndex = longIndex << 3;
   long mask = 1L << bitIndex;
   long l = bytes.readLong(byteIndex);
   if ((l & mask) == 0) return this;
   long l2 = l & ~mask;
   bytes.writeLong(byteIndex, l2);
   return this;
 }
コード例 #6
0
 @Override
 public boolean setIfClear(long bitIndex) {
   long longIndex = bitIndex >> 6;
   if (bitIndex < 0 || longIndex >= longLength) throw new IndexOutOfBoundsException();
   long byteIndex = longIndex << 3;
   long mask = 1L << bitIndex;
   long l = bytes.readLong(byteIndex);
   long l2 = l | mask;
   if (l == l2) return false;
   bytes.writeLong(byteIndex, l2);
   return true;
 }