1 | "use strict";
|
---|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
3 | /*
|
---|
4 | * This is a TypeScript port of the original Java version, which was written by
|
---|
5 | * Gil Tene as described in
|
---|
6 | * https://github.com/HdrHistogram/HdrHistogram
|
---|
7 | * and released to the public domain, as explained at
|
---|
8 | * http://creativecommons.org/publicdomain/zero/1.0/
|
---|
9 | */
|
---|
10 | const JsHistogram_1 = require("./JsHistogram");
|
---|
11 | class TypedArrayHistogram extends JsHistogram_1.default {
|
---|
12 | constructor(arrayCtr, lowestDiscernibleValue, highestTrackableValue, numberOfSignificantValueDigits) {
|
---|
13 | super(lowestDiscernibleValue, highestTrackableValue, numberOfSignificantValueDigits);
|
---|
14 | this.arrayCtr = arrayCtr;
|
---|
15 | this._totalCount = 0;
|
---|
16 | this._counts = new arrayCtr(this.countsArrayLength);
|
---|
17 | }
|
---|
18 | clearCounts() {
|
---|
19 | this._counts.fill(0);
|
---|
20 | }
|
---|
21 | incrementCountAtIndex(index) {
|
---|
22 | const currentCount = this._counts[index];
|
---|
23 | const newCount = currentCount + 1;
|
---|
24 | if (newCount < 0) {
|
---|
25 | throw newCount + " would overflow short integer count";
|
---|
26 | }
|
---|
27 | this._counts[index] = newCount;
|
---|
28 | }
|
---|
29 | addToCountAtIndex(index, value) {
|
---|
30 | const currentCount = this._counts[index];
|
---|
31 | const newCount = currentCount + value;
|
---|
32 | if (newCount < Number.MIN_SAFE_INTEGER ||
|
---|
33 | newCount > Number.MAX_SAFE_INTEGER) {
|
---|
34 | throw newCount + " would overflow integer count";
|
---|
35 | }
|
---|
36 | this._counts[index] = newCount;
|
---|
37 | }
|
---|
38 | setCountAtIndex(index, value) {
|
---|
39 | if (value < Number.MIN_SAFE_INTEGER || value > Number.MAX_SAFE_INTEGER) {
|
---|
40 | throw value + " would overflow integer count";
|
---|
41 | }
|
---|
42 | this._counts[index] = value;
|
---|
43 | }
|
---|
44 | resize(newHighestTrackableValue) {
|
---|
45 | this.establishSize(newHighestTrackableValue);
|
---|
46 | const newCounts = new this.arrayCtr(this.countsArrayLength);
|
---|
47 | newCounts.set(this._counts);
|
---|
48 | this._counts = newCounts;
|
---|
49 | }
|
---|
50 | getCountAtIndex(index) {
|
---|
51 | return this._counts[index];
|
---|
52 | }
|
---|
53 | _getEstimatedFootprintInBytes() {
|
---|
54 | return 1024 + this._counts.BYTES_PER_ELEMENT * this._counts.length;
|
---|
55 | }
|
---|
56 | copyCorrectedForCoordinatedOmission(expectedIntervalBetweenValueSamples) {
|
---|
57 | const copy = new TypedArrayHistogram(this.arrayCtr, this.lowestDiscernibleValue, this.highestTrackableValue, this.numberOfSignificantValueDigits);
|
---|
58 | copy.addWhileCorrectingForCoordinatedOmission(this, expectedIntervalBetweenValueSamples);
|
---|
59 | return copy;
|
---|
60 | }
|
---|
61 | toString() {
|
---|
62 | return `Histogram ${this._counts.BYTES_PER_ELEMENT * 8}b ${JSON.stringify(this, null, 2)}`;
|
---|
63 | }
|
---|
64 | }
|
---|
65 | exports.default = TypedArrayHistogram;
|
---|
66 | //# sourceMappingURL=TypedArrayHistogram.js.map |
---|