| java.lang.Object java.math.MutableBigInteger
All known Subclasses: java.math.SignedMutableBigInteger,
MutableBigInteger | class MutableBigInteger (Code) | | 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.
See Also: BigInteger version: 1.7, 02/02/00 author: Michael McCloskey since: 1.3 |
Field Summary | |
int | intLen The number of ints of the value array that are currently used
to hold the magnitude of this MutableBigInteger. | int | offset The offset into the value array where the magnitude of this
MutableBigInteger begins. | int[] | value Holds the magnitude of this MutableBigInteger in big endian order. |
Constructor Summary | |
| MutableBigInteger() The default constructor. | | MutableBigInteger(int val) Construct a new MutableBigInteger with a magnitude specified by
the int val. | | MutableBigInteger(int[] val, int len) Construct a new MutableBigInteger with the specified value array
up to the specified length. | | MutableBigInteger(int[] val) Construct a new MutableBigInteger with the specified value array
up to the length of the array supplied. | | MutableBigInteger(BigInteger b) Construct a new MutableBigInteger with a magnitude equal to the
specified BigInteger. | | MutableBigInteger(MutableBigInteger val) Construct a new MutableBigInteger with a magnitude equal to the
specified MutableBigInteger. |
Method Summary | |
void | add(MutableBigInteger addend) Adds the contents of two MutableBigInteger objects.The result
is placed within this MutableBigInteger. | static int | binaryGcd(int a, int b) Calculate GCD of a and b interpreted as unsigned integers. | void | clear() Clear out a MutableBigInteger for reuse. | final int | compare(MutableBigInteger b) Compare the magnitude of two MutableBigIntegers. | void | copyValue(MutableBigInteger val) Sets this MutableBigInteger's value array to a copy of the specified
array. | void | copyValue(int[] val) Sets this MutableBigInteger's value array to a copy of the specified
array. | 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. | void | divideOneWord(int divisor, MutableBigInteger quotient) This method is used for division of an n word dividend by a one word
divisor. | MutableBigInteger | euclidModInverse(int k) Uses the extended Euclidean algorithm to compute the modInverse of base
mod a modulus that is a power of 2. | static MutableBigInteger | fixup(MutableBigInteger c, MutableBigInteger p, int k) | MutableBigInteger | hybridGCD(MutableBigInteger b) Calculate GCD of this and b. | static int | inverseMod32(int val) | boolean | isEven() Returns true iff this MutableBigInteger is even. | boolean | isNormal() Returns true iff this MutableBigInteger is in normal form. | boolean | isOdd() Returns true iff this MutableBigInteger is odd. | boolean | isOne() Returns true iff this MutableBigInteger has a value of one. | boolean | isZero() Returns true iff this MutableBigInteger has a value of zero. | void | leftShift(int n) Left shift this MutableBigInteger n bits. | static MutableBigInteger | modInverseBP2(MutableBigInteger mod, int k) | MutableBigInteger | modInverseMP2(int k) | void | mul(int y, MutableBigInteger z) Multiply the contents of this MutableBigInteger by the word y. | void | multiply(MutableBigInteger y, MutableBigInteger z) Multiply the contents of two MutableBigInteger objects. | MutableBigInteger | mutableModInverse(MutableBigInteger p) Returns the modInverse of this mod p. | final 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. | void | reset() Set a MutableBigInteger to zero, removing its offset. | void | rightShift(int n) Right shift this MutableBigInteger n bits. | void | setInt(int index, int val) Sets the int at index+offset in this MutableBigInteger to val. | void | setValue(int[] val, int length) Sets this MutableBigInteger's value array to the specified array. | int | subtract(MutableBigInteger b) Subtracts the smaller of this and b from the larger and places the
result into this MutableBigInteger. | int[] | toIntArray() Convert this MutableBigInteger into an int array with no leading
zeros, of a length that is equal to this MutableBigInteger's intLen. | public String | toString() Returns a String representation of this MutableBigInteger in radix 10. |
intLen | int intLen(Code) | | The number of ints of the value array that are currently used
to hold the magnitude of this MutableBigInteger. The magnitude starts
at an offset and offset + intLen may be less than value.length.
|
offset | int offset(Code) | | The offset into the value array where the magnitude of this
MutableBigInteger begins.
|
value | int[] value(Code) | | Holds the magnitude of this MutableBigInteger in big endian order.
The magnitude may start at an offset into the value array, and it may
end before the length of the value array.
|
MutableBigInteger | MutableBigInteger()(Code) | | The default constructor. An empty MutableBigInteger is created with
a one word capacity.
|
MutableBigInteger | MutableBigInteger(int val)(Code) | | Construct a new MutableBigInteger with a magnitude specified by
the int val.
|
MutableBigInteger | MutableBigInteger(int[] val, int len)(Code) | | Construct a new MutableBigInteger with the specified value array
up to the specified length.
|
MutableBigInteger | MutableBigInteger(int[] val)(Code) | | Construct a new MutableBigInteger with the specified value array
up to the length of the array supplied.
|
MutableBigInteger | MutableBigInteger(BigInteger b)(Code) | | Construct a new MutableBigInteger with a magnitude equal to the
specified BigInteger.
|
MutableBigInteger | MutableBigInteger(MutableBigInteger val)(Code) | | Construct a new MutableBigInteger with a magnitude equal to the
specified MutableBigInteger.
|
add | void add(MutableBigInteger addend)(Code) | | Adds the contents of two MutableBigInteger objects.The result
is placed within this MutableBigInteger.
The contents of the addend are not changed.
|
binaryGcd | static int binaryGcd(int a, int b)(Code) | | Calculate GCD of a and b interpreted as unsigned integers.
|
clear | void clear()(Code) | | Clear out a MutableBigInteger for reuse.
|
compare | final int compare(MutableBigInteger b)(Code) | | Compare the magnitude of two MutableBigIntegers. Returns -1, 0 or 1
as this MutableBigInteger is numerically less than, equal to, or
greater than b.
|
copyValue | void copyValue(MutableBigInteger val)(Code) | | Sets this MutableBigInteger's value array to a copy of the specified
array. The intLen is set to the length of the new array.
|
copyValue | void copyValue(int[] val)(Code) | | Sets this MutableBigInteger's value array to a copy of the specified
array. The intLen is set to the length of the specified array.
|
divide | void divide(MutableBigInteger b, MutableBigInteger quotient, MutableBigInteger rem)(Code) | | Calculates the quotient and remainder of this div b and places them
in the MutableBigInteger objects provided.
Uses Algorithm D in Knuth section 4.3.1.
Many optimizations to that algorithm have been adapted from the Colin
Plumb C library.
It special cases one word divisors for speed.
The contents of a and b are not changed.
|
divideOneWord | void divideOneWord(int divisor, MutableBigInteger quotient)(Code) | | This method is used for division of an n word dividend by a one word
divisor. The quotient is placed into quotient. The one word divisor is
specified by divisor. The value of this MutableBigInteger is the
dividend at invocation but is replaced by the remainder.
NOTE: The value of this MutableBigInteger is modified by this method.
|
euclidModInverse | MutableBigInteger euclidModInverse(int k)(Code) | | Uses the extended Euclidean algorithm to compute the modInverse of base
mod a modulus that is a power of 2. The modulus is 2^k.
|
inverseMod32 | static int inverseMod32(int val)(Code) | | |
isEven | boolean isEven()(Code) | | Returns true iff this MutableBigInteger is even.
|
isNormal | boolean isNormal()(Code) | | Returns true iff this MutableBigInteger is in normal form. A
MutableBigInteger is in normal form if it has no leading zeros
after the offset, and intLen + offset <= value.length.
|
isOdd | boolean isOdd()(Code) | | Returns true iff this MutableBigInteger is odd.
|
isOne | boolean isOne()(Code) | | Returns true iff this MutableBigInteger has a value of one.
|
isZero | boolean isZero()(Code) | | Returns true iff this MutableBigInteger has a value of zero.
|
leftShift | void leftShift(int n)(Code) | | Left shift this MutableBigInteger n bits.
|
mul | void mul(int y, MutableBigInteger z)(Code) | | Multiply the contents of this MutableBigInteger by the word y. The
result is placed into z.
|
multiply | void multiply(MutableBigInteger y, MutableBigInteger z)(Code) | | Multiply the contents of two MutableBigInteger objects. The result is
placed into MutableBigInteger z. The contents of y are not changed.
|
normalize | final void normalize()(Code) | | 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.
|
reset | void reset()(Code) | | Set a MutableBigInteger to zero, removing its offset.
|
rightShift | void rightShift(int n)(Code) | | Right shift this MutableBigInteger n bits. The MutableBigInteger is left
in normal form.
|
setInt | void setInt(int index, int val)(Code) | | Sets the int at index+offset in this MutableBigInteger to val.
This does not get inlined on all platforms so it is not used
as often as originally intended.
|
setValue | void setValue(int[] val, int length)(Code) | | Sets this MutableBigInteger's value array to the specified array.
The intLen is set to the specified length.
|
subtract | int subtract(MutableBigInteger b)(Code) | | Subtracts the smaller of this and b from the larger and places the
result into this MutableBigInteger.
|
toIntArray | int[] toIntArray()(Code) | | Convert this MutableBigInteger into an int array with no leading
zeros, of a length that is equal to this MutableBigInteger's intLen.
|
toString | public String toString()(Code) | | Returns a String representation of this MutableBigInteger in radix 10.
|
|
|