private int estimateOptimalCapacity(int aliveValuesToFit) {
    int requiredCapacity = (int)(aliveValuesToFit / loadFactor + 1);
    int currentCapacity = capacity();
    if (requiredCapacity > currentCapacity) {
      //better: round requiredCapacity up to the nearest 2^N
      return currentCapacity * 2;
    }
    else if (requiredCapacity > currentCapacity / 2) {
      return currentCapacity;
    }
    else {
      return Math.max(requiredCapacity, MIN_CAPACITY);
    }
  }
private int estimateOptimalCapacity(int aliveValuesToFit)