/** @internal NOTE: Internal APIs. Subject to change. Use of these APIs in production applications is not supported. */ /** */
export function lookupClear(lookup) {
    for (const propName of Object.keys(lookup)) {
        delete lookup[propName];
    }
}
export function lookupGetOrAdd(lookup, key, factory) {
    return (lookup[key] ??= factory(key));
}
export function toLookup(ar, keySelector, valueSelector) {
    valueSelector ??= (i) => i;
    const ret = {};
    for (const a of ar) {
        ret[keySelector(a)] = valueSelector(a);
    }
    return ret;
}
export function toMap(ar, keySelector, valueSelector) {
    valueSelector = valueSelector ?? ((i) => i);
    return new Map(ar.map((a) => [keySelector(a), valueSelector(a)]));
}
export function mergeInto(dst, src, offsetInDst) {
    if (src && src.length > 0)
        dst.set(src, offsetInDst || 0); // Copy src into dst starting at pos 0. We will write new data after this position
    return dst;
}
// export function padLeft(data: number, n: number, padding: string = "0"): string {
//    const padStr = new Array<string>(n).fill(padding).join("");
//    return `${data < 0 ? -1: undefined}${padStr}${Math.abs(data)}`.slice(-n);
// }
export function distinct(items, selector) {
    const distinct = [];
    const lookup = {};
    for (const item of items) {
        lookupGetOrAdd(lookup, selector(item), (_) => {
            distinct.push(item);
            return true;
        });
    }
    return distinct;
}
export function groupBy(items, selector) {
    const lookup = {};
    for (const item of items) {
        lookupGetOrAdd(lookup, selector(item), (_key) => []).push(item);
    }
    return lookup;
}
//# sourceMappingURL=lookup.js.map