Class PForUtil


  • final class PForUtil
    extends java.lang.Object
    Utility class to encode sequences of 128 small positive integers.
    • Constructor Summary

      Constructors 
      Constructor Description
      PForUtil​(ForUtil forUtil)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) static boolean allEqual​(long[] l)  
      private void applyExceptions32​(int bitsPerValue, int numExceptions, DataInput in, long[] longs)
      Apply the exceptions where the values are packed two-per-long in longs.
      (package private) void decode​(DataInput in, long[] longs)
      Decode 128 integers into ints.
      (package private) void decodeAndPrefixSum​(DataInput in, long base, long[] longs)
      Decode deltas, compute the prefix sum and add base to all decoded longs.
      (package private) void encode​(long[] longs, DataOutput out)
      Encode 128 integers from longs into out.
      private static void expand32​(long[] longs)
      Expand the values packed two-per-long in longs into 128 individual long values stored back into longs.
      private static void fillSameValue32​(long[] longs, long val)
      Fills the longs with the provided val, packed two values per long (using 32 bits per value).
      private static void innerPrefixSum32​(long[] longs)
      Unrolled "inner" prefix sum logic where the values are packed two-per-long in longs.
      private static void prefixSum32​(long[] longs, long base)
      Apply prefix sum logic where the values are packed two-per-long in longs.
      private static void prefixSumOf​(long[] longs, long base, long val)
      Fill longs with the final values for the case of all deltas being val.
      private static void prefixSumOfOnes​(long[] longs, long base)
      Fill longs with the final values for the case of all deltas being 1.
      (package private) void skip​(DataInput in)
      Skip 128 integers.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • IDENTITY_PLUS_ONE

        private static final long[] IDENTITY_PLUS_ONE
      • forUtil

        private final ForUtil forUtil
      • exceptionBuff

        private final byte[] exceptionBuff
    • Constructor Detail

      • PForUtil

        PForUtil​(ForUtil forUtil)
    • Method Detail

      • allEqual

        static boolean allEqual​(long[] l)
      • encode

        void encode​(long[] longs,
                    DataOutput out)
             throws java.io.IOException
        Encode 128 integers from longs into out.
        Throws:
        java.io.IOException
      • decode

        void decode​(DataInput in,
                    long[] longs)
             throws java.io.IOException
        Decode 128 integers into ints.
        Throws:
        java.io.IOException
      • decodeAndPrefixSum

        void decodeAndPrefixSum​(DataInput in,
                                long base,
                                long[] longs)
                         throws java.io.IOException
        Decode deltas, compute the prefix sum and add base to all decoded longs.
        Throws:
        java.io.IOException
      • skip

        void skip​(DataInput in)
           throws java.io.IOException
        Skip 128 integers.
        Throws:
        java.io.IOException
      • prefixSumOfOnes

        private static void prefixSumOfOnes​(long[] longs,
                                            long base)
        Fill longs with the final values for the case of all deltas being 1. Note this assumes there are no exceptions to apply.
      • prefixSumOf

        private static void prefixSumOf​(long[] longs,
                                        long base,
                                        long val)
        Fill longs with the final values for the case of all deltas being val. Note this assumes there are no exceptions to apply.
      • fillSameValue32

        private static void fillSameValue32​(long[] longs,
                                            long val)
        Fills the longs with the provided val, packed two values per long (using 32 bits per value).
      • applyExceptions32

        private void applyExceptions32​(int bitsPerValue,
                                       int numExceptions,
                                       DataInput in,
                                       long[] longs)
                                throws java.io.IOException
        Apply the exceptions where the values are packed two-per-long in longs.
        Throws:
        java.io.IOException
      • prefixSum32

        private static void prefixSum32​(long[] longs,
                                        long base)
        Apply prefix sum logic where the values are packed two-per-long in longs.
      • expand32

        private static void expand32​(long[] longs)
        Expand the values packed two-per-long in longs into 128 individual long values stored back into longs.
      • innerPrefixSum32

        private static void innerPrefixSum32​(long[] longs)
        Unrolled "inner" prefix sum logic where the values are packed two-per-long in longs. After this method, the final values will be correct for all high-order bits (values [0..63]) but a final prefix loop will still need to run to "correct" the values of [64..127] in the low-order bits, which need the 64th value added to all of them.