class HashJoinHelperSizeCalculatorImpl implements HashJoinHelperSizeCalculator {

  @Override
  public long calculateSize(HashJoinMemoryCalculator.PartitionStat partitionStat, double fragmentationFactor) {
    Preconditions.checkArgument(!partitionStat.isSpilled());

    // Account for the size of the SV4 in a hash join helper
    long joinHelperSize = IntVector.VALUE_WIDTH * RecordBatch.MAX_BATCH_ROW_COUNT;

    // Account for the SV4 for each batch that holds links for each batch
    for (HashJoinMemoryCalculator.BatchStat batchStat: partitionStat.getInMemoryBatches()) {
      // Note we don't have to round up to nearest power of 2, since we allocate the exact
      // space needed for the value vector.
      joinHelperSize += batchStat.getNumRecords() * IntVector.VALUE_WIDTH;
    }

    // Note the BitSets of the HashJoin helper are stored on heap, so we don't account for them here.
    // TODO move BitSets to direct memory

    return RecordBatchSizer.multiplyByFactor(joinHelperSize, fragmentationFactor);
  }

  private  HashJoinHelperSizeCalculatorImpl();

}