|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.math.MutableBigInteger
A class used to represent multiprecision integers that makes efficient use of allocated space by allowing a number to occupy only part of an array so that the arrays do not have to be reallocated as often. When performing an operation with many iterations the array used to hold a number is only reallocated when necessary and does not have to be the same size as the number it represents. A mutable number allows calculations to occur on the same number without having to create a new number for every step of the calculation as occurs with BigIntegers.
BigInteger
Field Summary | |
(package private) int |
intLen
The number of ints of the value array that are currently used to hold the magnitude of this MutableBigInteger. |
private static long |
LONG_MASK
This mask is used to obtain the value of an int as if it were unsigned. |
(package private) int |
offset
The offset into the value array where the magnitude of this MutableBigInteger begins. |
(package private) int[] |
value
Holds the magnitude of this MutableBigInteger in big endian order. |
Constructor Summary | |
(package private) |
MutableBigInteger()
The default constructor. |
(package private) |
MutableBigInteger(BigInteger b)
Construct a new MutableBigInteger with a magnitude equal to the specified BigInteger. |
(package private) |
MutableBigInteger(int val)
Construct a new MutableBigInteger with a magnitude specified by the int val. |
(package private) |
MutableBigInteger(int[] val)
Construct a new MutableBigInteger with the specified value array up to the length of the array supplied. |
(package private) |
MutableBigInteger(int[] val,
int len)
Construct a new MutableBigInteger with the specified value array up to the specified length. |
(package private) |
MutableBigInteger(MutableBigInteger val)
Construct a new MutableBigInteger with a magnitude equal to the specified MutableBigInteger. |
Method Summary | |
(package private) void |
add(MutableBigInteger addend)
Adds the contents of two MutableBigInteger objects.The result is placed within this MutableBigInteger. |
(package private) static int |
binaryGcd(int a,
int b)
Calculate GCD of a and b interpreted as unsigned integers. |
private MutableBigInteger |
binaryGCD(MutableBigInteger v)
Calculate GCD of this and v. |
(package private) void |
clear()
Clear out a MutableBigInteger for reuse. |
(package private) int |
compare(MutableBigInteger b)
Compare the magnitude of two MutableBigIntegers. |
(package private) void |
copyValue(int[] val)
Sets this MutableBigInteger's value array to a copy of the specified array. |
(package private) void |
copyValue(MutableBigInteger val)
Sets this MutableBigInteger's value array to a copy of the specified array. |
private int |
difference(MutableBigInteger b)
Subtracts the smaller of a and b from the larger and places the result into the larger. |
private int |
divadd(int[] a,
int[] result,
int offset)
A primitive used for division. |
(package private) void |
divide(MutableBigInteger b,
MutableBigInteger quotient,
MutableBigInteger rem)
Calculates the quotient and remainder of this div b and places them in the MutableBigInteger objects provided. |
(package private) void |
divideOneWord(int divisor,
MutableBigInteger quotient)
This method is used for division of an n word dividend by a one word divisor. |
private void |
divWord(int[] result,
long n,
int d)
This method divides a long quantity by an int to estimate qhat for two multi precision numbers. |
private void |
ensureCapacity(int len)
If this MutableBigInteger cannot hold len words, increase the size of the value array to len words. |
(package private) MutableBigInteger |
euclidModInverse(int k)
Uses the extended Euclidean algorithm to compute the modInverse of base mod a modulus that is a power of 2. |
(package private) static MutableBigInteger |
fixup(MutableBigInteger c,
MutableBigInteger p,
int k)
|
private int |
getInt(int index)
Return the int in use in this MutableBigInteger at the specified index. |
private long |
getLong(int index)
Return a long which is equal to the unsigned value of the int in use in this MutableBigInteger at the specified index. |
private int |
getLowestSetBit()
Return the index of the lowest set bit in this MutableBigInteger. |
(package private) MutableBigInteger |
hybridGCD(MutableBigInteger b)
Calculate GCD of this and b. |
(package private) static int |
inverseMod32(int val)
|
(package private) boolean |
isEven()
Returns true iff this MutableBigInteger is even. |
(package private) boolean |
isNormal()
Returns true iff this MutableBigInteger is in normal form. |
(package private) boolean |
isOdd()
Returns true iff this MutableBigInteger is odd. |
(package private) boolean |
isOne()
Returns true iff this MutableBigInteger has a value of one. |
(package private) boolean |
isZero()
Returns true iff this MutableBigInteger has a value of zero. |
(package private) void |
leftShift(int n)
Left shift this MutableBigInteger n bits. |
private MutableBigInteger |
modInverse(MutableBigInteger mod)
Calculate the multiplicative inverse of this mod mod, where mod is odd. |
(package private) static MutableBigInteger |
modInverseBP2(MutableBigInteger mod,
int k)
|
(package private) MutableBigInteger |
modInverseMP2(int k)
|
(package private) void |
mul(int y,
MutableBigInteger z)
Multiply the contents of this MutableBigInteger by the word y. |
private int |
mulsub(int[] q,
int[] a,
int x,
int len,
int offset)
This method is used for division. |
(package private) void |
multiply(MutableBigInteger y,
MutableBigInteger z)
Multiply the contents of two MutableBigInteger objects. |
(package private) MutableBigInteger |
mutableModInverse(MutableBigInteger p)
Returns the modInverse of this mod p. |
(package private) void |
normalize()
Ensure that the MutableBigInteger is in normal form, specifically making sure that there are no leading zeros, and that if the magnitude is zero, then intLen is zero. |
private void |
primitiveLeftShift(int n)
Left shift this MutableBigInteger n bits, where n is less than 32. |
private void |
primitiveRightShift(int n)
Right shift this MutableBigInteger n bits, where n is less than 32. |
(package private) void |
reset()
Set a MutableBigInteger to zero, removing its offset. |
(package private) void |
rightShift(int n)
Right shift this MutableBigInteger n bits. |
(package private) void |
setInt(int index,
int val)
Sets the int at index+offset in this MutableBigInteger to val. |
(package private) void |
setValue(int[] val,
int length)
Sets this MutableBigInteger's value array to the specified array. |
(package private) int |
subtract(MutableBigInteger b)
Subtracts the smaller of this and b from the larger and places the result into this MutableBigInteger. |
(package private) int[] |
toIntArray()
Convert this MutableBigInteger into an int array with no leading zeros, of a length that is equal to this MutableBigInteger's intLen. |
String |
toString()
Returns a String representation of this MutableBigInteger in radix 10. |
private boolean |
unsignedLongCompare(long one,
long two)
Compare two longs as if they were unsigned. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
int[] value
int intLen
int offset
private static final long LONG_MASK
Constructor Detail |
MutableBigInteger()
MutableBigInteger(int val)
MutableBigInteger(int[] val, int len)
MutableBigInteger(int[] val)
MutableBigInteger(BigInteger b)
MutableBigInteger(MutableBigInteger val)
Method Detail |
void clear()
void reset()
final int compare(MutableBigInteger b)
private final int getLowestSetBit()
private final int getInt(int index)
private final long getLong(int index)
final void normalize()
private final void ensureCapacity(int len)
int[] toIntArray()
void setInt(int index, int val)
void setValue(int[] val, int length)
void copyValue(MutableBigInteger val)
void copyValue(int[] val)
boolean isOne()
boolean isZero()
boolean isEven()
boolean isOdd()
boolean isNormal()
public String toString()
toString
in class Object
void rightShift(int n)
void leftShift(int n)
private int divadd(int[] a, int[] result, int offset)
private int mulsub(int[] q, int[] a, int x, int len, int offset)
private final void primitiveRightShift(int n)
private final void primitiveLeftShift(int n)
void add(MutableBigInteger addend)
int subtract(MutableBigInteger b)
private int difference(MutableBigInteger b)
void multiply(MutableBigInteger y, MutableBigInteger z)
void mul(int y, MutableBigInteger z)
void divideOneWord(int divisor, MutableBigInteger quotient)
void divide(MutableBigInteger b, MutableBigInteger quotient, MutableBigInteger rem)
private boolean unsignedLongCompare(long one, long two)
private void divWord(int[] result, long n, int d)
MutableBigInteger hybridGCD(MutableBigInteger b)
private MutableBigInteger binaryGCD(MutableBigInteger v)
static int binaryGcd(int a, int b)
MutableBigInteger mutableModInverse(MutableBigInteger p)
MutableBigInteger modInverseMP2(int k)
static int inverseMod32(int val)
static MutableBigInteger modInverseBP2(MutableBigInteger mod, int k)
private MutableBigInteger modInverse(MutableBigInteger mod)
static MutableBigInteger fixup(MutableBigInteger c, MutableBigInteger p, int k)
MutableBigInteger euclidModInverse(int k)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |