/** * @param bitWidth the number of bits used to encode an int * @param packer factory for bit packing implementations */ public ByteBasedBitPackingEncoder(int bitWidth, Packer packer) { this.bitWidth = bitWidth; this.inputSize = 0; this.totalFullSlabSize = 0; // must be a multiple of bitWidth this.slabSize = (bitWidth == 0) ? 1 : (bitWidth * INITIAL_SLAB_SIZE_MULT); initPackedSlab(); this.packer = packer.newBytePacker(bitWidth); }
/** * @param bitWidth the number of bits used to encode an int * @param packer factory for bit packing implementations */ public ByteBasedBitPackingEncoder(int bitWidth, Packer packer) { this.bitWidth = bitWidth; this.inputSize = 0; this.totalFullSlabSize = 0; // must be a multiple of bitWidth this.slabSize = (bitWidth == 0) ? 1 : (bitWidth * INITIAL_SLAB_SIZE_MULT); initPackedSlab(); this.packer = packer.newBytePacker(bitWidth); }
/** * writes an int using the requested number of bits. * accepts only values less than 2^bitWidth * @param value the value to write * @throws IOException if there is an exception while writing */ public void writeInt(int value) throws IOException { input[inputSize] = value; ++ inputSize; if (inputSize == VALUES_WRITTEN_AT_A_TIME) { pack(); if (packedPosition == slabSize) { slabs.add(BytesInput.from(packed)); totalFullSlabSize += slabSize; if (slabSize < bitWidth * MAX_SLAB_SIZE_MULT) { slabSize *= 2; } initPackedSlab(); } } }
/** * writes an int using the requested number of bits. * accepts only values less than 2^bitWidth * @param value the value to write * @throws IOException if there is an exception while writing */ public void writeInt(int value) throws IOException { input[inputSize] = value; ++ inputSize; if (inputSize == VALUES_WRITTEN_AT_A_TIME) { pack(); if (packedPosition == slabSize) { slabs.add(BytesInput.from(packed)); totalFullSlabSize += slabSize; if (slabSize < bitWidth * MAX_SLAB_SIZE_MULT) { slabSize *= 2; } initPackedSlab(); } } }