public RunLengthIntegerReaderV2(InStream input, bool signed,
     bool skipCorrupt)
 {
     this.input = input;
     this.signed = signed;
     this.skipCorrupt = skipCorrupt;
     this.utils = new SerializationUtils();
 }
 public void testSubtractionOverflow()
 {
     // cross check results with Guava results below
     SerializationUtils utils = new SerializationUtils();
     Assert.Equal(false, utils.isSafeSubtract(22222222222L, Int64.MinValue));
     Assert.Equal(false, utils.isSafeSubtract(-22222222222L, Int64.MaxValue));
     Assert.Equal(false, utils.isSafeSubtract(Int64.MinValue, Int64.MaxValue));
     Assert.Equal(true, utils.isSafeSubtract(-1553103058346370095L, 6553103058346370095L));
     Assert.Equal(true, utils.isSafeSubtract(0, Int64.MaxValue));
     Assert.Equal(true, utils.isSafeSubtract(Int64.MinValue, 0));
 }
 public void testDoubles()
 {
     int tolerance = 15;
     MemoryStream buffer = new MemoryStream();
     SerializationUtils utils = new SerializationUtils();
     utils.writeDouble(buffer, 1343822337.759);
     Assert.Equal(1343822337.759, utils.readDouble(fromBuffer(buffer)), tolerance);
     buffer = new MemoryStream();
     utils.writeDouble(buffer, 0.8);
     double got = utils.readDouble(fromBuffer(buffer));
     Assert.Equal(0.8, got, tolerance);
 }
示例#4
0
 private void runTest(int numBits)
 {
     long[] inp = new long[SIZE];
     for (int i = 0; i < SIZE; i++)
     {
         long val = 0;
         if (numBits <= 32)
         {
             if (numBits == 1)
             {
                 val = -1 * rand.Next(2);
             }
             else
             {
                 int max = (numBits == 32) ? Int32.MaxValue : (int)Math.Pow(2, numBits - 1);
                 val = rand.Next(max);
             }
         }
         else
         {
             val = nextLong(rand, (long)Math.Pow(2, numBits - 2));
         }
         if (val % 2 == 0)
         {
             val = -val;
         }
         inp[i] = val;
     }
     long[] deltaEncoded = deltaEncode(inp);
     long minInput = deltaEncoded.Min();
     long maxInput = deltaEncoded.Max();
     long rangeInput = maxInput - minInput;
     SerializationUtils utils = new SerializationUtils();
     int fixedWidth = utils.findClosestNumBits(rangeInput);
     TestInStream.OutputCollector collect = new TestInStream.OutputCollector();
     OutStream output = new OutStream("test", SIZE, null, collect);
     utils.writeInts(deltaEncoded, 0, deltaEncoded.Length, fixedWidth, output);
     output.Flush();
     ByteBuffer inBuf = ByteBuffer.allocate(collect.buffer.size());
     collect.buffer.setByteBuffer(inBuf, 0, collect.buffer.size());
     inBuf.flip();
     long[] buff = new long[SIZE];
     #pragma warning disable 612
     utils.readInts(buff, 0, SIZE, fixedWidth, InStream.create(null, "test", new ByteBuffer[] { inBuf },
         new long[] { 0 }, inBuf.remaining(), null, SIZE));
     #pragma warning restore 612
     for (int i = 0; i < SIZE; i++)
     {
         buff[i] = utils.zigzagDecode(buff[i]);
     }
     Assert.Equal(numBits, fixedWidth);
     Assert.Equal(inp, buff);
 }
示例#5
0
 private long[] deltaEncode(long[] inp)
 {
     long[] output = new long[inp.Length];
     SerializationUtils utils = new SerializationUtils();
     for (int i = 0; i < inp.Length; i++)
     {
         output[i] = utils.zigzagEncode(inp[i]);
     }
     return output;
 }
示例#6
0
 public FloatTreeWriter(int columnId,
                   ObjectInspector inspector,
                   TypeDescription schema,
                   StreamFactory writer,
                   bool nullable)
     : base(columnId, inspector, schema, writer, nullable)
 {
     this.stream = writer.createStream(id,
         OrcProto.Stream.Types.Kind.DATA);
     this.utils = new SerializationUtils();
     recordPosition(rowIndexPosition);
 }
 public RunLengthIntegerWriterV2(PositionedOutputStream output, bool signed, bool alignedBitpacking = true)
 {
     this.output = output;
     this.signed = signed;
     this.alignedBitpacking = alignedBitpacking;
     this.utils = new SerializationUtils();
     clear();
 }
 public RunLengthIntegerReader(InStream input, bool signed)
 {
     this.input = input;
     this.signed = signed;
     this.utils = new SerializationUtils();
 }