/*!
 * Custom elements for Nanopore-Digital Web applications
 */
/**
 * Returns a given number between a min and max
 * @param min - the minimum number
 * @param n - the number to clamp
 * @param max - the maximum number
 * @returns the clamped number
 */
export const clamp = (min, n, max) => {
    return Math.max(min, Math.min(n, max));
};
/**
 * Generates a 53-bit hash from any given string
 * @param str - the string to hash
 * @param seed - optionally supply a seed (unsigned integer, 32-bit max) for alternate streams of the same input
 * @returns a 53-bit hash integer
 */
export function cyrb53(str, seed = 0) {
    let h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed;
    for (let i = 0, ch; i < str.length; i++) {
        ch = str.charCodeAt(i);
        h1 = Math.imul(h1 ^ ch, 2654435761);
        h2 = Math.imul(h2 ^ ch, 1597334677);
    }
    h1 =
        Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^
            Math.imul(h2 ^ (h2 >>> 13), 3266489909);
    h2 =
        Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^
            Math.imul(h1 ^ (h1 >>> 13), 3266489909);
    return 4294967296 * (2097151 & h2) + (h1 >>> 0);
}
