import { utcDateToExcelSerial } from '@bilig/formula';
export function createRecalcVolatileState(now) {
    return {
        nowSerial: utcDateToExcelSerial(now()),
        randomValues: [],
        randomCursor: 0,
    };
}
function ensureVolatileRandomValues(state, count, random) {
    const needed = state.randomCursor + count - state.randomValues.length;
    if (needed <= 0) {
        return;
    }
    for (let index = 0; index < needed; index += 1) {
        state.randomValues.push(random());
    }
}
export function consumeVolatileRandomValues(state, count, random) {
    ensureVolatileRandomValues(state, count, random);
    const values = state.randomValues.slice(state.randomCursor, state.randomCursor + count);
    state.randomCursor += count;
    return Float64Array.from(values);
}
export function toOrderedUint32(ordered, orderedCount) {
    if (ordered instanceof Uint32Array) {
        return ordered;
    }
    const next = new Uint32Array(orderedCount);
    for (let index = 0; index < orderedCount; index += 1) {
        next[index] = ordered[index] ?? 0;
    }
    return next;
}
//# sourceMappingURL=recalc-evaluation-state.js.map