org.apache.hadoop.io.file.tfile
Class Utils

java.lang.Object
  extended by org.apache.hadoop.io.file.tfile.Utils

public final class Utils
extends Object

Supporting Utility classes used by TFile, and shared by users of TFile.


Nested Class Summary
static class Utils.Version
          A generic Version class.
 
Method Summary
static
<T> int
lowerBound(List<? extends Comparable<? super T>> list, T key)
          Lower bound binary search.
static
<T> int
lowerBound(List<? extends T> list, T key, Comparator<? super T> cmp)
          Lower bound binary search.
static String readString(DataInput in)
          Read a String as a VInt n, followed by n Bytes in Text format.
static int readVInt(DataInput in)
          Decoding the variable-length integer.
static long readVLong(DataInput in)
          Decoding the variable-length integer.
static
<T> int
upperBound(List<? extends Comparable<? super T>> list, T key)
          Upper bound binary search.
static
<T> int
upperBound(List<? extends T> list, T key, Comparator<? super T> cmp)
          Upper bound binary search.
static void writeString(DataOutput out, String s)
          Write a String as a VInt n, followed by n Bytes as in Text format.
static void writeVInt(DataOutput out, int n)
          Encoding an integer into a variable-length encoding format.
static void writeVLong(DataOutput out, long n)
          Encoding a Long integer into a variable-length encoding format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

writeVInt

public static void writeVInt(DataOutput out,
                             int n)
                      throws IOException
Encoding an integer into a variable-length encoding format. Synonymous to Utils#writeVLong(out, n).

Parameters:
out - output stream
n - The integer to be encoded
Throws:
IOException
See Also:
writeVLong(DataOutput, long)

writeVLong

public static void writeVLong(DataOutput out,
                              long n)
                       throws IOException
Encoding a Long integer into a variable-length encoding format.

Parameters:
out - output stream
n - the integer number
Throws:
IOException

readVInt

public static int readVInt(DataInput in)
                    throws IOException
Decoding the variable-length integer. Synonymous to (int)Utils#readVLong(in).

Parameters:
in - input stream
Returns:
the decoded integer
Throws:
IOException
See Also:
readVLong(DataInput)

readVLong

public static long readVLong(DataInput in)
                      throws IOException
Decoding the variable-length integer. Suppose the value of the first byte is FB, and the following bytes are NB[*].

writeString

public static void writeString(DataOutput out,
                               String s)
                        throws IOException
Write a String as a VInt n, followed by n Bytes as in Text format.

Parameters:
out -
s -
Throws:
IOException

readString

public static String readString(DataInput in)
                         throws IOException
Read a String as a VInt n, followed by n Bytes in Text format.

Parameters:
in - The input stream.
Returns:
The string
Throws:
IOException

lowerBound

public static <T> int lowerBound(List<? extends T> list,
                                 T key,
                                 Comparator<? super T> cmp)
Lower bound binary search. Find the index to the first element in the list that compares greater than or equal to key.

Type Parameters:
T - Type of the input key.
Parameters:
list - The list
key - The input key.
cmp - Comparator for the key.
Returns:
The index to the desired element if it exists; or list.size() otherwise.

upperBound

public static <T> int upperBound(List<? extends T> list,
                                 T key,
                                 Comparator<? super T> cmp)
Upper bound binary search. Find the index to the first element in the list that compares greater than the input key.

Type Parameters:
T - Type of the input key.
Parameters:
list - The list
key - The input key.
cmp - Comparator for the key.
Returns:
The index to the desired element if it exists; or list.size() otherwise.

lowerBound

public static <T> int lowerBound(List<? extends Comparable<? super T>> list,
                                 T key)
Lower bound binary search. Find the index to the first element in the list that compares greater than or equal to key.

Type Parameters:
T - Type of the input key.
Parameters:
list - The list
key - The input key.
Returns:
The index to the desired element if it exists; or list.size() otherwise.

upperBound

public static <T> int upperBound(List<? extends Comparable<? super T>> list,
                                 T key)
Upper bound binary search. Find the index to the first element in the list that compares greater than the input key.

Type Parameters:
T - Type of the input key.
Parameters:
list - The list
key - The input key.
Returns:
The index to the desired element if it exists; or list.size() otherwise.


Copyright © 2009 The Apache Software Foundation