org.apache.hadoop.hbase.util.vint
Class UFIntTool

java.lang.Object
  extended by org.apache.hadoop.hbase.util.vint.UFIntTool

@InterfaceAudience.Private
public class UFIntTool
extends Object

UFInt is an abbreviation for Unsigned Fixed-width Integer. This class converts between positive ints and 1-4 bytes that represent the int. All input ints must be positive. Max values stored in N bytes are: N=1: 2^8 => 256 N=2: 2^16 => 65,536 N=3: 2^24 => 16,777,216 N=4: 2^31 => 2,147,483,648 (Integer.MAX_VALUE) This was created to get most of the memory savings of a variable length integer when encoding an array of input integers, but to fix the number of bytes for each integer to the number needed to store the maximum integer in the array. This enables a binary search to be performed on the array of encoded integers. PrefixTree nodes often store offsets into a block that can fit into 1 or 2 bytes. Note that if the maximum value of an array of numbers needs 2 bytes, then it's likely that a majority of the numbers will also require 2 bytes. warnings: * no input validation for max performance * no negatives


Constructor Summary
UFIntTool()
           
 
Method Summary
static long fromBytes(byte[] bytes)
           
static long fromBytes(byte[] bytes, int offset, int width)
           
static byte[] getBytes(int outputWidth, long value)
           
static long maxValueForNumBytes(int numBytes)
           
static int numBytes(long value)
           
static void writeBytes(int outputWidth, long value, byte[] bytes, int offset)
           
static void writeBytes(int outputWidth, long value, OutputStream os)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UFIntTool

public UFIntTool()
Method Detail

maxValueForNumBytes

public static long maxValueForNumBytes(int numBytes)

numBytes

public static int numBytes(long value)

getBytes

public static byte[] getBytes(int outputWidth,
                              long value)

writeBytes

public static void writeBytes(int outputWidth,
                              long value,
                              byte[] bytes,
                              int offset)

writeBytes

public static void writeBytes(int outputWidth,
                              long value,
                              OutputStream os)
                       throws IOException
Throws:
IOException

fromBytes

public static long fromBytes(byte[] bytes)

fromBytes

public static long fromBytes(byte[] bytes,
                             int offset,
                             int width)


Copyright © 2007-2015 The Apache Software Foundation. All Rights Reserved.