/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
/**
 * Given a state tree, constructs the sequence of edits which led to that state.
 */
export function getSequentialEdits(initialState) {
    const edits = [];
    for (const state of getSequentialStates(initialState)) {
        if (state.mostRecentEdit !== undefined) {
            edits.push(state.mostRecentEdit);
        }
    }
    return edits;
}
export function getSequentialStates(state) {
    const states = [];
    for (let current = state; current !== undefined; current = current.parent) {
        states.push(current);
    }
    states.reverse();
    return states;
}
function* depthFirstWalk(initialState, generateChildStates, depth, tagFromIntention, mintIntention) {
    yield initialState;
    if (depth > 0) {
        for (const childState of generateChildStates(initialState, tagFromIntention, mintIntention)) {
            yield* depthFirstWalk(childState, generateChildStates, depth - 1, tagFromIntention, mintIntention);
        }
    }
}
export function makeIntentionMinter() {
    let intent = 0;
    return () => intent++;
}
/**
 * Generates all possible sequences of edits of a fixed length.
 * Revision tags will be prefixed with the provided `tagPrefix`.
 */
export function* generatePossibleSequenceOfEdits(initialState, generateChildStates, numberOfEdits, tagPrefix, intentionMinter) {
    for (const state of depthFirstWalk(initialState, generateChildStates, numberOfEdits, (intention) => `${tagPrefix}${intention}`, intentionMinter ?? makeIntentionMinter())) {
        const edits = [];
        for (let current = state; current?.mostRecentEdit !== undefined; current = current.parent) {
            edits.push(current.mostRecentEdit);
        }
        if (edits.length === numberOfEdits) {
            edits.reverse();
            yield edits;
        }
    }
}
//# sourceMappingURL=exhaustiveRebaserUtils.js.map