1 | /*
|
---|
2 | * This is a TypeScript port of the original Java version, which was written by
|
---|
3 | * Gil Tene as described in
|
---|
4 | * https://github.com/HdrHistogram/HdrHistogram
|
---|
5 | * and released to the public domain, as explained at
|
---|
6 | * http://creativecommons.org/publicdomain/zero/1.0/
|
---|
7 | */
|
---|
8 |
|
---|
9 | import JsHistogram from "./JsHistogram";
|
---|
10 | import JsHistogramIterator from "./JsHistogramIterator";
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * Used for iterating through all recorded histogram values using the finest granularity steps supported by the
|
---|
14 | * underlying representation. The iteration steps through all non-zero recorded value counts, and terminates when
|
---|
15 | * all recorded histogram values are exhausted.
|
---|
16 | */
|
---|
17 | class RecordedValuesIterator extends JsHistogramIterator {
|
---|
18 | visitedIndex: number;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * @param histogram The histogram this iterator will operate on
|
---|
22 | */
|
---|
23 | constructor(histogram: JsHistogram) {
|
---|
24 | super();
|
---|
25 | this.doReset(histogram);
|
---|
26 | }
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * Reset iterator for re-use in a fresh iteration over the same histogram data set.
|
---|
30 | */
|
---|
31 | public reset() {
|
---|
32 | this.doReset(this.histogram);
|
---|
33 | }
|
---|
34 |
|
---|
35 | private doReset(histogram: JsHistogram) {
|
---|
36 | super.resetIterator(histogram);
|
---|
37 | this.visitedIndex = -1;
|
---|
38 | }
|
---|
39 |
|
---|
40 | incrementIterationLevel() {
|
---|
41 | this.visitedIndex = this.currentIndex;
|
---|
42 | }
|
---|
43 |
|
---|
44 | reachedIterationLevel() {
|
---|
45 | const currentCount = this.histogram.getCountAtIndex(this.currentIndex);
|
---|
46 | return currentCount != 0 && this.visitedIndex !== this.currentIndex;
|
---|
47 | }
|
---|
48 | }
|
---|
49 |
|
---|
50 | export default RecordedValuesIterator;
|
---|