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

com.github.jnthnclt.os.lab.collections.baph.BAPHasher Maven / Gradle / Ivy

There is a newer version: 1.12.2
Show newest version
package com.github.jnthnclt.os.lab.collections.baph;

/**
 *
 * @author jonathan.colt
 */
public class BAPHasher {

    public static final BAPHasher SINGLETON = new BAPHasher();

    public int hashCode(byte[] bytes, int offset, int length) {
        return bytes == null ? 0 : compute(bytes, offset, length);
    }

    private int compute(byte[] bytes, int offset, int length) {
        int hash = 0;
        long randMult = 0x5_DEEC_E66DL;
        long randAdd = 0xBL;
        long randMask = (1L << 48) - 1;
        long seed = bytes.length;
        for (int i = offset; i < offset + length; i++) {
            long x = (seed * randMult + randAdd) & randMask;

            seed = x;
            hash += (bytes[i] + 128) * x;
        }
        return hash;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy