private int calculateSegmentSize ( int factor , int segmentSizeOld ) { DatabaseKelp db = _table . database ( ) ; long segmentFactor = _tableLength / db . getSegmentSizeMin ( ) ; long segmentFactorNew = segmentFactor / factor ; // segment size is (tableSize / factor), restricted to a power of 4 // over the min segment size. if ( segmentFactorNew > 0 ) { int bit = 63 - Long . numberOfLeadingZeros ( segmentFactorNew ) ; bit &= ~ 0x1 ; long segmentFactorPower = ( 1 << bit ) ; if ( segmentFactorPower < segmentFactorNew ) { segmentFactorNew = 4 * segmentFactorPower ; } } long segmentSizeNew = segmentFactorNew * db . getSegmentSizeMin ( ) ; segmentSizeNew = Math . max ( db . getSegmentSizeMin ( ) , segmentSizeNew ) ; long segmentSizeBlob = _blobSizeMax * 4 ; while ( segmentSizeNew < segmentSizeBlob ) { segmentSizeNew *= 4 ; } segmentSizeNew = Math . min ( db . getSegmentSizeMax ( ) , segmentSizeNew ) ; return ( int ) Math . max ( segmentSizeNew , segmentSizeOld ) ; }
Calculate the dynamic segment size .