public static int hashToIndex(int hash, int length) {
        checkPositive(length, "length must be larger than 0");

        if (hash == Integer.MIN_VALUE) {
            return 0;
        }

        return abs(hash) % length;
    }
public static int hashToIndex ( int hash , int length ) { checkPositive ( length , "length must be larger than 0" ) ; if ( hash == Integer . MIN_VALUE ) { return 0 ; } return abs ( hash ) % length ; }
A function that calculates the index (e.g. to be used in an array/list) for a given hash. The returned value will always
be equal or larger than 0 and will always be smaller than 'length'.

The reason this function exists is to deal correctly with negative and especially the Integer.MIN_VALUE; since that can't
be used safely with a Math.abs function.

@param length the length of the array/list
@return the mod of the hash
@throws IllegalArgumentException if mod smaller than 1.