public void writeByteBufferSparse ( ByteBuffer buf , int nonEmptyBuckets ) { writeByteBufferSerdeHeader ( buf , SPARSE_ENCODING_MODE ) ; writeByteBufferCommonFields ( buf ) ; buf . putInt ( nonEmptyBuckets ) ; int bucketsWritten = 0 ; for ( int i = 0 ; i < numBuckets ; i ++ ) { if ( histogram [ i ] > 0 ) { buf . putInt ( i ) ; buf . putLong ( histogram [ i ] ) ; bucketsWritten += 1 ; } if ( bucketsWritten == nonEmptyBuckets ) { break ; } } }
Helper method for toBytesSparse