"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.computeNumericOrdinal = exports.computeHierarchicalOrdinal = void 0;
/* eslint-disable no-bitwise */
const common_utils_1 = require("@fluidframework/common-utils");
function computeHierarchicalOrdinal(maxCount, actualCount, parentOrdinal, previousOrdinal) {
    (0, common_utils_1.assert)(maxCount <= 16 && actualCount <= maxCount, 0x3f0 /* count must be less than max, and max must be 16 or less */);
    const ordinalWidth = 1 << (maxCount - actualCount);
    let ordinal;
    if (previousOrdinal === undefined) {
        ordinal = parentOrdinal + String.fromCharCode(ordinalWidth - 1);
    }
    else {
        const prevOrdCode = previousOrdinal.charCodeAt(previousOrdinal.length - 1);
        const localOrdinal = prevOrdCode + ordinalWidth;
        ordinal = parentOrdinal + String.fromCharCode(localOrdinal);
    }
    return ordinal;
}
exports.computeHierarchicalOrdinal = computeHierarchicalOrdinal;
function computeNumericOrdinal(index) {
    const prefixLen = Math.floor(index / 0xffff);
    const prefix = String.fromCharCode(0xffff).repeat(prefixLen);
    return `${prefix}${String.fromCharCode(index - prefixLen * 0xffff)}`;
}
exports.computeNumericOrdinal = computeNumericOrdinal;
//# sourceMappingURL=ordinal.js.map