boolean get(long bitIndex) { return (data.get((int) (bitIndex >>> 6)) & (1L << bitIndex)) != 0; }
public long getValue(int index) { return rangeCounters.get(index); }
public long get(int index) { return rangeCounters.get(index); }
/** * Gets the current value at position {@code i}. * * @param i the index * @return the current value */ public final double get(int i) { return longBitsToDouble(longs.get(i)); }
/** * Gets the current value at position {@code i}. * * @param i the index * @return the current value */ public final double get(int i) { return longBitsToDouble(longs.get(i)); }
/** * Careful here: if threads are mutating the atomicLongArray while this method is executing, the * final long[] will be a "rolling snapshot" of the state of the bit array. This is usually good * enough, but should be kept in mind. */ public static long[] toPlainArray(AtomicLongArray atomicLongArray) { long[] array = new long[atomicLongArray.length()]; for (int i = 0; i < array.length; ++i) { array[i] = atomicLongArray.get(i); } return array; }
public long getSum() { long sum = 0; for (int i = 0; i < rangeCounters.length(); ++i) { sum += rangeCounters.get(i); } return sum; }
public String toString() { StringBuilder buf = new StringBuilder(); buf.append('['); for (int i = 0; i < rangeCounters.length(); ++i) { if (i != 0) { buf.append(','); } buf.append(rangeCounters.get(i)); } buf.append(']'); return buf.toString(); } }
/** * Returns the String representation of the current values of array. * * @return the String representation of the current values of array */ public String toString() { int iMax = length() - 1; if (iMax == -1) { return "[]"; } // Double.toString(Math.PI).length() == 17 StringBuilder b = new StringBuilder((17 + 2) * (iMax + 1)); b.append('['); for (int i = 0; ; i++) { b.append(longBitsToDouble(longs.get(i))); if (i == iMax) { return b.append(']').toString(); } b.append(',').append(' '); } }
/** * Careful here: if threads are mutating the atomicLongArray while this method is executing, the * final long[] will be a "rolling snapshot" of the state of the bit array. This is usually good * enough, but should be kept in mind. */ public static long[] toPlainArray(AtomicLongArray atomicLongArray) { long[] array = new long[atomicLongArray.length()]; for (int i = 0; i < array.length; ++i) { array[i] = atomicLongArray.get(i); } return array; }
@Managed public long getCompletedSplitsLevel0() { return completedSplitsPerLevel.get(0); }
@Managed public long getCompletedTasksLevel2() { return completedTasksPerLevel.get(2); }
@Managed public long getCompletedTasksLevel3() { return completedTasksPerLevel.get(3); }
@Managed public long getCompletedSplitsLevel4() { return completedSplitsPerLevel.get(4); }
@Managed public long getCompletedTasksLevel1() { return completedTasksPerLevel.get(1); }
/** * Atomically adds the given value to the element at index {@code i}. * * @param i the index * @param delta the value to add * @return the previous value */ @CanIgnoreReturnValue public final double getAndAdd(int i, double delta) { while (true) { long current = longs.get(i); double currentVal = longBitsToDouble(current); double nextVal = currentVal + delta; long next = doubleToRawLongBits(nextVal); if (longs.compareAndSet(i, current, next)) { return currentVal; } } }
/** * Atomically adds the given value to the element at index {@code i}. * * @param i the index * @param delta the value to add * @return the updated value */ @CanIgnoreReturnValue public double addAndGet(int i, double delta) { while (true) { long current = longs.get(i); double currentVal = longBitsToDouble(current); double nextVal = currentVal + delta; long next = doubleToRawLongBits(nextVal); if (longs.compareAndSet(i, current, next)) { return nextVal; } } }
public long[] toArray() { long[] array = new long[rangeCounters.length()]; for (int i = 0; i < rangeCounters.length(); i++) { array[i] = rangeCounters.get(i); } return array; }
/** * Writes this {@code BloomFilter} to an output stream, with a custom format (not Java * serialization). This has been measured to save at least 400 bytes compared to regular * serialization. * * <p>Use {@linkplain #readFrom(InputStream, Funnel)} to reconstruct the written BloomFilter. */ public void writeTo(OutputStream out) throws IOException { // Serial form: // 1 signed byte for the strategy // 1 unsigned byte for the number of hash functions // 1 big endian int, the number of longs in our bitset // N big endian longs of our bitset DataOutputStream dout = new DataOutputStream(out); dout.writeByte(SignedBytes.checkedCast(strategy.ordinal())); dout.writeByte(UnsignedBytes.checkedCast(numHashFunctions)); // note: checked at the c'tor dout.writeInt(bits.data.length()); for (int i = 0; i < bits.data.length(); i++) { dout.writeLong(bits.data.get(i)); } }
/** Returns true if the bit changed value. */ boolean set(long bitIndex) { if (get(bitIndex)) { return false; } int longIndex = (int) (bitIndex >>> LONG_ADDRESSABLE_BITS); long mask = 1L << bitIndex; // only cares about low 6 bits of bitIndex long oldValue; long newValue; do { oldValue = data.get(longIndex); newValue = oldValue | mask; if (oldValue == newValue) { return false; } } while (!data.compareAndSet(longIndex, oldValue, newValue)); // We turned the bit on, so increment bitCount. bitCount.increment(); return true; }