Skip to content

Commit b9002a6

Browse files
committed
refactor: use BitSet to record non-zero components instead of HashSet
1 parent 6856c2b commit b9002a6

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

measure/src/main/java/net/laprun/sustainability/power/measure/OngoingPowerMeasure.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package net.laprun.sustainability.power.measure;
22

33
import java.time.Duration;
4-
import java.util.HashSet;
5-
import java.util.Set;
4+
import java.util.BitSet;
65

76
import org.apache.commons.math3.util.FastMath;
87

@@ -13,7 +12,7 @@ public class OngoingPowerMeasure implements PowerMeasure {
1312
private final SensorMetadata sensorMetadata;
1413
private final long startedAt;
1514
private final double[] averages;
16-
private final Set<Integer> nonZeroComponents;
15+
private final BitSet nonZeroComponents;
1716
private final int[] totalComponents;
1817
private final int totalIndex;
1918
private double minTotal = Double.MAX_VALUE;
@@ -35,7 +34,7 @@ public OngoingPowerMeasure(SensorMetadata sensorMetadata) {
3534
totalIndex = numComponents;
3635
averages = new double[measuresNb];
3736
// we don't need to record the total component as a non-zero component since it's almost never zero and we compute the std dev separately
38-
nonZeroComponents = new HashSet<>(numComponents);
37+
nonZeroComponents = new BitSet(numComponents);
3938
totalComponents = sensorMetadata.totalComponents();
4039
}
4140

@@ -56,7 +55,7 @@ public void recordMeasure(double[] components) {
5655
final var componentValue = components[component];
5756
// record that the value is not zero
5857
if (componentValue != 0) {
59-
nonZeroComponents.add(component);
58+
nonZeroComponents.set(component);
6059
}
6160
recordComponentValue(component, componentValue);
6261
averages[component] = averages[component] == 0 ? componentValue

0 commit comments

Comments
 (0)