List of usage examples for org.apache.lucene.util BitUtil zigZagEncode
public static long zigZagEncode(long l)
From source file:org.codelibs.elasticsearch.common.io.stream.StreamOutput.java
License:Apache License
/** * Writes a long in a variable-length format. Writes between one and ten bytes. * Values are remapped by sliding the sign bit into the lsb and then encoded as an unsigned number * e.g., 0 -;> 0, -1 -;> 1, 1 -;> 2, ..., Long.MIN_VALUE -;> -1, Long.MAX_VALUE -;> -2 * Numbers with small absolute value will have a small encoding * If the numbers are known to be non-negative, use {#writeVLong(long)} *//*w ww. j ava2 s . c o m*/ public void writeZLong(long i) throws IOException { // zig-zag encoding cf. https://developers.google.com/protocol-buffers/docs/encoding?hl=en long value = BitUtil.zigZagEncode(i); while ((value & 0xFFFFFFFFFFFFFF80L) != 0L) { writeByte((byte) ((value & 0x7F) | 0x80)); value >>>= 7; } writeByte((byte) (value & 0x7F)); }