Skip to content

Commit 7711093

Browse files
[CI] Auto commit changes from spotless
1 parent 486a8bd commit 7711093

File tree

10 files changed

+68
-68
lines changed

10 files changed

+68
-68
lines changed

benchmarks/src/main/java/org/elasticsearch/benchmark/exponentialhistogram/ExponentialHistogramGenerationBench.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
@State(Scope.Thread)
4444
public class ExponentialHistogramGenerationBench {
4545

46-
@Param({ "100", "500", "1000", "5000" , "10000", "20000"})
46+
@Param({ "100", "500", "1000", "5000", "10000", "20000" })
4747
int bucketCount;
4848

4949
@Param({ "NORMAL", "GAUSSIAN" })

libs/exponential-histogram/src/main/java/org/elasticsearch/exponentialhistogram/ExponentialHistogram.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
*/
3131
public interface ExponentialHistogram {
3232

33-
//TODO: support min/max/sum/count storage and merging
34-
//TODO: Add special positive and negative infinity buckets to allow representation of explicit bucket histograms with open boundaries
33+
// TODO: support min/max/sum/count storage and merging
34+
// TODO: Add special positive and negative infinity buckets to allow representation of explicit bucket histograms with open boundaries
3535

3636
// scale of 38 is the largest scale where at the borders we don't run into problems due to floating point precision when computing
3737
// indices for double values

libs/exponential-histogram/src/main/java/org/elasticsearch/exponentialhistogram/ExponentialHistogramGenerator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public ExponentialHistogram get() {
7373
public static ExponentialHistogram createFor(double... values) {
7474
return createFor(values.length, Arrays.stream(values));
7575
}
76+
7677
/**
7778
* Create a histogram representing the distribution of the given values with at most the given number of buckets.
7879
* If the given bucketCount is greater or equal to the number of values, the resulting histogram will have a

libs/exponential-histogram/src/main/java/org/elasticsearch/exponentialhistogram/ExponentialHistogramMerger.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
package org.elasticsearch.exponentialhistogram;
1111

12-
import java.util.Arrays;
1312
import java.util.OptionalLong;
14-
import java.util.stream.Stream;
1513

1614
import static org.elasticsearch.exponentialhistogram.ExponentialScaleUtils.getMaximumScaleIncrease;
1715

@@ -64,7 +62,8 @@ public ExponentialHistogram get() {
6462

6563
// TODO: this algorithm is very efficient if b has roughly as many buckets as a
6664
// However, if b is much smaller we still have to iterate over all buckets of a which is very wasteful
67-
// This can be optimized by buffering multiple histograms to accumulate first, then in O(log(b)) turn them into a single, merged histogram
65+
// This can be optimized by buffering multiple histograms to accumulate first, then in O(log(b)) turn them into a single, merged
66+
// histogram
6867
// (b is the number of buffered buckets)
6968

7069
private void merge(FixedCapacityExponentialHistogram output, ExponentialHistogram a, ExponentialHistogram b) {

libs/exponential-histogram/src/main/java/org/elasticsearch/exponentialhistogram/ExponentialHistogramQuantile.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,12 @@ public static double getQuantile(ExponentialHistogram histo, double quantile) {
4545
double upperFactor = exactRank - lowerRank;
4646

4747
// TODO: if we want more performance here, we could iterate the buckets once instead of twice
48-
return getElementAtRank(histo, lowerRank, negCount, zeroCount) * ( 1 - upperFactor)
49-
+getElementAtRank(histo, upperRank, negCount, zeroCount) * upperFactor;
48+
return getElementAtRank(histo, lowerRank, negCount, zeroCount) * (1 - upperFactor) + getElementAtRank(
49+
histo,
50+
upperRank,
51+
negCount,
52+
zeroCount
53+
) * upperFactor;
5054
}
5155

5256
private static double getElementAtRank(ExponentialHistogram histo, long rank, long negCount, long zeroCount) {

libs/exponential-histogram/src/main/java/org/elasticsearch/exponentialhistogram/ExponentialScaleUtils.java

Lines changed: 51 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import static org.elasticsearch.exponentialhistogram.ExponentialHistogram.MAX_INDEX;
1313
import static org.elasticsearch.exponentialhistogram.ExponentialHistogram.MAX_INDEX_BITS;
14-
import static org.elasticsearch.exponentialhistogram.ExponentialHistogram.MAX_SCALE;
1514
import static org.elasticsearch.exponentialhistogram.ExponentialHistogram.MIN_INDEX;
1615
import static org.elasticsearch.exponentialhistogram.ExponentialHistogram.MIN_SCALE;
1716

@@ -30,58 +29,57 @@ public class ExponentialScaleUtils {
3029
* The constant is computed using the following formula:
3130
* <code>(1 + 2^scale * ( 1 - log2(1 + 2^(2^-scale))))</code>
3231
*/
33-
static final double[] SCALE_UP_CONSTANT_TABLE = new double[]{
34-
4.8828125E-4,
35-
9.765625E-4,
36-
0.001953125,
37-
0.00390625,
38-
0.0078125,
39-
0.015625,
40-
0.03124999998950301,
41-
0.06249862414928998,
42-
0.12429693135076524,
43-
0.22813428968741514,
44-
0.33903595255631885,
45-
0.4150374992788438,
46-
0.45689339367277604,
47-
0.47836619809201575,
48-
0.4891729613112115,
49-
0.49458521106164327,
50-
0.497292446757125,
51-
0.4986462035295225,
52-
0.4993230992835585,
53-
0.4996615493316266,
54-
0.49983077462704417,
55-
0.49991538730867596,
56-
0.4999576936537322,
57-
0.4999788468267904,
58-
0.4999894234133857,
59-
0.4999947117066917,
60-
0.4999973558533457,
61-
0.49999867792667285,
62-
0.4999993389633364,
63-
0.4999996694816682,
64-
0.4999998347408341,
65-
0.49999991737041705,
66-
0.4999999586852085,
67-
0.49999997934260426,
68-
0.49999998967130216,
69-
0.49999999483565105,
70-
0.4999999974178255,
71-
0.49999999870891276,
72-
0.4999999993544564,
73-
0.4999999996772282,
74-
0.4999999998386141,
75-
0.49999999991930705,
76-
0.49999999995965355,
77-
0.49999999997982675,
78-
0.4999999999899134,
79-
0.4999999999949567,
80-
0.49999999999747835,
81-
0.4999999999987392,
82-
0.49999999999936956,
83-
0.4999999999996848
84-
};
32+
static final double[] SCALE_UP_CONSTANT_TABLE = new double[] {
33+
4.8828125E-4,
34+
9.765625E-4,
35+
0.001953125,
36+
0.00390625,
37+
0.0078125,
38+
0.015625,
39+
0.03124999998950301,
40+
0.06249862414928998,
41+
0.12429693135076524,
42+
0.22813428968741514,
43+
0.33903595255631885,
44+
0.4150374992788438,
45+
0.45689339367277604,
46+
0.47836619809201575,
47+
0.4891729613112115,
48+
0.49458521106164327,
49+
0.497292446757125,
50+
0.4986462035295225,
51+
0.4993230992835585,
52+
0.4996615493316266,
53+
0.49983077462704417,
54+
0.49991538730867596,
55+
0.4999576936537322,
56+
0.4999788468267904,
57+
0.4999894234133857,
58+
0.4999947117066917,
59+
0.4999973558533457,
60+
0.49999867792667285,
61+
0.4999993389633364,
62+
0.4999996694816682,
63+
0.4999998347408341,
64+
0.49999991737041705,
65+
0.4999999586852085,
66+
0.49999997934260426,
67+
0.49999998967130216,
68+
0.49999999483565105,
69+
0.4999999974178255,
70+
0.49999999870891276,
71+
0.4999999993544564,
72+
0.4999999996772282,
73+
0.4999999998386141,
74+
0.49999999991930705,
75+
0.49999999995965355,
76+
0.49999999997982675,
77+
0.4999999999899134,
78+
0.4999999999949567,
79+
0.49999999999747835,
80+
0.4999999999987392,
81+
0.49999999999936956,
82+
0.4999999999996848 };
8583

8684
/**
8785
* Computes the new index for a bucket when adjusting the scale of the histogram by the given amount.
@@ -110,7 +108,6 @@ static long adjustScale(long index, int currentScale, int scaleAdjustment) {
110108
}
111109
}
112110

113-
114111
/**
115112
* Equivalent to mathematically correct comparison of the lower bucket boundaries of the given buckets
116113
*/

libs/exponential-histogram/src/main/java/org/elasticsearch/exponentialhistogram/FixedCapacityExponentialHistogram.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void reset() {
5757
*/
5858
public void resetBuckets(int scale) {
5959
if (scale > MAX_SCALE || scale < MIN_SCALE) {
60-
throw new IllegalArgumentException("scale must be in range ["+MIN_SCALE+".."+MAX_SCALE+"]");
60+
throw new IllegalArgumentException("scale must be in range [" + MIN_SCALE + ".." + MAX_SCALE + "]");
6161
}
6262
negativeBucketCount = 0;
6363
positiveBucketCount = 0;

libs/exponential-histogram/src/main/java/org/elasticsearch/exponentialhistogram/ZeroBucket.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99

1010
package org.elasticsearch.exponentialhistogram;
1111

12+
import static org.elasticsearch.exponentialhistogram.ExponentialHistogram.MAX_SCALE;
1213
import static org.elasticsearch.exponentialhistogram.ExponentialHistogram.MIN_INDEX;
1314
import static org.elasticsearch.exponentialhistogram.ExponentialScaleUtils.compareLowerBoundaries;
1415
import static org.elasticsearch.exponentialhistogram.ExponentialScaleUtils.computeIndex;
1516
import static org.elasticsearch.exponentialhistogram.ExponentialScaleUtils.getLowerBucketBoundary;
16-
import static org.elasticsearch.exponentialhistogram.ExponentialHistogram.MAX_SCALE;
1717

1818
public record ZeroBucket(long index, int scale, long count) {
1919

libs/exponential-histogram/src/test/java/org/elasticsearch/exponentialhistogram/ExponentialHistogramGeneratorTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
public class ExponentialHistogramGeneratorTests extends ESTestCase {
1818

1919
public void testVeryLargeValue() {
20-
double value = Double.MAX_VALUE/10;
20+
double value = Double.MAX_VALUE / 10;
2121
ExponentialHistogram histo = ExponentialHistogramGenerator.createFor(value);
2222

2323
long index = histo.positiveBuckets().peekIndex();

libs/exponential-histogram/src/test/java/org/elasticsearch/exponentialhistogram/ExponentialScaleUtilsTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void testRandomValueIndexing() {
7171
// generate values in the range 10^-100 to 10^100
7272
double exponent = rnd.nextDouble() * 200 - 100;
7373
double testValue = Math.pow(10, exponent);
74-
int scale = rnd.nextInt(MIN_SCALE/2, MAX_SCALE/2);
74+
int scale = rnd.nextInt(MIN_SCALE / 2, MAX_SCALE / 2);
7575
long index = computeIndex(testValue, scale);
7676

7777
double lowerBound = getLowerBucketBoundary(index, scale);
@@ -160,13 +160,12 @@ public void testUpscalingAccuracy() {
160160
for (int i = 0; i < 10_000; i++) {
161161

162162
int startScale = rnd.nextInt(minScale, maxScale);
163-
int scaleIncrease = rnd.nextInt(1, maxScale-startScale + 1);
163+
int scaleIncrease = rnd.nextInt(1, maxScale - startScale + 1);
164164

165165
long index = MAX_INDEX >> scaleIncrease >> (int) (rnd.nextDouble() * (MAX_INDEX_BITS - scaleIncrease));
166166
index = Math.max(1, index);
167167
index = (long) (rnd.nextDouble() * index) * (rnd.nextBoolean() ? 1 : -1);
168168

169-
170169
double midPoint = getPointOfLeastRelativeError(index, startScale);
171170
// limit the numeric range, otherwise we get rounding errors causing the test to fail
172171
while (midPoint > Math.pow(10, 10) || midPoint < Math.pow(10, -10)) {

0 commit comments

Comments
 (0)