/** * Get the highest recorded value level in the histogram as a double * * @return the Max value recorded in the histogram */ @Override public double getMaxValueAsDouble() { return getMaxValue(); }
/** * Get the highest recorded value level in the histogram * * @return the Max value recorded in the histogram */ public double getMaxValue() { return integerValuesHistogram.getMaxValue() * getIntegerToDoubleValueConversionRatio(); }
/** * Encode this histogram into a ByteBuffer * @param buffer The buffer to encode into * @return The number of bytes written to the buffer */ synchronized public int encodeIntoByteBuffer(final ByteBuffer buffer) { final long maxValue = getMaxValue(); final int relevantLength = countsArrayIndex(maxValue) + 1; if (buffer.capacity() < getNeededByteBufferCapacity(relevantLength)) { throw new ArrayIndexOutOfBoundsException("buffer does not have capacity for " + getNeededByteBufferCapacity(relevantLength) + " bytes"); } int initialPosition = buffer.position(); buffer.putInt(getEncodingCookie()); buffer.putInt(0); // Placeholder for payload length in bytes. buffer.putInt(getNormalizingIndexOffset()); buffer.putInt(numberOfSignificantValueDigits); buffer.putLong(lowestDiscernibleValue); buffer.putLong(highestTrackableValue); buffer.putDouble(getIntegerToDoubleValueConversionRatio()); int payloadStartPosition = buffer.position(); fillBufferFromCountsArray(buffer); buffer.putInt(initialPosition + 4, buffer.position() - payloadStartPosition); // Record the payload length return buffer.position() - initialPosition; }
/** * Encode this histogram into a ByteBuffer * @param buffer The buffer to encode into * @return The number of bytes written to the buffer */ synchronized public int encodeIntoByteBuffer(final ByteBuffer buffer) { long maxValue = integerValuesHistogram.getMaxValue(); int relevantLength = integerValuesHistogram.getLengthForNumberOfBuckets( integerValuesHistogram.getBucketsNeededToCoverValue(maxValue)); if (buffer.capacity() < getNeededByteBufferCapacity(relevantLength)) { throw new ArrayIndexOutOfBoundsException("buffer does not have capacity for " + getNeededByteBufferCapacity(relevantLength) + " bytes"); } buffer.putInt(DHIST_encodingCookie); buffer.putInt(getNumberOfSignificantValueDigits()); buffer.putLong(configuredHighestToLowestValueRatio); return integerValuesHistogram.encodeIntoByteBuffer(buffer) + 16; }
if (highestEquivalentValue(otherHistogram.getMaxValue()) > highestEquivalentValue(valueFromIndex(this.countsArrayLength - 1))) { throw new IllegalArgumentException( if ((getCountAtValue(getMaxValue()) <= 0) || getCountAtValue(getMinNonZeroValue()) <= 0) { establishInternalTackingValues();
if (highestRecordableValue < otherHistogram.getMaxValue()) { if (!isAutoResize()) { throw new ArrayIndexOutOfBoundsException( "The other histogram includes values that do not fit in this histogram's range."); resize(otherHistogram.getMaxValue()); updatedMaxValue(Math.max(getMaxValue(), otherHistogram.getMaxValue())); updateMinNonZeroValue(Math.min(getMinNonZeroValue(), otherHistogram.getMinNonZeroValue())); } else { int otherMaxIndex = otherHistogram.countsArrayIndex(otherHistogram.getMaxValue()); long otherCount = otherHistogram.getCountAtIndex(otherMaxIndex); recordValueWithCount(otherHistogram.valueFromIndex(otherMaxIndex), otherCount);
void shiftValuesLeft(final int numberOfBinaryOrdersOfMagnitude, final double newIntegerToDoubleValueConversionRatio) { if (numberOfBinaryOrdersOfMagnitude < 0) { throw new IllegalArgumentException("Cannot shift by a negative number of magnitudes"); } if (numberOfBinaryOrdersOfMagnitude == 0) { return; } if (getTotalCount() == getCountAtIndex(0)) { // (no need to shift any values if all recorded values are at the 0 value level:) return; } final int shiftAmount = numberOfBinaryOrdersOfMagnitude << subBucketHalfCountMagnitude; int maxValueIndex = countsArrayIndex(getMaxValue()); // indicate overflow if maxValue is in the range being wrapped: if (maxValueIndex >= (countsArrayLength - shiftAmount)) { throw new ArrayIndexOutOfBoundsException( "Operation would overflow, would discard recorded value counts"); } long maxValueBeforeShift = maxValueUpdater.getAndSet(this, 0); long minNonZeroValueBeforeShift = minNonZeroValueUpdater.getAndSet(this, Long.MAX_VALUE); boolean lowestHalfBucketPopulated = (minNonZeroValueBeforeShift < (subBucketHalfCount << unitMagnitude)); // Perform the shift: shiftNormalizingIndexByOffset(shiftAmount, lowestHalfBucketPopulated, newIntegerToDoubleValueConversionRatio); // adjust min, max: updateMinAndMax(maxValueBeforeShift << numberOfBinaryOrdersOfMagnitude); if (minNonZeroValueBeforeShift < Long.MAX_VALUE) { updateMinAndMax(minNonZeroValueBeforeShift << numberOfBinaryOrdersOfMagnitude); } }
@Override public int hashCode() { int h = 0; h = oneAtATimeHashStep(h, unitMagnitude); h = oneAtATimeHashStep(h, numberOfSignificantValueDigits); h = oneAtATimeHashStep(h, (int) getTotalCount()); h = oneAtATimeHashStep(h, (int) getMaxValue()); h = oneAtATimeHashStep(h, (int) getMinNonZeroValue()); h += (h << 3); h ^= (h >> 11); h += (h << 15); return h; }
printStream.format(Locale.US, "#[Max = %12." + numberOfSignificantValueDigits + "f, Total count = %12d]\n", getMaxValue() / outputValueUnitScalingRatio, getTotalCount()); printStream.format(Locale.US, "#[Buckets = %12d, SubBuckets = %12d]\n", bucketCount, subBucketCount);
return false; if (getMaxValue() != that.getMaxValue()) { return false;
/** * Get the highest recorded value level in the histogram as a double * * @return the Max value recorded in the histogram */ @Override public double getMaxValueAsDouble() { return getMaxValue(); }
/** * Get the highest recorded value level in the histogram * * @return the Max value recorded in the histogram */ public double getMaxValue() { return integerValuesHistogram.getMaxValue() * getIntegerToDoubleValueConversionRatio(); }
/** * Encode this histogram into a ByteBuffer * @param buffer The buffer to encode into * @return The number of bytes written to the buffer */ synchronized public int encodeIntoByteBuffer(final ByteBuffer buffer) { final long maxValue = getMaxValue(); final int relevantLength = countsArrayIndex(maxValue) + 1; if (buffer.capacity() < getNeededByteBufferCapacity(relevantLength)) { throw new ArrayIndexOutOfBoundsException("buffer does not have capacity for " + getNeededByteBufferCapacity(relevantLength) + " bytes"); } int initialPosition = buffer.position(); buffer.putInt(getEncodingCookie()); buffer.putInt(0); // Placeholder for payload length in bytes. buffer.putInt(getNormalizingIndexOffset()); buffer.putInt(numberOfSignificantValueDigits); buffer.putLong(lowestDiscernibleValue); buffer.putLong(highestTrackableValue); buffer.putDouble(getIntegerToDoubleValueConversionRatio()); int payloadStartPosition = buffer.position(); fillBufferFromCountsArray(buffer); buffer.putInt(initialPosition + 4, buffer.position() - payloadStartPosition); // Record the payload length return buffer.position() - initialPosition; }
/** * Encode this histogram into a ByteBuffer * @param buffer The buffer to encode into * @return The number of bytes written to the buffer */ synchronized public int encodeIntoByteBuffer(final ByteBuffer buffer) { long maxValue = integerValuesHistogram.getMaxValue(); int relevantLength = integerValuesHistogram.getLengthForNumberOfBuckets( integerValuesHistogram.getBucketsNeededToCoverValue(maxValue)); if (buffer.capacity() < getNeededByteBufferCapacity(relevantLength)) { throw new ArrayIndexOutOfBoundsException("buffer does not have capacity for " + getNeededByteBufferCapacity(relevantLength) + " bytes"); } buffer.putInt(DHIST_encodingCookie); buffer.putInt(getNumberOfSignificantValueDigits()); buffer.putLong(configuredHighestToLowestValueRatio); return integerValuesHistogram.encodeIntoByteBuffer(buffer) + 16; }
void shiftValuesLeft(final int numberOfBinaryOrdersOfMagnitude, final double newIntegerToDoubleValueConversionRatio) { if (numberOfBinaryOrdersOfMagnitude < 0) { throw new IllegalArgumentException("Cannot shift by a negative number of magnitudes"); } if (numberOfBinaryOrdersOfMagnitude == 0) { return; } if (getTotalCount() == getCountAtIndex(0)) { // (no need to shift any values if all recorded values are at the 0 value level:) return; } final int shiftAmount = numberOfBinaryOrdersOfMagnitude << subBucketHalfCountMagnitude; int maxValueIndex = countsArrayIndex(getMaxValue()); // indicate overflow if maxValue is in the range being wrapped: if (maxValueIndex >= (countsArrayLength - shiftAmount)) { throw new ArrayIndexOutOfBoundsException( "Operation would overflow, would discard recorded value counts"); } long maxValueBeforeShift = maxValueUpdater.getAndSet(this, 0); long minNonZeroValueBeforeShift = minNonZeroValueUpdater.getAndSet(this, Long.MAX_VALUE); boolean lowestHalfBucketPopulated = (minNonZeroValueBeforeShift < (subBucketHalfCount << unitMagnitude)); // Perform the shift: shiftNormalizingIndexByOffset(shiftAmount, lowestHalfBucketPopulated, newIntegerToDoubleValueConversionRatio); // adjust min, max: updateMinAndMax(maxValueBeforeShift << numberOfBinaryOrdersOfMagnitude); if (minNonZeroValueBeforeShift < Long.MAX_VALUE) { updateMinAndMax(minNonZeroValueBeforeShift << numberOfBinaryOrdersOfMagnitude); } }
if (highestEquivalentValue(otherHistogram.getMaxValue()) > highestEquivalentValue(valueFromIndex(this.countsArrayLength - 1))) { throw new IllegalArgumentException( if ((getCountAtValue(getMaxValue()) <= 0) || getCountAtValue(getMinNonZeroValue()) <= 0) { establishInternalTackingValues();
if (highestRecordableValue < otherHistogram.getMaxValue()) { if (!isAutoResize()) { throw new ArrayIndexOutOfBoundsException( "The other histogram includes values that do not fit in this histogram's range."); resize(otherHistogram.getMaxValue()); updatedMaxValue(Math.max(getMaxValue(), otherHistogram.getMaxValue())); updateMinNonZeroValue(Math.min(getMinNonZeroValue(), otherHistogram.getMinNonZeroValue())); } else { int otherMaxIndex = otherHistogram.countsArrayIndex(otherHistogram.getMaxValue()); long otherCount = otherHistogram.getCountAtIndex(otherMaxIndex); recordValueWithCount(otherHistogram.valueFromIndex(otherMaxIndex), otherCount);
@Override public int hashCode() { int h = 0; h = oneAtATimeHashStep(h, unitMagnitude); h = oneAtATimeHashStep(h, numberOfSignificantValueDigits); h = oneAtATimeHashStep(h, (int) getTotalCount()); h = oneAtATimeHashStep(h, (int) getMaxValue()); h = oneAtATimeHashStep(h, (int) getMinNonZeroValue()); h += (h << 3); h ^= (h >> 11); h += (h << 15); return h; }
printStream.format(Locale.US, "#[Max = %12." + numberOfSignificantValueDigits + "f, Total count = %12d]\n", getMaxValue() / outputValueUnitScalingRatio, getTotalCount()); printStream.format(Locale.US, "#[Buckets = %12d, SubBuckets = %12d]\n", bucketCount, subBucketCount);
return false; if (getMaxValue() != that.getMaxValue()) { return false;