Exemplo n.º 1
0
        //使用PFor算法对已经压缩的int数组进行解压缩
        public static int[] fastPforDecoder(int[] compressed)
        {
            var codec = new SkippableIntegratedComposition(new IntegratedBinaryPacking(), new IntegratedVariableByte());
            var size  = compressed[0];
            // output vector should be large enough...
            var recovered = new int[size];
            var inPoso    = new IntWrapper(1);
            var outPoso   = new IntWrapper(0);
            var recoffset = new IntWrapper(0);

            codec.headlessUncompress(compressed, inPoso, compressed.Length, recovered, recoffset, size, outPoso);

            return(recovered);
        }
Exemplo n.º 2
0
        public void basicExampleHeadless()
        {
            int[] data = new int[2342351];
            Console.WriteLine("Compressing " + data.Length + " integers in one go using the headless approach");
            // data should be sorted for best
            // results
            for (int k = 0; k < data.Length; ++k)
            {
                data[k] = k;
            }
            // Very important: the data is in sorted order!!! If not, you
            // will get very poor compression with IntegratedBinaryPacking,
            // you should use another CODEC.

            // next we compose a CODEC. Most of the processing
            // will be done with binary packing, and leftovers will
            // be processed using variable byte
            SkippableIntegratedComposition codec = new SkippableIntegratedComposition(new IntegratedBinaryPacking(),
                                                                                      new IntegratedVariableByte());

            // output vector should be large enough...
            int[] compressed = new int[data.Length + 1024];
            // compressed might not be large enough in some cases
            // if you get java.lang.ArrayIndexOutOfBoundsException, try
            // allocating more memory

            /**
             *
             * compressing
             *
             */
            IntWrapper inputoffset  = new IntWrapper(0);
            IntWrapper outputoffset = new IntWrapper(1);

            compressed[0] = data.Length; // we manually store how many integers we
            codec.headlessCompress(data, inputoffset, data.Length, compressed, outputoffset, new IntWrapper(0));
            // got it!
            // inputoffset should be at data.Length but outputoffset tells
            // us where we are...
            Console.WriteLine(
                "compressed from " + data.Length * 4 / 1024 + "KB to " + outputoffset.intValue() * 4 / 1024 + "KB");
            // we can repack the data: (optional)
            compressed = Arrays.copyOf(compressed, outputoffset.intValue());

            /**
             *
             * now uncompressing
             *
             */
            int howmany = compressed[0];// we manually stored the number of

            // compressed integers
            int[]      recovered = new int[howmany];
            IntWrapper recoffset = new IntWrapper(0);

            codec.headlessUncompress(compressed, new IntWrapper(1), compressed.Length, recovered, recoffset, howmany, new IntWrapper(0));
            if (Arrays.equals(data, recovered))
            {
                Console.WriteLine("data is recovered without loss");
            }
            else
            {
                throw new Exception("bug"); // could use assert
            }
            Console.WriteLine();
        }