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


/**
 * Mapping from {@link DataType} to TypedArray constructors
 * @enum {function}
 */
export const DataType2TypedArrayConstructorMapping = {
    [BinaryDataType.Uint8]: Uint8Array,
    [BinaryDataType.Uint16]: Uint16Array,
    [BinaryDataType.Uint32]: Uint32Array,
    [BinaryDataType.Int8]: Int8Array,
    [BinaryDataType.Int16]: Int16Array,
    [BinaryDataType.Int32]: Int32Array,
    [BinaryDataType.Float16]: Float16Array,
    [BinaryDataType.Float32]: Float32Array,
    [BinaryDataType.Float64]: Float64Array,
};

/**
 *
 * @param {BinaryDataType} dt
 * @returns {constructor|function}
 */
export function compute_typed_array_constructor_from_data_type(dt) {
    const r = DataType2TypedArrayConstructorMapping[dt];

    if (r === undefined) {
        throw new Error(`Unsupported data type '${dt}'`);
    }

    return r;
}
