import { assert } from "../../../assert.js";

/**
 * @example `const my_array = new ( UintArrayForCount(x) )(length);`
 * @param {number} max_value maximum value to be contained in the array
 * @returns {function} TypedArray constructor
 */
export function UintArrayForCount(max_value) {
    assert.isNonNegativeInteger(max_value, 'max_value');

    if (max_value <= 256) {
        return Uint8Array;
    } else if (max_value <= 65536) {
        return Uint16Array;
    } else if (max_value <= 4294967295) {
        return Uint32Array;
    } else {
        throw new Error(`Unsupported size ${max_value}`)
    }
}
