io.virtdata.libbasics.shared.unary_int.HashRange Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of virtdata-lib-realer Show documentation
Show all versions of virtdata-lib-realer Show documentation
With inspiration from other libraries
package io.virtdata.libbasics.shared.unary_int;
import io.virtdata.annotations.ThreadSafeMapper;
import java.util.function.IntUnaryOperator;
@ThreadSafeMapper
public class HashRange implements IntUnaryOperator {
private final int minValue;
private final int width;
private final Hash hash = new Hash();
public HashRange(int width) {
this.minValue=0;
this.width=width;
}
public HashRange(int minValue, int maxValue) {
this.minValue = minValue;
if (maxValue<=minValue) {
throw new RuntimeException("HashRange must have min and max value in that order.");
}
this.width = maxValue - minValue;
}
@Override
public int applyAsInt(int operand) {
return minValue + (hash.applyAsInt(operand) & width);
}
}