/**
 * Useful for computing hashes of large arrays, can pick a relevant stride and skip large chunks of memory while still capturing good amount of unique information from evenly-spaced areas of the array
 * @param {number[]|Uint32Array|Uint16Array|Uint8Array} array
 * @param {number} offset
 * @param {number} length
 * @param {number} stride
 * @return {number}
 */
export function computeStridedIntegerArrayHash(
    array, offset, length, stride
) {
    let hash = length;

    for (let i = offset; i < length; i += stride) {
        const value = array[i] >>> 0; //force uint32

        /**
         * Simple hashing scheme, multiplying existing hash by a prime and adding next value
         * (h<<5) - h ===  h*31
         * @type {number}
         * @ignore
         */
        hash = ((hash << 5) - hash) + value;
    }

    // force uint32
    return hash >>> 0;
}

