private void resizeStorage ( ) { int currentElementsPerNode = maxElementsPerNode ; int newElementsPerNode = ( int ) ( currentElementsPerNode * RESIZE_MULTIPLE ) ; if ( newElementsPerNode <= currentElementsPerNode ) { throw new IllegalStateException ( "cannot resize fixed length array from " + currentElementsPerNode + " to " + newElementsPerNode ) ; } FixedLengthElementArray newStorage = new FixedLengthElementArray ( memoryRecycler , numNodes * bitsPerElement * newElementsPerNode ) ; LongStream . range ( 0 , numNodes ) . forEach ( nodeIndex -> { long currentBucketStart = nodeIndex * currentElementsPerNode * bitsPerElement ; long newBucketStart = nodeIndex * newElementsPerNode * bitsPerElement ; for ( int offset = 0 ; offset < currentElementsPerNode ; offset ++ ) { long element = storage . getElementValue ( currentBucketStart + offset * bitsPerElement , bitsPerElement , elementMask ) ; if ( element == NO_ELEMENT ) { break ; // we have exhausted the elements at this index } newStorage . setElementValue ( newBucketStart + offset * bitsPerElement , bitsPerElement , element ) ; } } ) ; storage . destroy ( memoryRecycler ) ; storage = newStorage ; maxElementsPerNode = newElementsPerNode ; }
Resize the underlying storage to a multiple of what it currently is . This method is not thread - safe .