docs: private void calculateInsideBeam(int spanStart, int spanEnd, BeamSearchCfgParseChart chart,
        long[] treeEncodingOffsets) {
      // For efficiency, precompute values which are used repeatedly in the loop
      // below.
      double[] values = binaryDistributionWeights.getValues();
      long[] dimensionOffsets = binaryDistributionWeights.getDimensionOffsets();
  
      for (int i = 0; i < spanEnd - spanStart; i++) {
        for (int j = i + 1; j < (canSkipTerminals ? 1 + spanEnd - spanStart : i + 2); j++) {
  
          // These variables store the (integer encoded) parse trees from the two
          // subspans.
          long[] leftParseTreeKeys = chart.getParseTreeKeysForSpan(spanStart, spanStart + i);
          double[] leftParseTreeProbs = chart.getParseTreeProbsForSpan(spanStart, spanStart + i);
          int numLeftParseTrees = chart.getNumParseTreeKeysForSpan(spanStart, spanStart + i);
          long[] rightParseTreeKeys = chart.getParseTreeKeysForSpan(spanStart + j, spanEnd);
          double[] rightParseTreeProbs = chart.getParseTreeProbsForSpan(spanStart + j, spanEnd);
          int numRightParseTrees = chart.getNumParseTreeKeysForSpan(spanStart + j, spanEnd);
  
          long spanKey = ((spanStart + i) * treeEncodingOffsets[2]) + ((spanStart + j) * treeEncodingOffsets[3]);
          for (int leftIndex = 0; leftIndex < numLeftParseTrees; leftIndex++) {
            // Parse out the parent node's index from the left tree.
            int leftRoot = (int) ((leftParseTreeKeys[leftIndex] % treeEncodingOffsets[3]) / treeEncodingOffsets[4]);
            long leftIndexPartialKey = (leftIndex * treeEncodingOffsets[0]) + spanKey;
            for (int rightIndex = 0; rightIndex < numRightParseTrees; rightIndex++) {
              int rightRoot = (int) ((rightParseTreeKeys[rightIndex] % treeEncodingOffsets[3]) / treeEncodingOffsets[4]);
              long rightIndexPartialKey = (rightIndex * treeEncodingOffsets[1]) + leftIndexPartialKey;
  
              // Compute the tensor index containing any production rules
              // where leftRoot is the left nonterminal and rightRoot is the right
              // nonterminal.
              long partialKeyNum = leftRoot * dimensionOffsets[0] + rightRoot * dimensionOffsets[1];
              int startIndex = binaryDistributionWeights.getNearestIndex(partialKeyNum);
              long endKeyNum = partialKeyNum + dimensionOffsets[1];
              long startKeyNum;
  
              while (startIndex < values.length) {
                startKeyNum = binaryDistributionWeights.indexToKeyNum(startIndex);
                if (startKeyNum >= endKeyNum) {
                  break;
                }
                double treeProb = leftParseTreeProbs[leftIndex] * rightParseTreeProbs[rightIndex] * values[startIndex];
                long treeKeyNum = rightIndexPartialKey + startKeyNum - partialKeyNum;
                chart.addParseTreeKeyForSpan(spanStart, spanEnd, treeKeyNum, treeProb);
  
                startIndex++;
              }
            }
          }
        }
      }
    }