public int compareTo(IndexedBin o) { return getBinNumber() - o.getBinNumber(); } }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; IndexedBin other = (IndexedBin) obj; if (getBinNumber() != other.getBinNumber()) return false; if (getCount() != other.getCount()) return false; return true; }
public Map<Integer,MutableDouble> getBinCountsMap () { if (bins.isEmpty()) { return Collections.emptyMap(); } Map<Integer,MutableDouble> binCountsMap=new TreeMap<Integer,MutableDouble>(); for (IndexedBin indexedBin : bins) { int binIndex=indexedBin.getBinNumber(); double binCount=indexedBin.getCount(); MutableDouble prevCount=binCountsMap.put(Integer.valueOf(binIndex), new MutableDouble(binCount)); if (prevCount != null) { throw new IllegalStateException("Multiple counts for bin=" + binIndex + " current=" + binCount + "/prev=" + prevCount); } } return binCountsMap; }
public void writeExternal(ObjectOutput out) throws IOException { if (histogramDefinition == null) { throw new StreamCorruptedException("No current histogram definition"); } out.writeLong(serialVersionUID); int numBins=bins.size(); out.writeInt(numBins+1); int maxNumber=(-1); for (IndexedBin bin: bins) { int binNumber=bin.getBinNumber(); out.writeInt(binNumber); out.writeLong(bin.getCount()); if (binNumber > maxNumber) { maxNumber = binNumber; } } /* * We need to preserve backward compatibility, so we add a "fake" extra bin * to signal the existence of the histogram definition */ out.writeInt(maxNumber + 1); out.writeLong(withHistogramDefinitionUID); out.writeObject(histogramDefinition); }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + getBinNumber(); result = prime * result + MathUtil.hashValue(getCount()); return result; }
double currentPercentile = runningCount / total; if (currentPercentile >= cutoff) { return bin.getBinNumber(); lastBinIndex = bin.getBinNumber();
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { long version = in.readLong(); if (version != serialVersionUID) { throw new StreamCorruptedException("Mismatched serialVersionUID - expected" + serialVersionUID + ", actual=" + version); } int size = in.readInt(), maxNumber=(-1); bins = (size > 0) ? new ArrayList<IndexedBin>(size) : null; boolean readHistogramDefinition=false; for (size-- ; size >= 0; size--) { IndexedBin bin=new IndexedBin(in.readInt(), in.readLong()); int binNumber=bin.getBinNumber(); if (binNumber > maxNumber) { maxNumber = binNumber; } if ((size == 0) && (maxNumber == binNumber) && (bin.getCount() == withHistogramDefinitionUID)) { readHistogramDefinition = true; } else { bins.add(bin); } } bins = (bins == null) ? Collections.<IndexedBin>emptyList() : Collections.unmodifiableList(bins); if (readHistogramDefinition) { histogramDefinition = (HistogramDefinition) in.readObject(); } else { histogramDefinition = InsightGaugeHistogramDefinition.getInstance(); } }
public void toData(DataOutput dataOutput) throws IOException { super.toData(serialVersionUID, dataOutput); dataOutput.writeInt(slots.size()); int usedSlots = 0; for (GaugeMetricValue v : slots) { if (v != null) usedSlots++; } dataOutput.writeInt(usedSlots); int idx = -1; for (GaugeMetricValue v : slots) { idx++; if (v == null) { continue; } dataOutput.writeInt(idx); dataOutput.writeDouble(v.getMin()); dataOutput.writeDouble(v.getMax()); dataOutput.writeLong(v.getN()); dataOutput.writeDouble(v.getSum()); dataOutput.writeDouble(v.getSumOfSquares()); dataOutput.writeLong(v.getRange().getStart()); SparseHistogram histo = v.getHistogram(); dataOutput.writeInt(histo.getBins().size()); for (IndexedBin bin : histo.getBins()) { dataOutput.writeInt(bin.getBinNumber()); dataOutput.writeLong(bin.getCount()); } } }
/** * Add all data from another histogram into this accumulator. The passed * histogram must be created against the same {@link HistogramDefinition} as * any other histograms passed into this accumulator. */ public void add(SparseHistogram histo) { for (IndexedBin addBin : histo.getBins()) { MutableLong bin = getOrCreateBin(addBin.getBinNumber()); bin.increment(addBin.getCount()); } }
target.addHistogramEntry(bins.get(b).getBinNumber(), binAllocated);
Map<Integer,Bin> binsMap=new TreeMap<Integer, Bin>(); for (IndexedBin indexBin : populatedBins) { int mappedIndex=indexBin.getBinNumber(); BinDefinition mappedBin=def.getBinDefinition(mappedIndex); long mappedValue=indexBin.getCount();
int binIndex=indexedBin.getBinNumber(); BinDefinition binDef=histogramDefinition.getBinDefinition(binIndex); double binStart=binDef.getStart(), binEnd=binDef.getEnd();