function calculateDistanceAlphabetLimit(maxDistance, npostfix, ndirect) {
    if (maxDistance < ndirect + (2 << npostfix)) {
      throw "maxDistance is too small";
    }
    let /** @type{number} */ offset = ((maxDistance - ndirect) >> npostfix) + 4;
    let /** @type{number} */ ndistbits = log2floor(offset) - 1;
    let /** @type{number} */ group = ((ndistbits - 1) << 1) | ((offset >> ndistbits) & 1);
    return ((group - 1) << npostfix) + (1 << npostfix) + ndirect + 16;
  }
@param {number} maxDistance
@param {number} npostfix
@param {number} ndirect
@return {number}