4040 */
4141public class FastPFOR implements IntegerCODEC ,SkippableIntegerCODEC {
4242 final static int OVERHEAD_OF_EACH_EXCEPT = 8 ;
43+ private static final int OVERHEAD_OF_EACH_PAGE_IN_INTS = 36 ; // 1 int for the header
44+ // 1 int for the byte array size
45+ // 1 int for the bitmap
46+ // 1 int for byte array padding (to align to 4 bytes)
47+ // 32 to have enough space to bit-pack the exceptions
48+ private static final int OVERHEAD_OF_EACH_BLOCK_IN_INTS = 1 ; // 1 byte for the number of bits allocated per truncated integer
49+ // 1 byte for the number of exceptions
4350 /**
4451 *
4552 */
@@ -65,7 +72,7 @@ public class FastPFOR implements IntegerCODEC,SkippableIntegerCODEC {
6572 * @param pagesize
6673 * the desired page size (recommended value is FastPFOR.DEFAULT_PAGE_SIZE)
6774 */
68- private FastPFOR (int pagesize ) {
75+ FastPFOR (int pagesize ) {
6976 pageSize = pagesize ;
7077 // Initiate arrrays.
7178 byteContainer = makeBuffer (3 * pageSize
@@ -230,6 +237,18 @@ public void headlessUncompress(int[] in, IntWrapper inpos, int inlength,
230237 }
231238 }
232239
240+ @ Override
241+ public int maxHeadlessCompressedLength (IntWrapper compressedPositions , int inlength ) {
242+ inlength = Util .greatestMultiple (inlength , BLOCK_SIZE );
243+
244+ int pageCount = (inlength + pageSize - 1 ) / pageSize ;
245+ int blockCount = inlength / BLOCK_SIZE ;
246+
247+ // getBestBFromData limits the memory used for exceptions so that the total size of the block does not exceed BLOCK_SIZE integers.
248+ int blockSizeInInts = OVERHEAD_OF_EACH_BLOCK_IN_INTS + BLOCK_SIZE ;
249+ return OVERHEAD_OF_EACH_PAGE_IN_INTS * pageCount + blockSizeInInts * blockCount + 24 ;
250+ }
251+
233252 private void decodePage (int [] in , IntWrapper inpos , int [] out ,
234253 IntWrapper outpos , int thissize ) {
235254 final int initpos = inpos .get ();
0 commit comments