Skip to content

Commit b21bfc9

Browse files
committed
fixed indentation
1 parent 75814d9 commit b21bfc9

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

contents/approximate_counting/code/java/ApproximateCounting.java

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class ApproximateCounting {
1010
* It returns the approximate count
1111
*/
1212
static double n(double v, double a) {
13-
return a * (Math.pow(1 + 1 / a, v) - 1);
13+
return a * (Math.pow(1 + 1 / a, v) - 1);
1414
}
1515

1616

@@ -21,13 +21,13 @@ static double n(double v, double a) {
2121
* It returns the new value for v
2222
*/
2323
static double increment(double v, double a) {
24-
double delta = 1 / (n(v + 1, a) - n(v, a));
24+
double delta = 1 / (n(v + 1, a) - n(v, a));
2525

26-
if (Math.random() <= delta) {
27-
return v + 1;
28-
} else {
29-
return v;
30-
}
26+
if (Math.random() <= delta) {
27+
return v + 1;
28+
} else {
29+
return v;
30+
}
3131
}
3232

3333

@@ -39,13 +39,13 @@ static double increment(double v, double a) {
3939
* It returns the new value for v
4040
*/
4141
static double approximateCount(int nItems, double a) {
42-
double v = 0;
43-
44-
for (int i = 1; i < nItems + 1; i++) {
45-
v = increment(v, a);
46-
}
42+
double v = 0;
43+
44+
for (int i = 1; i < nItems + 1; i++) {
45+
v = increment(v, a);
46+
}
4747

48-
return n(v, a);
48+
return n(v, a);
4949
}
5050

5151
/*
@@ -57,26 +57,26 @@ static double approximateCount(int nItems, double a) {
5757
* It terminates the program on failure
5858
*/
5959
static void testApproximateCount(int nTrails, int nItems, double a, double threshold) {
60-
double avg = DoubleStream.generate(() -> approximateCount(nItems, a))
61-
.limit(nTrails)
62-
.average()
63-
.getAsDouble();
64-
65-
if (Math.abs((avg - nItems) / nItems) < threshold) {
66-
System.out.println("passed");
67-
}
60+
double avg = DoubleStream.generate(() -> approximateCount(nItems, a))
61+
.limit(nTrails)
62+
.average()
63+
.getAsDouble();
64+
65+
if (Math.abs((avg - nItems) / nItems) < threshold) {
66+
System.out.println("passed");
67+
}
6868
}
6969

7070

7171
public static void main(String args[]) {
72-
System.out.println("testing 1,000, a = 30, 1% error");
73-
testApproximateCount(100, 1_000, 30, 0.1);
72+
System.out.println("testing 1,000, a = 30, 1% error");
73+
testApproximateCount(100, 1_000, 30, 0.1);
7474

75-
System.out.println("testing 12,345, a = 10, 1% error");
76-
testApproximateCount(100, 12_345, 10, 0.1);
77-
78-
System.out.println("testing 222,222, a = 0.5, 10% error");
79-
testApproximateCount(100, 222_222, 0.5, 0.2);
75+
System.out.println("testing 12,345, a = 10, 1% error");
76+
testApproximateCount(100, 12_345, 10, 0.1);
77+
78+
System.out.println("testing 222,222, a = 0.5, 10% error");
79+
testApproximateCount(100, 222_222, 0.5, 0.2);
8080
}
8181

8282
}

0 commit comments

Comments
 (0)