Package org.apache.lucene.store

Examples of org.apache.lucene.store.ByteArrayDataOutput


            // here is the trick:
            //  - the first value is zig-zag encoded so that eg. -5 would become positive and would be better compressed by vLong
            //  - for other values, we only encode deltas using vLong
            final byte[] bytes = new byte[values.size() * ByteUtils.MAX_BYTES_VLONG];
            final ByteArrayDataOutput out = new ByteArrayDataOutput(bytes);
            ByteUtils.writeVLong(out, ByteUtils.zigZagEncode(values.get(0)));
            for (int i = 1; i < values.size(); ++i) {
                final long delta = values.get(i) - values.get(i - 1);
                ByteUtils.writeVLong(out, delta);
            }
            return new BytesRef(bytes, 0, out.getPosition());
        }
View Full Code Here


            default:
                throw new AssertionError();
            }
        }
        final byte[] encoded = new byte[ByteUtils.MAX_BYTES_VLONG * data.length];
        ByteArrayDataOutput out = new ByteArrayDataOutput(encoded);
        for (int i = 0; i < data.length; ++i) {
            final int pos = out.getPosition();
            ByteUtils.writeVLong(out, data[i]);
            if (data[i] < 0) {
                assertEquals(ByteUtils.MAX_BYTES_VLONG, out.getPosition() - pos);
            }
        }
        final ByteArrayDataInput in = new ByteArrayDataInput(encoded);
        for (int i = 0; i < data.length; ++i) {
            assertEquals(data[i], ByteUtils.readVLong(in));
View Full Code Here

  @BeforeClass
  public static void beforeClass() throws IOException {
    INTS = new int[COUNT];
    LONGS = new long[COUNT];
    RANDOM_TEST_BYTES = new byte[COUNT * (5 + 4 + 9 + 8)];
    final ByteArrayDataOutput bdo = new ByteArrayDataOutput(RANDOM_TEST_BYTES);
    for (int i = 0; i < COUNT; i++) {
      final int i1 = INTS[i] = random.nextInt();
      bdo.writeVInt(i1);
      bdo.writeInt(i1);

      final long l1;
      if (rarely()) {
        // a long with lots of zeroes at the end
        l1 = LONGS[i] = ((long) Math.abs(random.nextInt())) << 32;
      } else {
        l1 = LONGS[i] = Math.abs(random.nextLong());
      }
      bdo.writeVLong(l1);
      bdo.writeLong(l1);
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.lucene.store.ByteArrayDataOutput

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.