Package org.apache.hadoop.io.file.tfile
Class Utils
java.lang.Object
org.apache.hadoop.io.file.tfile.Utils
Supporting Utility classes used by TFile, and shared by users of TFile.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classorg.apache.hadoop.io.file.tfile.Utils.VersionA generic Version class. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> intlowerBound(List<? extends Comparable<? super T>> list, T key) Lower bound binary search.static <T> intlowerBound(List<? extends T> list, T key, Comparator<? super T> cmp) Lower bound binary search.static StringreadString(DataInput in) Read a String as a VInt n, followed by n Bytes in Text format.static intDecoding the variable-length integer.static longDecoding the variable-length integer.static <T> intupperBound(List<? extends Comparable<? super T>> list, T key) Upper bound binary search.static <T> intupperBound(List<? extends T> list, T key, Comparator<? super T> cmp) Upper bound binary search.static voidwriteString(DataOutput out, String s) Write a String as a VInt n, followed by n Bytes as in Text format.static voidwriteVInt(DataOutput out, int n) Encoding an integer into a variable-length encoding format.static voidwriteVLong(DataOutput out, long n) Encoding a Long integer into a variable-length encoding format.
-
Method Details
-
writeVInt
Encoding an integer into a variable-length encoding format. Synonymous toUtils#writeVLong(out, n).- Parameters:
out- output streamn- The integer to be encoded- Throws:
IOException- raised on errors performing I/O.- See Also:
-
writeVLong
Encoding a Long integer into a variable-length encoding format.- if n in [-32, 127): encode in one byte with the actual value. Otherwise,
- if n in [-20*2^8, 20*2^8): encode in two bytes: byte[0] = n/256 - 52; byte[1]=n&0xff. Otherwise,
- if n IN [-16*2^16, 16*2^16): encode in three bytes: byte[0]=n/2^16 - 88; byte[1]=(n>>8)&0xff; byte[2]=n&0xff. Otherwise,
- if n in [-8*2^24, 8*2^24): encode in four bytes: byte[0]=n/2^24 - 112; byte[1] = (n>>16)&0xff; byte[2] = (n>>8)&0xff; byte[3]=n&0xff. Otherwise:
- if n in [-2^31, 2^31): encode in five bytes: byte[0]=-125; byte[1] = (n>>24)&0xff; byte[2]=(n>>16)&0xff; byte[3]=(n>>8)&0xff; byte[4]=n&0xff;
- if n in [-2^39, 2^39): encode in six bytes: byte[0]=-124; byte[1] = (n>>32)&0xff; byte[2]=(n>>24)&0xff; byte[3]=(n>>16)&0xff; byte[4]=(n>>8)&0xff; byte[5]=n&0xff
- if n in [-2^47, 2^47): encode in seven bytes: byte[0]=-123; byte[1] = (n>>40)&0xff; byte[2]=(n>>32)&0xff; byte[3]=(n>>24)&0xff; byte[4]=(n>>16)&0xff; byte[5]=(n>>8)&0xff; byte[6]=n&0xff;
- if n in [-2^55, 2^55): encode in eight bytes: byte[0]=-122; byte[1] = (n>>48)&0xff; byte[2] = (n>>40)&0xff; byte[3]=(n>>32)&0xff; byte[4]=(n>>24)&0xff; byte[5]= (n>>16)&0xff; byte[6]=(n>>8)&0xff; byte[7]=n&0xff;
- if n in [-2^63, 2^63): encode in nine bytes: byte[0]=-121; byte[1] = (n>>54)&0xff; byte[2] = (n>>48)&0xff; byte[3] = (n>>40)&0xff; byte[4]=(n>>32)&0xff; byte[5]=(n>>24)&0xff; byte[6]=(n>>16)&0xff; byte[7]= (n>>8)&0xff; byte[8]=n&0xff;
- Parameters:
out- output streamn- the integer number- Throws:
IOException- raised on errors performing I/O.
-
readVInt
Decoding the variable-length integer. Synonymous to(int)Utils#readVLong(in).- Parameters:
in- input stream- Returns:
- the decoded integer
- Throws:
IOException- raised on errors performing I/O.- See Also:
-
readVLong
Decoding the variable-length integer. Suppose the value of the first byte is FB, and the following bytes are NB[*].- if (FB >= -32), return (long)FB;
- if (FB in [-72, -33]), return (FB+52)<<8 + NB[0]&0xff;
- if (FB in [-104, -73]), return (FB+88)<<16 + (NB[0]&0xff)<<8 + NB[1]&0xff;
- if (FB in [-120, -105]), return (FB+112)<<24 + (NB[0]&0xff) <<16 + (NB[1]&0xff)<<8 + NB[2]&0xff;
- if (FB in [-128, -121]), return interpret NB[FB+129] as a signed big-endian integer.
- Parameters:
in- input stream- Returns:
- the decoded long integer.
- Throws:
IOException- raised on errors performing I/O.
-
writeString
Write a String as a VInt n, followed by n Bytes as in Text format.- Parameters:
out- out.s- s.- Throws:
IOException- raised on errors performing I/O.
-
readString
Read a String as a VInt n, followed by n Bytes in Text format.- Parameters:
in- The input stream.- Returns:
- The string
- Throws:
IOException- raised on errors performing I/O.
-
lowerBound
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 listkey- The input key.cmp- Comparator for the key.- Returns:
- The index to the desired element if it exists; or list.size() otherwise.
-
upperBound
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 listkey- The input key.cmp- Comparator for the key.- Returns:
- The index to the desired element if it exists; or list.size() otherwise.
-
lowerBound
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 listkey- The input key.- Returns:
- The index to the desired element if it exists; or list.size() otherwise.
-
upperBound
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 listkey- The input key.- Returns:
- The index to the desired element if it exists; or list.size() otherwise.
-