20
20
import com .arpnetworking .metrics .mad .model .Quantity ;
21
21
import com .arpnetworking .metrics .mad .model .Unit ;
22
22
import com .arpnetworking .tsdcore .model .CalculatedValue ;
23
- import it .unimi .dsi .fastutil .doubles .Double2IntAVLTreeMap ;
24
- import it .unimi .dsi .fastutil .doubles .Double2IntMap ;
25
- import it .unimi .dsi .fastutil .doubles .Double2IntSortedMap ;
23
+ import it .unimi .dsi .fastutil .doubles .Double2LongAVLTreeMap ;
24
+ import it .unimi .dsi .fastutil .doubles .Double2LongMap ;
25
+ import it .unimi .dsi .fastutil .doubles .Double2LongSortedMap ;
26
26
import it .unimi .dsi .fastutil .objects .ObjectSortedSet ;
27
27
import net .sf .oval .constraint .NotNull ;
28
28
@@ -182,7 +182,7 @@ public HistogramSnapshot getHistogramSnapshot() {
182
182
public HistogramSupportingData toUnit (final Unit newUnit ) {
183
183
if (_unit .isPresent ()) {
184
184
final Histogram newHistogram = new Histogram ();
185
- for (final Map .Entry <Double , Integer > entry : _histogramSnapshot .getValues ()) {
185
+ for (final Map .Entry <Double , Long > entry : _histogramSnapshot .getValues ()) {
186
186
final Double newBucket = newUnit .convert (entry .getKey (), _unit .get ());
187
187
newHistogram .recordValue (newBucket , entry .getValue ());
188
188
}
@@ -259,8 +259,8 @@ public static final class Histogram {
259
259
* @param value The value of the entry.
260
260
* @param count The number of entries at this value.
261
261
*/
262
- public void recordValue (final double value , final int count ) {
263
- _data .merge (truncateToDouble (value ), count , Integer ::sum );
262
+ public void recordValue (final double value , final long count ) {
263
+ _data .merge (truncateToDouble (value ), count , Long ::sum );
264
264
_entriesCount += count ;
265
265
}
266
266
@@ -280,7 +280,7 @@ public void recordValue(final double value) {
280
280
* @param packed The packed bucket key.
281
281
* @param count The number of entries at this value.
282
282
*/
283
- public void recordPacked (final long packed , final int count ) {
283
+ public void recordPacked (final long packed , final long count ) {
284
284
recordValue (unpack (packed ), count );
285
285
}
286
286
@@ -290,8 +290,8 @@ public void recordPacked(final long packed, final int count) {
290
290
* @param histogramSnapshot The histogram snapshot to add to this one.
291
291
*/
292
292
public void add (final HistogramSnapshot histogramSnapshot ) {
293
- for (final Double2IntMap .Entry entry : histogramSnapshot ._data .double2IntEntrySet ()) {
294
- _data .merge (entry .getDoubleKey (), entry .getIntValue (), Integer ::sum );
293
+ for (final Double2LongMap .Entry entry : histogramSnapshot ._data .double2LongEntrySet ()) {
294
+ _data .merge (entry .getDoubleKey (), entry .getLongValue (), Long ::sum );
295
295
}
296
296
_entriesCount += histogramSnapshot ._entriesCount ;
297
297
}
@@ -341,8 +341,8 @@ public Histogram(final int precision) {
341
341
_packMask = (1 << (_precision + EXPONENT_BITS + 1 )) - 1 ;
342
342
}
343
343
344
- private int _entriesCount = 0 ;
345
- private final Double2IntSortedMap _data = new Double2IntAVLTreeMap ();
344
+ private long _entriesCount = 0 ;
345
+ private final Double2LongSortedMap _data = new Double2LongAVLTreeMap ();
346
346
private final int _precision ;
347
347
private final long _truncateMask ;
348
348
private final int _packMask ;
@@ -358,7 +358,7 @@ public Histogram(final int precision) {
358
358
* @author Brandon Arp (brandon dot arp at inscopemetrics dot io)
359
359
*/
360
360
public static final class HistogramSnapshot {
361
- private HistogramSnapshot (final Double2IntSortedMap data , final int entriesCount , final int precision ) {
361
+ private HistogramSnapshot (final Double2LongSortedMap data , final long entriesCount , final int precision ) {
362
362
_precision = precision ;
363
363
_entriesCount = entriesCount ;
364
364
_data .putAll (data );
@@ -375,9 +375,10 @@ public Double getValueAtPercentile(final double percentile) {
375
375
// The Math.min is for the case where the computation may be just
376
376
// slightly larger than the _entriesCount and prevents an index out of range.
377
377
final int target = (int ) Math .min (Math .ceil (_entriesCount * percentile / 100.0D ), _entriesCount );
378
- int accumulated = 0 ;
379
- for (final Double2IntMap .Entry next : _data .double2IntEntrySet ()) {
380
- accumulated += next .getIntValue ();
378
+ // TODO(ville): Is it sufficient for this to be a long?
379
+ long accumulated = 0 ;
380
+ for (final Double2LongMap .Entry next : _data .double2LongEntrySet ()) {
381
+ accumulated += next .getLongValue ();
381
382
if (accumulated >= target ) {
382
383
return next .getDoubleKey ();
383
384
}
@@ -389,7 +390,7 @@ public int getPrecision() {
389
390
return _precision ;
390
391
}
391
392
392
- public int getEntriesCount () {
393
+ public long getEntriesCount () {
393
394
return _entriesCount ;
394
395
}
395
396
@@ -398,8 +399,8 @@ public int getEntriesCount() {
398
399
*
399
400
* @return the histogram bucket count entries
400
401
*/
401
- public ObjectSortedSet <Double2IntMap .Entry > getValues () {
402
- return _data .double2IntEntrySet ();
402
+ public ObjectSortedSet <Double2LongMap .Entry > getValues () {
403
+ return _data .double2LongEntrySet ();
403
404
}
404
405
405
406
/**
@@ -408,12 +409,12 @@ public ObjectSortedSet<Double2IntMap.Entry> getValues() {
408
409
* @param key the histogram bucket key
409
410
* @return the count in the bucket
410
411
*/
411
- public int getValue (final double key ) {
412
+ public long getValue (final double key ) {
412
413
return _data .get (key );
413
414
}
414
415
415
- private int _entriesCount ;
416
- private final Double2IntSortedMap _data = new Double2IntAVLTreeMap ();
416
+ private long _entriesCount ;
417
+ private final Double2LongSortedMap _data = new Double2LongAVLTreeMap ();
417
418
private final int _precision ;
418
419
}
419
420
}
0 commit comments