static long getBucketsNeeded ( long maxKeys , double loadFactor , int bucketSize ) { /* * force a power-of-two bucket count so hash functions for bucket index * can hashBits%numBuckets and get randomly distributed index. See wiki * "Modulo Bias". Only time we can get perfectly distributed index is * when numBuckets is a power of 2. */ long bucketsNeeded = DoubleMath . roundToLong ( ( 1.0 / loadFactor ) * maxKeys / bucketSize , RoundingMode . UP ) ; // get next biggest power of 2 long bitPos = Long . highestOneBit ( bucketsNeeded ) ; if ( bucketsNeeded > bitPos ) bitPos = bitPos << 1 ; return bitPos ; }
Calculates how many buckets are needed to hold the chosen number of keys taking the standard load factor into account .