Class ForUtil


  • final class ForUtil
    extends java.lang.Object
    Encode all values in normal area with fixed bit width, which is determined by the max value in this block.
    • Field Detail

      • ALL_VALUES_EQUAL

        private static final int ALL_VALUES_EQUAL
        Special number of bits per value used whenever all values to encode are equal.
        See Also:
        Constant Field Values
      • MAX_ENCODED_SIZE

        static final int MAX_ENCODED_SIZE
        Upper limit of the number of bytes that might be required to stored BLOCK_SIZE encoded values.
        See Also:
        Constant Field Values
      • MAX_DATA_SIZE

        static final int MAX_DATA_SIZE
        Upper limit of the number of values that might be decoded in a single call to readBlock(IndexInput, byte[], int[]). Although values after BLOCK_SIZE are garbage, it is necessary to allocate value buffers whose size is >= MAX_DATA_SIZE to avoid ArrayIndexOutOfBoundsExceptions.
      • encodedSizes

        private final int[] encodedSizes
      • iterations

        private final int[] iterations
    • Constructor Detail

      • ForUtil

        ForUtil​(float acceptableOverheadRatio,
                DataOutput out)
         throws java.io.IOException
        Create a new ForUtil instance and save state into out.
        Throws:
        java.io.IOException
      • ForUtil

        ForUtil​(DataInput in)
         throws java.io.IOException
        Restore a ForUtil from a DataInput.
        Throws:
        java.io.IOException
    • Method Detail

      • computeIterations

        private static int computeIterations​(PackedInts.Decoder decoder)
        Compute the number of iterations required to decode BLOCK_SIZE values with the provided PackedInts.Decoder.
      • encodedSize

        private static int encodedSize​(PackedInts.Format format,
                                       int packedIntsVersion,
                                       int bitsPerValue)
        Compute the number of bytes required to encode a block of values that require bitsPerValue bits per value with format format.
      • writeBlock

        void writeBlock​(int[] data,
                        byte[] encoded,
                        IndexOutput out)
                 throws java.io.IOException
        Write a block of data (For format).
        Parameters:
        data - the data to write
        encoded - a buffer to use to encode data
        out - the destination output
        Throws:
        java.io.IOException - If there is a low-level I/O error
      • readBlock

        void readBlock​(IndexInput in,
                       byte[] encoded,
                       int[] decoded)
                throws java.io.IOException
        Read the next block of data (For format).
        Parameters:
        in - the input to use to read data
        encoded - a buffer that can be used to store encoded data
        decoded - where to write decoded data
        Throws:
        java.io.IOException - If there is a low-level I/O error
      • skipBlock

        void skipBlock​(IndexInput in)
                throws java.io.IOException
        Skip the next block of data.
        Parameters:
        in - the input where to read data
        Throws:
        java.io.IOException - If there is a low-level I/O error
      • isAllEqual

        private static boolean isAllEqual​(int[] data)
      • bitsRequired

        private static int bitsRequired​(int[] data)
        Compute the number of bits required to serialize any of the longs in data.