org.apache.hadoop.hive.common.type
Class SignedInt128

java.lang.Object
  extended by java.lang.Number
      extended by org.apache.hadoop.hive.common.type.SignedInt128
All Implemented Interfaces:
Serializable, Comparable<SignedInt128>

public final class SignedInt128
extends Number
implements Comparable<SignedInt128>

This code was originally written for Microsoft PolyBase. Represents a signed 128-bit integer. This object is much faster and more compact than BigInteger, but has many limitations explained in UnsignedInt128. In short, this class is a thin wrapper for UnsignedInt128 to make it signed. This object can be used to represent a few SQL data types, such as DATETIMEOFFSET in SQLServer.

See Also:
Serialized Form

Field Summary
static SignedInt128 MAX_VALUE
          Maximum value that can be represented in this class.
static SignedInt128 MIN_VALUE
          Minimum value that can be represented in this class.
 
Constructor Summary
SignedInt128()
          Empty constructor to construct zero.
SignedInt128(char[] str, int offset, int length)
          Constructs from the given string with given offset and length.
SignedInt128(int v0, int v1, int v2, int v3)
          Construct this object from the given integers.
SignedInt128(long v)
          Construct this object from a long value.
SignedInt128(SignedInt128 o)
          Copy Constructor.
SignedInt128(String str)
          Constructs from the given string.
SignedInt128(UnsignedInt128 mag)
          Construct this object from UnsignedInt128.
 
Method Summary
static void abs(SignedInt128 left, SignedInt128 result)
          This version returns the result as a new object, not modifying the give objects.
 void absDestructive()
          Makes this object positive.
static void add(SignedInt128 left, SignedInt128 right, SignedInt128 result)
          Calculates addition and puts the result into the given object.
 void addDestructive(SignedInt128 right)
          Calculates addition and stores the result into this object.
 int compareTo(SignedInt128 o)
           
static void decrement(SignedInt128 left, SignedInt128 result)
          This version returns the result as a new object, not modifying the give objects.
 void decrementDestructive()
          Subtracts one from this value.
static void divide(SignedInt128 left, SignedInt128 right, SignedInt128 quotient, SignedInt128 remainder)
          Performs division and puts the quotient into the given object.
 int divideDestructive(int right)
          Divides this value with the given value.
 void divideDestructive(SignedInt128 right, SignedInt128 remainder)
          Performs division and puts the quotient into this object.
 double doubleValue()
           
 boolean equals(Object obj)
           
 boolean equals(SignedInt128 o)
          Specialized version.
 float floatValue()
           
static int getIntsPerElement(int precision)
          Determines the number of ints to store one value.
 int getV0()
           
 int getV1()
           
 int getV2()
           
 int getV3()
           
 int hashCode()
           
static void increment(SignedInt128 left, SignedInt128 result)
          This version returns the result as a new object, not modifying the give objects.
 void incrementDestructive()
          Adds one to this value.
 int intValue()
           
 boolean isZero()
           
 long longValue()
           
static void multiply(SignedInt128 left, SignedInt128 right, SignedInt128 result)
          Calculates multiplication and puts the result into the given object.
 void multiplyDestructive(int right)
          Performs multiplication.
 void multiplyDestructive(SignedInt128 right)
          Performs multiplication.
static void negate(SignedInt128 left, SignedInt128 result)
          This version returns the result as a new object, not modifying the give objects.
 void negateDestructive()
          Reverses the sign of this object.
static void scaleDownTen(SignedInt128 left, SignedInt128 result, short tenScale)
          This version returns the result as a new object, not modifying the give objects.
 void scaleDownTenDestructive(short tenScale)
          Scale down the value for 10**tenScale (this := this / 10**tenScale).
static void scaleUpTen(SignedInt128 left, SignedInt128 result, short tenScale)
          This version returns the result as a new object, not modifying the give objects.
 void scaleUpTenDestructive(short tenScale)
          Scale up the value for 10**tenScale (this := this * 10**tenScale).
 void serializeTo128(int[] array, int offset)
          Serializes the value of this object to the given array, putting 128 bits data (full ranges).
 void serializeTo128(IntBuffer buf)
          Serializes the value of this object to ByteBuffer, putting 128 bits data (full ranges).
 void serializeTo32(int[] array, int offset)
          Serializes the value of this object to the given array, putting only 32 bits data.
 void serializeTo32(IntBuffer buf)
          Serializes the value of this object to ByteBuffer, putting only 32 bits data.
 void serializeTo64(int[] array, int offset)
          Serializes the value of this object to the given array, putting only 64 bits data.
 void serializeTo64(IntBuffer buf)
          Serializes the value of this object to ByteBuffer, putting only 64 bits data.
 void serializeTo96(int[] array, int offset)
          Serializes the value of this object to the given array, putting only 96 bits data.
 void serializeTo96(IntBuffer buf)
          Serializes the value of this object to ByteBuffer, putting only 96 bits data.
static void shiftLeft(SignedInt128 left, SignedInt128 result, int bits)
          This version returns the result as a new object, not modifying the give objects.
 void shiftLeftDestructive(int bits)
          Left-shift for the given number of bits.
static void shiftRight(SignedInt128 left, SignedInt128 result, int bits, boolean roundUp)
          This version returns the result as a new object, not modifying the give objects.
 void shiftRightDestructive(int bits, boolean roundUp)
          Right-shift for the given number of bits.
static void subtract(SignedInt128 left, SignedInt128 right, SignedInt128 result)
          Calculates subtraction and puts the result into the given object.
 void subtractDestructive(SignedInt128 right)
          Calculates subtraction and stores the result into this object.
 BigInteger toBigIntegerSlow()
          Convert this object to BigInteger.
 String toFormalString()
          Returns the formal string representation of this value.
 String toString()
           
 void update(char[] str, int offset, int length)
          Updates the value of this object from the given string with given offset and length.
 void update(long v)
          Update this object with the given long value.
 void update(SignedInt128 o)
          Update this object with the value of the given object.
 void update(String str)
          Updates the value of this object with the given string.
 void update128(int[] array, int offset)
          Updates the value of this object by reading from the given array, receiving 128 bits data (full ranges).
 void update128(IntBuffer buf)
          Updates the value of this object by reading from ByteBuffer, receiving 128 bits data (full ranges).
 void update128(int v0, int v1, int v2, int v3)
          Update this object with the given integers, receiving 128 bits data (full ranges).
 void update32(int v0)
          Update this object with the given integers, receiving only 32 bits data.
 void update32(int[] array, int offset)
          Updates the value of this object by reading from the given array, receiving only 32 bits data.
 void update32(IntBuffer buf)
          Updates the value of this object by reading from ByteBuffer, receiving only 32 bits data.
 void update64(int[] array, int offset)
          Updates the value of this object by reading from the given array, receiving only 64 bits data.
 void update64(IntBuffer buf)
          Updates the value of this object by reading from ByteBuffer, receiving only 64 bits data.
 void update64(int v0, int v1)
          Update this object with the given integers, receiving only 64 bits data.
 void update96(int[] array, int offset)
          Updates the value of this object by reading from the given array, receiving only 96 bits data.
 void update96(IntBuffer buf)
          Updates the value of this object by reading from ByteBuffer, receiving only 96 bits data.
 void update96(int v0, int v1, int v2)
          Update this object with the given integers, receiving only 96 bits data.
 void zeroClear()
          Make the value to zero.
 
Methods inherited from class java.lang.Number
byteValue, shortValue
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_VALUE

public static final SignedInt128 MAX_VALUE
Maximum value that can be represented in this class.


MIN_VALUE

public static final SignedInt128 MIN_VALUE
Minimum value that can be represented in this class.

Constructor Detail

SignedInt128

public SignedInt128()
Empty constructor to construct zero.


SignedInt128

public SignedInt128(long v)
Construct this object from a long value.

Parameters:
v - long value

SignedInt128

public SignedInt128(UnsignedInt128 mag)
Construct this object from UnsignedInt128. The highest bit of the UnsignedInt128 is converted as the sign bit just like conversion between int/uint in C++.

Parameters:
mag - UnsignedInt128 object

SignedInt128

public SignedInt128(SignedInt128 o)
Copy Constructor.

Parameters:
o - object to copy from

SignedInt128

public SignedInt128(int v0,
                    int v1,
                    int v2,
                    int v3)
Construct this object from the given integers. The highest bit of v3 is converted as the sign bit just like conversion between int/uint in C++.

Parameters:
v0 - v0
v1 - v1
v2 - v2
v3 - v3

SignedInt128

public SignedInt128(String str)
Constructs from the given string.

Parameters:
str - string

SignedInt128

public SignedInt128(char[] str,
                    int offset,
                    int length)
Constructs from the given string with given offset and length.

Parameters:
str - string
offset - offset
length - length
Method Detail

getIntsPerElement

public static int getIntsPerElement(int precision)
Determines the number of ints to store one value.

Parameters:
precision - precision (0-38)
Returns:
the number of ints to store one value

getV0

public int getV0()
Returns:
v[0]

getV1

public int getV1()
Returns:
v[1]

getV2

public int getV2()
Returns:
v[2]

getV3

public int getV3()
Returns:
v[3]

zeroClear

public void zeroClear()
Make the value to zero.


update

public void update(long v)
Update this object with the given long value.

Parameters:
v - long value

update

public void update(SignedInt128 o)
Update this object with the value of the given object.

Parameters:
o - object to copy from

update

public void update(String str)
Updates the value of this object with the given string.

Parameters:
str - string

update

public void update(char[] str,
                   int offset,
                   int length)
Updates the value of this object from the given string with given offset and length.

Parameters:
str - string
offset - offset
length - length

update128

public void update128(int v0,
                      int v1,
                      int v2,
                      int v3)
Update this object with the given integers, receiving 128 bits data (full ranges).

Parameters:
v0 - v0
v1 - v1
v2 - v2
v3 - v3

update96

public void update96(int v0,
                     int v1,
                     int v2)
Update this object with the given integers, receiving only 96 bits data.

Parameters:
v0 - v0
v1 - v1
v2 - v2

update64

public void update64(int v0,
                     int v1)
Update this object with the given integers, receiving only 64 bits data.

Parameters:
v0 - v0
v1 - v1

update32

public void update32(int v0)
Update this object with the given integers, receiving only 32 bits data.

Parameters:
v0 - v0

update128

public void update128(int[] array,
                      int offset)
Updates the value of this object by reading from the given array, receiving 128 bits data (full ranges).

Parameters:
array - array to read values from
offset - offset of the int array

update96

public void update96(int[] array,
                     int offset)
Updates the value of this object by reading from the given array, receiving only 96 bits data.

Parameters:
array - array to read values from
offset - offset of the int array

update64

public void update64(int[] array,
                     int offset)
Updates the value of this object by reading from the given array, receiving only 64 bits data.

Parameters:
array - array to read values from
offset - offset of the int array

update32

public void update32(int[] array,
                     int offset)
Updates the value of this object by reading from the given array, receiving only 32 bits data.

Parameters:
array - array to read values from
offset - offset of the int array

update128

public void update128(IntBuffer buf)
Updates the value of this object by reading from ByteBuffer, receiving 128 bits data (full ranges).

Parameters:
buf - ByteBuffer to read values from

update96

public void update96(IntBuffer buf)
Updates the value of this object by reading from ByteBuffer, receiving only 96 bits data.

Parameters:
buf - ByteBuffer to read values from

update64

public void update64(IntBuffer buf)
Updates the value of this object by reading from ByteBuffer, receiving only 64 bits data.

Parameters:
buf - ByteBuffer to read values from

update32

public void update32(IntBuffer buf)
Updates the value of this object by reading from ByteBuffer, receiving only 32 bits data.

Parameters:
buf - ByteBuffer to read values from

serializeTo128

public void serializeTo128(int[] array,
                           int offset)
Serializes the value of this object to the given array, putting 128 bits data (full ranges).

Parameters:
array - array to use
offset - offset of the int array

serializeTo96

public void serializeTo96(int[] array,
                          int offset)
Serializes the value of this object to the given array, putting only 96 bits data.

Parameters:
array - array to use
offset - offset of the int array

serializeTo64

public void serializeTo64(int[] array,
                          int offset)
Serializes the value of this object to the given array, putting only 64 bits data.

Parameters:
array - array to use
offset - offset of the int array

serializeTo32

public void serializeTo32(int[] array,
                          int offset)
Serializes the value of this object to the given array, putting only 32 bits data.

Parameters:
array - array to use
offset - offset of the int array

serializeTo128

public void serializeTo128(IntBuffer buf)
Serializes the value of this object to ByteBuffer, putting 128 bits data (full ranges).

Parameters:
buf - ByteBuffer to use

serializeTo96

public void serializeTo96(IntBuffer buf)
Serializes the value of this object to ByteBuffer, putting only 96 bits data.

Parameters:
buf - ByteBuffer to use

serializeTo64

public void serializeTo64(IntBuffer buf)
Serializes the value of this object to ByteBuffer, putting only 64 bits data.

Parameters:
buf - ByteBuffer to use

serializeTo32

public void serializeTo32(IntBuffer buf)
Serializes the value of this object to ByteBuffer, putting only 32 bits data.

Parameters:
buf - ByteBuffer to use

isZero

public boolean isZero()
Returns:
Whether this object represents zero.

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

equals

public boolean equals(SignedInt128 o)
Specialized version.

Parameters:
o - the object to compare
Returns:
whether the object is equal to this object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

compareTo

public int compareTo(SignedInt128 o)
Specified by:
compareTo in interface Comparable<SignedInt128>

intValue

public int intValue()
Specified by:
intValue in class Number

longValue

public long longValue()
Specified by:
longValue in class Number

floatValue

public float floatValue()
Specified by:
floatValue in class Number

doubleValue

public double doubleValue()
Specified by:
doubleValue in class Number

add

public static void add(SignedInt128 left,
                       SignedInt128 right,
                       SignedInt128 result)
Calculates addition and puts the result into the given object. This method is static and not destructive (except the result object).

Parameters:
left - left operand
right - right operand
result - object to receive the calculation result

addDestructive

public void addDestructive(SignedInt128 right)
Calculates addition and stores the result into this object. This method is destructive.

Parameters:
right - right operand

subtract

public static void subtract(SignedInt128 left,
                            SignedInt128 right,
                            SignedInt128 result)
Calculates subtraction and puts the result into the given object. This method is static and not destructive (except the result object).

Parameters:
left - left operand
right - right operand
result - object to receive the calculation result

subtractDestructive

public void subtractDestructive(SignedInt128 right)
Calculates subtraction and stores the result into this object. This method is destructive.

Parameters:
right - right operand

multiply

public static void multiply(SignedInt128 left,
                            SignedInt128 right,
                            SignedInt128 result)
Calculates multiplication and puts the result into the given object. This method is static and not destructive (except the result object).

Parameters:
left - left operand
right - right operand
result - object to receive the calculation result

multiplyDestructive

public void multiplyDestructive(SignedInt128 right)
Performs multiplication.

Parameters:
right - right operand. this object is not modified.

multiplyDestructive

public void multiplyDestructive(int right)
Performs multiplication.

Parameters:
right - right operand.

divideDestructive

public int divideDestructive(int right)
Divides this value with the given value. This version is destructive, meaning it modifies this object.

Parameters:
right - the value to divide
Returns:
remainder

divide

public static void divide(SignedInt128 left,
                          SignedInt128 right,
                          SignedInt128 quotient,
                          SignedInt128 remainder)
Performs division and puts the quotient into the given object. This method is static and not destructive (except the result object).

Parameters:
left - left operand
right - right operand
quotient - result object to receive the calculation result
remainder - result object to receive the calculation result

divideDestructive

public void divideDestructive(SignedInt128 right,
                              SignedInt128 remainder)
Performs division and puts the quotient into this object.

Parameters:
right - right operand. this object is not modified.
remainder - result object to receive the calculation result

negateDestructive

public void negateDestructive()
Reverses the sign of this object. This method is destructive.


absDestructive

public void absDestructive()
Makes this object positive. This method is destructive.


negate

public static void negate(SignedInt128 left,
                          SignedInt128 result)
This version returns the result as a new object, not modifying the give objects.

Parameters:
left - left operand
result - object to receive the calculation result

abs

public static void abs(SignedInt128 left,
                       SignedInt128 result)
This version returns the result as a new object, not modifying the give objects.

Parameters:
left - left operand
result - object to receive the calculation result

incrementDestructive

public void incrementDestructive()
Adds one to this value. This version is destructive, meaning it modifies this object.


decrementDestructive

public void decrementDestructive()
Subtracts one from this value. This version is destructive, meaning it modifies this object.


increment

public static void increment(SignedInt128 left,
                             SignedInt128 result)
This version returns the result as a new object, not modifying the give objects.

Parameters:
left - left operand
result - object to receive the calculation result

decrement

public static void decrement(SignedInt128 left,
                             SignedInt128 result)
This version returns the result as a new object, not modifying the give objects.

Parameters:
left - left operand
result - object to receive the calculation result

shiftRightDestructive

public void shiftRightDestructive(int bits,
                                  boolean roundUp)
Right-shift for the given number of bits. This bit-shift is equivalent to Java's signed bit shift ">>". This version is destructive, meaning it modifies this object. NOTE: So far we don't provide an equivalent of the unsigned right bit shift ">>>" because we recommend to simply use UnsignedInt128 for unsigned use.

Parameters:
bits - the number of bits. must be positive
roundUp - whether to round up the most significant bit that was discarded

shiftLeftDestructive

public void shiftLeftDestructive(int bits)
Left-shift for the given number of bits. This bit-shift is equivalent to Java's signed bit shift "<<". This method does not throw an error even if overflow happens. This version is destructive, meaning it modifies this object.

Parameters:
bits - the number of bits. must be positive

scaleDownTenDestructive

public void scaleDownTenDestructive(short tenScale)
Scale down the value for 10**tenScale (this := this / 10**tenScale). This method rounds-up, eg 44/10=4, 45/10=5. This version is destructive, meaning it modifies this object.

Parameters:
tenScale - scaling. must be positive

scaleUpTenDestructive

public void scaleUpTenDestructive(short tenScale)
Scale up the value for 10**tenScale (this := this * 10**tenScale). Scaling up DOES throw an error when an overflow occurs. For example, 42.scaleUp(1) = 420, 42.scaleUp(40) = ArithmeticException. This version is destructive, meaning it modifies this object.

Parameters:
tenScale - scaling. must be positive

shiftRight

public static void shiftRight(SignedInt128 left,
                              SignedInt128 result,
                              int bits,
                              boolean roundUp)
This version returns the result as a new object, not modifying the give objects.

Parameters:
left - left operand
result - object to receive the calculation result
bits - the number of bits. must be positive
roundUp - whether to round up the most significant bit that was discarded

shiftLeft

public static void shiftLeft(SignedInt128 left,
                             SignedInt128 result,
                             int bits)
This version returns the result as a new object, not modifying the give objects.

Parameters:
left - left operand
result - object to receive the calculation result
bits - the number of bits. must be positive

scaleDownTen

public static void scaleDownTen(SignedInt128 left,
                                SignedInt128 result,
                                short tenScale)
This version returns the result as a new object, not modifying the give objects.

Parameters:
left - left operand
result - object to receive the calculation result
tenScale - scaling. must be positive

scaleUpTen

public static void scaleUpTen(SignedInt128 left,
                              SignedInt128 result,
                              short tenScale)
This version returns the result as a new object, not modifying the give objects.

Parameters:
left - left operand
result - object to receive the calculation result
tenScale - scaling. must be positive

toBigIntegerSlow

public BigInteger toBigIntegerSlow()
Convert this object to BigInteger. Do not use this method in a performance sensitive place.

Returns:
BigInteger to represent this object

toFormalString

public String toFormalString()
Returns the formal string representation of this value. Unlike the debug string returned by toString(), this method returns a string that can be used to re-construct this object. Remember, toString() is only for debugging.

Returns:
string representation of this value

toString

public String toString()
Overrides:
toString in class Object


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