## org.apache.mahout.math
Class Varint

    java.lang.Object
      org.apache.mahout.math.Varint

    public final class Varint

extends Object

Encodes signed and unsigned values using a common variable-length scheme, found for example in Google's Protocol Buffers. It uses fewer bytes to encode smaller values, but will use slightly more bytes to encode large values.

Signed values are further encoded using so-called zig-zag encoding in order to make them "compatible" with variable-length encoding.

Method Summary
`static int` `readSignedVarInt(DataInput in)`
`static long` `readSignedVarLong(DataInput in)`
`static int` `readUnsignedVarInt(DataInput in)`
`static long` `readUnsignedVarLong(DataInput in)`
`static void` `writeSignedVarInt(int value, DataOutput out)`
`static void` `writeSignedVarLong(long value, DataOutput out)` Encodes a value using the variable-length encoding from Google Protocol Buffers.
`static void` `writeUnsignedVarInt(int value, DataOutput out)`
`static void` `writeUnsignedVarLong(long value, DataOutput out)` Encodes a value using the variable-length encoding from Google Protocol Buffers.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Method Detail

### writeSignedVarLong

    public static void writeSignedVarLong(long value,
                                          DataOutput out)
                                   throws IOException

  Encodes a value using the variable-length encoding from Google Protocol Buffers. It uses zig-zag encoding to efficiently encode signed values. If values are known to be nonnegative, `writeUnsignedVarLong(long, DataOutput)` should be used.

  Parameters:
    `value` - value to encode
    `out` - to write bytes to
  Throws:
    `IOException` - if `DataOutput` throws `IOException`

### writeUnsignedVarLong

    public static void writeUnsignedVarLong(long value,
                                            DataOutput out)
                                     throws IOException

  Encodes a value using the variable-length encoding from Google Protocol Buffers. Zig-zag is not used, so input must not be negative. If values can be negative, use `writeSignedVarLong(long, DataOutput)` instead. This method treats negative input as like a large unsigned value.

  Parameters:
    `value` - value to encode
    `out` - to write bytes to
  Throws:
    `IOException` - if `DataOutput` throws `IOException`

### writeSignedVarInt

    public static void writeSignedVarInt(int value,
                                         DataOutput out)
                                  throws IOException

  Throws:
    `IOException`
  See Also:
    `writeSignedVarLong(long, DataOutput)`

### writeUnsignedVarInt

    public static void writeUnsignedVarInt(int value,
                                           DataOutput out)
                                    throws IOException

  Throws:
    `IOException`
  See Also:
    `writeUnsignedVarLong(long, DataOutput)`

### readSignedVarLong

    public static long readSignedVarLong(DataInput in)
                                  throws IOException

  Parameters:
    `in` - to read bytes from
  Returns:
    decode value
  Throws:
    `IOException` - if `DataInput` throws `IOException`
    `IllegalArgumentException` - if variable-length value does not terminate after 9 bytes have been read
  See Also:
    `writeSignedVarLong(long, DataOutput)`

### readUnsignedVarLong

    public static long readUnsignedVarLong(DataInput in)
                                    throws IOException

  Parameters:
    `in` - to read bytes from
  Returns:
    decode value
  Throws:
    `IOException` - if `DataInput` throws `IOException`
    `IllegalArgumentException` - if variable-length value does not terminate after 9 bytes have been read
  See Also:
    `writeUnsignedVarLong(long, DataOutput)`

### readSignedVarInt

    public static int readSignedVarInt(DataInput in)
                                throws IOException

  Throws:
    `IllegalArgumentException` - if variable-length value does not terminate after 5 bytes have been read
    `IOException` - if `DataInput` throws `IOException`
  See Also:
    `readSignedVarLong(DataInput)`

### readUnsignedVarInt

    public static int readUnsignedVarInt(DataInput in)
                                  throws IOException

  Throws:
    `IllegalArgumentException` - if variable-length value does not terminate after 5 bytes have been read
    `IOException` - if `DataInput` throws `IOException`
  See Also:
    `readUnsignedVarLong(DataInput)`

Copyright © 2008–2014 The Apache Software Foundation. All rights reserved.