add FixedValues for double

This commit is contained in:
Jonathan Shook 2020-11-16 17:29:11 -06:00
parent fa85704b83
commit a3e0739ade

View File

@ -0,0 +1,23 @@
package io.nosqlbench.virtdata.library.basics.shared.from_long.to_double;
import io.nosqlbench.virtdata.api.annotations.Example;
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
import java.util.function.LongToDoubleFunction;
@ThreadSafeMapper
public class FixedValues implements LongToDoubleFunction {
private final long[] fixedValues;
@Example({"FixedValues(3D,53D,73d)", "Yield 3D, 53D, 73D, 3D, 53D, 73D, 3D, ..."})
public FixedValues(long... values) {
this.fixedValues = values;
}
@Override
public double applyAsDouble(long value) {
int index = (int) (value % Integer.MAX_VALUE) % fixedValues.length;
return fixedValues[index];
}
}