All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.virtdata.libbasics.shared.unary_int.HashRange Maven / Gradle / Ivy

There is a newer version: 2.12.15
Show newest version
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);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy