io.nosqlbench.virtdata.library.curves4.continuous.common.RealIntDoubleSampler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of driver-cql-shaded Show documentation
Show all versions of driver-cql-shaded Show documentation
A Shaded CQL ActivityType driver for http://nosqlbench.io/
package io.nosqlbench.virtdata.library.curves4.continuous.common;
import io.nosqlbench.virtdata.library.curves4.discrete.common.ThreadSafeHash;
import java.util.function.DoubleUnaryOperator;
import java.util.function.IntToDoubleFunction;
public class RealIntDoubleSampler implements IntToDoubleFunction {
private final DoubleUnaryOperator f;
private final boolean clamp;
private final double clampMax;
private ThreadSafeHash hash;
public RealIntDoubleSampler(DoubleUnaryOperator parentFunc, boolean hash, boolean clamp, double clampMax) {
this.f = parentFunc;
if (hash) {
this.hash = new ThreadSafeHash();
}
this.clamp = clamp;
this.clampMax = clampMax;
}
@Override
public double applyAsDouble(int input) {
long value = input;
if (hash!=null) {
value = hash.applyAsLong(value);
}
double unit = (double) value / (double) Long.MAX_VALUE;
double sample =clamp ? Double.min(clampMax,f.applyAsDouble(unit)) : f.applyAsDouble(unit);
return sample;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy