/* * This is a AssemblyScript port of the original Java version, which was written by * Gil Tene as described in * https://github.com/HdrHistogram/HdrHistogram * and released to the public domain, as explained at * http://creativecommons.org/publicdomain/zero/1.0/ */ import Histogram from "./Histogram"; import { Uint8Storage, Uint16Storage, Uint32Storage, Uint64Storage, } from "./Histogram"; import { decodeFromByteBuffer } from "./encoding"; import ByteBuffer from "./ByteBuffer"; import { PackedArray } from "./packedarray/PackedArray"; export const UINT8ARRAY_ID = idof(); class HistogramAdapter { private _histogram: Histogram; constructor( lowestDiscernibleValue: f64, highestTrackableValue: f64, numberOfSignificantValueDigits: f64, autoResize: boolean, histogram: Histogram | null = null ) { if (histogram) { this._histogram = histogram; } else { this._histogram = new Histogram( lowestDiscernibleValue, highestTrackableValue, numberOfSignificantValueDigits ); this._histogram.autoResize = autoResize; } } public get autoResize(): boolean { return this._histogram.autoResize; } public set autoResize(resize: boolean) { this._histogram.autoResize = resize; } public get highestTrackableValue(): f64 { return this._histogram.highestTrackableValue; } public set highestTrackableValue(value: f64) { this._histogram.highestTrackableValue = value; } public get startTimeStampMsec(): f64 { return this._histogram.startTimeStampMsec; } public set startTimeStampMsec(value: f64) { this._histogram.startTimeStampMsec = value; } public get endTimeStampMsec(): f64 { return this._histogram.endTimeStampMsec; } public set endTimeStampMsec(value: f64) { this._histogram.endTimeStampMsec = value; } public get minNonZeroValue(): f64 { return this._histogram.minNonZeroValue; } public get maxValue(): f64 { return this._histogram.maxValue; } public get totalCount(): f64 { return this._histogram.totalCount; } public get stdDeviation(): f64 { return this._histogram.getStdDeviation(); } public get mean(): f64 { return this._histogram.getMean(); } public get estimatedFootprintInBytes(): f64 { return ( (offsetof>() + this._histogram.estimatedFootprintInBytes) ); } recordValue(value: f64): void { this._histogram.recordSingleValue(value); } recordValueWithCount(value: f64, count: f64): void { this._histogram.recordCountAtValue(count, value); } recordValueWithExpectedInterval( value: f64, expectedIntervalBetweenValueSamples: f64 ): void { this._histogram.recordSingleValueWithExpectedInterval( value, expectedIntervalBetweenValueSamples ); } getValueAtPercentile(percentile: f64): f64 { return this._histogram.getValueAtPercentile(percentile); } outputPercentileDistribution( percentileTicksPerHalfDistance: f64, outputValueUnitScalingRatio: f64 ): string { return this._histogram.outputPercentileDistribution( percentileTicksPerHalfDistance, outputValueUnitScalingRatio ); } copyCorrectedForCoordinatedOmission( expectedIntervalBetweenValueSamples: f64 ): HistogramAdapter { const copy = this._histogram.copyCorrectedForCoordinatedOmission( expectedIntervalBetweenValueSamples ); return new HistogramAdapter(0, 0, 0, false, copy); } addHistogram8(otherHistogram: Histogram8): void { this._histogram.add(otherHistogram._histogram); } addHistogram16(otherHistogram: Histogram16): void { this._histogram.add(otherHistogram._histogram); } addHistogram32(otherHistogram: Histogram32): void { this._histogram.add(otherHistogram._histogram); } addHistogram64(otherHistogram: Histogram64): void { this._histogram.add(otherHistogram._histogram); } addPackedHistogram(otherHistogram: PackedHistogram): void { this._histogram.add(otherHistogram._histogram); } subtractHistogram8(otherHistogram: Histogram8): void { this._histogram.subtract(otherHistogram._histogram); } subtractHistogram16(otherHistogram: Histogram16): void { this._histogram.subtract(otherHistogram._histogram); } subtractHistogram32(otherHistogram: Histogram32): void { this._histogram.subtract(otherHistogram._histogram); } subtractHistogram64(otherHistogram: Histogram64): void { this._histogram.subtract(otherHistogram._histogram); } subtractPackedHistogram(otherHistogram: PackedHistogram): void { this._histogram.subtract(otherHistogram._histogram); } encode(): Uint8Array { return this._histogram.encode(); } reset(): void { this._histogram.reset(); } } export class Histogram8 extends HistogramAdapter {} export class Histogram16 extends HistogramAdapter {} export class Histogram32 extends HistogramAdapter {} export class Histogram64 extends HistogramAdapter {} export class PackedHistogram extends HistogramAdapter {} function decodeHistogram( data: Uint8Array, minBarForHighestTrackableValue: f64 ): HistogramAdapter { const buffer = new ByteBuffer(data); const histogram = decodeFromByteBuffer( buffer, minBarForHighestTrackableValue ); return new HistogramAdapter(0, 0, 0, false, histogram); } export function decodeHistogram8( data: Uint8Array, minBarForHighestTrackableValue: f64 ): HistogramAdapter { return decodeHistogram( data, minBarForHighestTrackableValue ); } export function decodeHistogram16( data: Uint8Array, minBarForHighestTrackableValue: f64 ): HistogramAdapter { return decodeHistogram( data, minBarForHighestTrackableValue ); } export function decodeHistogram32( data: Uint8Array, minBarForHighestTrackableValue: f64 ): HistogramAdapter { return decodeHistogram( data, minBarForHighestTrackableValue ); } export function decodeHistogram64( data: Uint8Array, minBarForHighestTrackableValue: f64 ): HistogramAdapter { return decodeHistogram( data, minBarForHighestTrackableValue ); } export function decodePackedHistogram( data: Uint8Array, minBarForHighestTrackableValue: f64 ): HistogramAdapter { return decodeHistogram( data, minBarForHighestTrackableValue ); }