Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Written by Gil Tene of Azul Systems, and released to the public domain, as explained at http://creativecommons.org/publicdomain/zero/1.0/

Author(s):
Gil Tene
  
  
  package org.HdrHistogram;
  

A High Dynamic Range (HDR) Histogram using an int count type

See package description for org.HdrHistogram for details.

 
 
 public class IntHistogram extends AbstractHistogram {
     long totalCount;
     final int[] counts;
 
     @Override
     long getCountAtIndex(final int index) {
         return [index];
     }
 
     @Override
     void incrementCountAtIndex(final int index) {
         [index]++;
     }
 
     @Override
     void addToCountAtIndex(final int indexfinal long value) {
         [index] += value;
     }
 
     @Override
     void clearCounts() {
         java.util.Arrays.fill(, 0);
          = 0;
     }

    

InheritDoc:
 
     @Override
     public IntHistogram copy() {
       copy.add(this);
       return copy;
     }

    

InheritDoc:
 
     @Override
     public IntHistogram copyCorrectedForCoordinatedOmission(final long expectedIntervalBetweenValueSamples) {
         toHistogram.addWhileCorrectingForCoordinatedOmission(thisexpectedIntervalBetweenValueSamples);
         return toHistogram;
     }
 
     @Override
     long getTotalCount() {
         return ;
     }
 
     @Override
     void setTotalCount(final long totalCount) {
         this. = totalCount;
     }
 
     @Override
     void incrementTotalCount() {
         ++;
     }
 
     @Override
     void addToTotalCount(long value) {
          += value;
     }
 
     @Override
         return (512 + (4 * .));
     }

    
Construct a IntHistogram given the Highest value to be tracked and a number of significant decimal digits. The histogram will be constructed to implicitly track (distinguish from 0) values as low as 1.

Parameters:
highestTrackableValue The highest value to be tracked by the histogram. Must be a positive integer that is >= 2.
numberOfSignificantValueDigits The number of significant decimal digits to which the histogram will maintain value resolution and separation. Must be a non-negative integer between 0 and 5.
    public IntHistogram(final long highestTrackableValuefinal int numberOfSignificantValueDigits) {
        this(1, highestTrackableValuenumberOfSignificantValueDigits);
    }

    
Construct a IntHistogram given the Lowest and Highest values to be tracked and a number of significant decimal digits. Providing a lowestTrackableValue is useful is situations where the units used for the histogram's values are much smaller that the minimal accuracy required. E.g. when tracking time values stated in nanosecond units, where the minimal accuracy required is a microsecond, the proper value for lowestTrackableValue would be 1000.

Parameters:
lowestTrackableValue The lowest value that can be tracked (distinguished from 0) by the histogram. Must be a positive integer that is >= 1. May be internally rounded down to nearest power of 2.
highestTrackableValue The highest value to be tracked by the histogram. Must be a positive integer that is >= (2 * lowestTrackableValue).
numberOfSignificantValueDigits The number of significant decimal digits to which the histogram will maintain value resolution and separation. Must be a non-negative integer between 0 and 5.
    public IntHistogram(final long lowestTrackableValuefinal long highestTrackableValuefinal int numberOfSignificantValueDigits) {
        super(lowestTrackableValuehighestTrackableValuenumberOfSignificantValueDigits);
         = new int[];
         = 4;
    }

    
Construct a new histogram by decoding it from a ByteBuffer.

Parameters:
buffer The buffer to decode from
minBarForHighestTrackableValue Force highestTrackableValue to be set at least this high
Returns:
The newly constructed histogram
    public static IntHistogram decodeFromByteBuffer(final ByteBuffer buffer,
                                                    final long minBarForHighestTrackableValue) {
        return (IntHistogramdecodeFromByteBuffer(bufferIntHistogram.class,
                minBarForHighestTrackableValue);
    }

    
Construct a new histogram by decoding it from a compressed form in a ByteBuffer.

Parameters:
buffer The buffer to encode into
minBarForHighestTrackableValue Force highestTrackableValue to be set at least this high
Returns:
The newly constructed histogram
Throws:
java.util.zip.DataFormatException
    public static IntHistogram decodeFromCompressedByteBuffer(final ByteBuffer buffer,
                                                              final long minBarForHighestTrackableValuethrows DataFormatException {
        return (IntHistogramdecodeFromCompressedByteBuffer(bufferIntHistogram.class,
                minBarForHighestTrackableValue);
    }
    private void readObject(final ObjectInputStream o)
            throws IOExceptionClassNotFoundException {
        o.defaultReadObject();
    }
    @Override
    synchronized void fillCountsArrayFromBuffer(final ByteBuffer bufferfinal int length) {
        buffer.asIntBuffer().get(, 0, length);
    }
    // We try to cache the LongBuffer used in output cases, as repeated
    // output form the same histogram using the same buffer is likely:
    private IntBuffer cachedDstIntBuffer = null;
    private ByteBuffer cachedDstByteBuffer = null;
    private int cachedDstByteBufferPosition = 0;
    @Override
    synchronized void fillBufferFromCountsArray(final ByteBuffer bufferfinal int length) {
        if (( == null) ||
                (buffer != ) ||
                (buffer.position() != )) {
             = buffer;
             = buffer.position();
             = buffer.asIntBuffer();
        }
        .rewind();
        .put(, 0, length);
    }
New to GrepCode? Check out our FAQ X