net.sf.ivmaidns.util
Class IntVector

java.lang.Object
  extended by net.sf.ivmaidns.util.IntVector
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Indexable, ReallyCloneable, Sortable, Verifiable

public final class IntVector
extends java.lang.Object
implements ReallyCloneable, java.io.Serializable, Indexable, Sortable, Verifiable

Class for 'int' array wrappers. This class wraps a primitive int-type array, and has the possibility to resize (when required) the wrapped array. This class supports cloning, serialization and comparison of its instances. In addition, the class contains static methods for int arrays resizing, filling in, reversing, vector arithmetics (addition, subtraction, multiplication by a value, scalar multiplication, polynome evaluation), elements summing and non-zero elements counting, linear/binary searching in for a value or sequence, mismatches counting, signed/unsigned 'less-equal-greater' comparison, sorting, and 'to-string' conversion. The class may be also used to store and operate on bits packed into int arrays (each int element contains JavaConsts INT_SIZE bits, where the packed bits are numbered starting from either the least (typically) or the most significant bit of int); the supplementary bit-oriented static methods here are for boolean vector arithmetics (logical and, or, exclusive or, inversion).

Version:
2.0
Author:
Ivan Maidanski
See Also:
ByteVector, CharVector, DoubleVector, FloatVector, LongVector, ShortVector, BooleanVector, ObjectVector, UnsignedInt, Serialized Form

Field Summary
protected  int[] array
          The wrapped (encapsulated) custom int array.
protected static int[] EMPTY
          A constant initialized with an instance of empty int array.
 
Constructor Summary
IntVector()
          Constructs an empty int vector.
IntVector(int size)
          Constructs a new int vector of the specified length.
IntVector(int[] array)
          Constructs a new int array wrapper.
 
Method Summary
static void addTo(int[] arrayA, int[] arrayB)
          Adds a given vector (array) to another one.
static void and(int[] arrayA, int[] arrayB)
          Performs logical 'and' operation on two given arrays.
static void andNot(int[] arrayA, int[] arrayB)
          Performs logical 'and not' operation on two given arrays.
 int[] array()
          Returns array wrapped by this vector.
static int binarySearch(int[] array, int offset, int len, int value, boolean isUnsigned)
          Searches (fast) for value in a given sorted array.
 java.lang.Object clone()
          Creates and returns a copy of this object.
static int compare(int[] arrayA, int offsetA, int lenA, int[] arrayB, int offsetB, int lenB, boolean isUnsigned)
          Compares two given array regions.
 void copyAt(int srcOffset, int destOffset, int len)
          Copies a region of values at one offset to another offset in this vector.
static int countNonZero(int[] array)
          Count non-zero elements in a given array.
 void ensureSize(int size)
          Ensures the size (capacity) of this vector.
static int[] ensureSize(int[] array, int size)
          Ensures the length (capacity) of a given array.
static boolean equals(int[] arrayA, int[] arrayB)
          Tests whether or not the specified two arrays are equal.
 boolean equals(java.lang.Object obj)
          Indicates whether this object is equal to the specified one.
static void fill(int[] array, int offset, int len, int value)
          Fills in the region of a given array with the specified value.
 java.lang.Object getAt(int index)
          Returns the wrapped value of the element at the specified index.
 int getIntAt(int index)
          Returns value of the element at the specified index.
 boolean greaterThan(java.lang.Object obj)
          Tests for being semantically greater than the argument.
 int hashCode()
          Computes and returns a hash code value for the object.
static int hashCode(int[] array)
          Produces a hash code value for a given array.
static int indexOf(int[] subArray, int offset, int len, int index, int[] array)
          Searches forward for the specified sequence in a given array.
static int indexOf(int value, int index, int[] array)
          Searches forward for value in a given array.
 void integrityCheck()
          Verifies this object for its integrity.
static void invert(int[] array)
          Performs logical 'not' operation on a given array.
static int lastIndexOf(int[] subArray, int offset, int len, int index, int[] array)
          Searches backward for the specified sequence in a given array.
static int lastIndexOf(int value, int index, int[] array)
          Searches backward for value in a given array.
 int length()
          Returns the number of elements in this vector.
static long longPolynome(long longValue, int[] array, boolean isUnsigned)
          Computes the result of substitution of a given long value into the polynome specified by its coefficients.
static long longScalarMul(int[] arrayA, int[] arrayB, boolean isUnsigned)
          Multiplies two given vectors (arrays) in a scalar way treating their elements as long values.
static long longSumOf(int[] array, int offset, int len, boolean isUnsigned)
          Sums the elements in the region of a given array as long values.
static int mismatches(int[] arrayA, int offsetA, int[] arrayB, int offsetB, int len)
          Count the mismatches of two given array regions.
static void multiplyBy(int[] array, int value)
          Multiplies a given vector (array) by a value.
static void or(int[] arrayA, int[] arrayB)
          Performs logical 'or' operation on two given arrays.
static void orNot(int[] arrayA, int[] arrayB)
          Performs logical 'or not' operation on two given arrays.
static int polynome(int value, int[] array)
          Computes the result of substitution of a given value into the polynome specified by its coefficients.
static void quickSort(int[] array, int offset, int len, boolean isUnsigned)
          Sorts the elements in the region of a given array using 'Quick' algorithm.
 void resize(int size)
          Resizes this vector.
static int[] resize(int[] array, int size)
          Resizes a given array.
static void reverse(int[] array)
          Reverses the elements order in a given array.
static int scalarMul(int[] arrayA, int[] arrayB)
          Multiplies two given vectors (arrays) in a scalar way.
 void setArray(int[] array)
          Sets another array to be wrapped by this vector.
 void setAt(int index, int value)
          Assigns a new value to the element at the specified index.
static void subtractFrom(int[] arrayA, int[] arrayB)
          Subtracts a given vector (array) from another one.
static int sumOf(int[] array, int offset, int len)
          Sums the elements in the region of a given array.
 java.lang.String toString()
          Converts this vector to its 'in-line' string representation.
static java.lang.String toString(int[] array, int offset, int len, char separator, boolean isUnsigned)
          Converts the region of a given array to its 'in-line' string representation.
static void xor(int[] arrayA, int[] arrayB)
          Performs logical 'exclusive or' operation on two given arrays.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY

protected static final int[] EMPTY
A constant initialized with an instance of empty int array.

See Also:
array

array

protected int[] array
The wrapped (encapsulated) custom int array. array must be non-null.

See Also:
EMPTY, IntVector(), IntVector(int), IntVector(int[]), setArray(int[]), array(), length(), resize(int), ensureSize(int), setAt(int, int), getIntAt(int), copyAt(int, int, int), clone(), integrityCheck()
Constructor Detail

IntVector

public IntVector()
Constructs an empty int vector. This constructor is used for the creation of a resizable vector. The length of such a vector is changed only by resize(int) and ensureSize(int) methods.

See Also:
IntVector(int), IntVector(int[]), array(), length(), resize(int), ensureSize(int), setAt(int, int), getIntAt(int), copyAt(int, int, int), clone(), toString()

IntVector

public IntVector(int size)
Constructs a new int vector of the specified length. This constructor is typically used for the creation of a vector with a fixed size. All elements of the created vector are set to zero.

Parameters:
size - the initial length (unsigned) of the vector to be created.
Throws:
java.lang.OutOfMemoryError - if there is not enough memory.
See Also:
IntVector(), IntVector(int[]), array(), length(), setAt(int, int), getIntAt(int), copyAt(int, int, int), fill(int[], int, int, int), clone(), toString()

IntVector

public IntVector(int[] array)
          throws java.lang.NullPointerException
Constructs a new int array wrapper. This constructor is used for the creation of a vector which wraps the specified array (without copying it). The wrapped array may be further replaced with another one only by setArray(int[]) and by resize(int), ensureSize(int) methods.

Parameters:
array - the int array (must be non-null) to be wrapped.
Throws:
java.lang.NullPointerException - if array is null.
Since:
2.0
See Also:
IntVector(), IntVector(int), setArray(int[]), array(), resize(int), ensureSize(int), setAt(int, int), getIntAt(int), copyAt(int, int, int), clone(), toString()
Method Detail

setArray

public void setArray(int[] array)
              throws java.lang.NullPointerException
Sets another array to be wrapped by this vector. Important notes: resize(int) and ensureSize(int) methods may change the array to be wrapped too (but only with its copy of a different length); this method does not copy array. If an exception is thrown then this vector remains unchanged.

Parameters:
array - the int array (must be non-null) to be wrapped.
Throws:
java.lang.NullPointerException - if array is null.
Since:
2.0
See Also:
IntVector(), IntVector(int[]), array(), resize(int), ensureSize(int), setAt(int, int), getIntAt(int), copyAt(int, int, int), clone()

array

public final int[] array()
Returns array wrapped by this vector. Important notes: this method does not copy array.

Returns:
the int array (not null), which is wrapped.
Since:
1.8
See Also:
IntVector(int[]), setArray(int[]), length(), resize(int), ensureSize(int), copyAt(int, int, int), clone()

length

public int length()
Returns the number of elements in this vector. The result is the same as length of array().

Specified by:
length in interface Indexable
Returns:
the length (non-negative value) of this vector.
Since:
1.8
See Also:
setArray(int[]), array(), setAt(int, int), resize(int), ensureSize(int), getIntAt(int), getAt(int)

getAt

public java.lang.Object getAt(int index)
                       throws java.lang.ArrayIndexOutOfBoundsException
Returns the wrapped value of the element at the specified index. The result is the same as of new Integer(array()[index]).

Specified by:
getAt in interface Indexable
Parameters:
index - the index (must be in the range) at which to return an element.
Returns:
an element (instance of Integer) at index.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if index is negative or is not less than length().
java.lang.OutOfMemoryError - if there is not enough memory.
See Also:
getIntAt(int), array(), length()

getIntAt

public final int getIntAt(int index)
                   throws java.lang.ArrayIndexOutOfBoundsException
Returns value of the element at the specified index. The result is the same as of array()[index].

Parameters:
index - the index (must be in the range) at which to return an element.
Returns:
a int element at index.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if index is negative or is not less than length().
See Also:
array(), length(), setAt(int, int), resize(int), ensureSize(int)

setAt

public void setAt(int index,
                  int value)
           throws java.lang.ArrayIndexOutOfBoundsException
Assigns a new value to the element at the specified index. If an exception is thrown then this vector remains unchanged.

Parameters:
index - the index (must be in the range) at which to assign a new value.
value - the value to be assigned.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if index is negative or is not less than length().
See Also:
setArray(int[]), array(), length(), getIntAt(int), resize(int), ensureSize(int), copyAt(int, int, int), fill(int[], int, int, int)

copyAt

public void copyAt(int srcOffset,
                   int destOffset,
                   int len)
            throws java.lang.ArrayIndexOutOfBoundsException
Copies a region of values at one offset to another offset in this vector. Copying is performed here through arraycopy(Object, int, Object, int, int) method of System class. Negative len is treated as zero. If an exception is thrown then this vector remains unchanged.

Parameters:
srcOffset - the source first index (must be in the range) of the region to be copied.
destOffset - the first index (must be in the range) of the region copy destination.
len - the length of the region to be copied.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if len is positive and (srcOffset is negative or is greater than length() minus len, or destOffset is negative or is greater than length() minus len).
See Also:
array(), length(), setAt(int, int), getIntAt(int), resize(int), ensureSize(int)

resize

public void resize(int size)
Resizes this vector. The result is the same as of setArray(resize(array(), size)). This method changes the length of this vector to the specified one. Important notes: if size (length) of the vector grows then its new elements are set to zero. If an exception is thrown then this vector remains unchanged.

Parameters:
size - the (unsigned) length of this vector to set.
Throws:
java.lang.OutOfMemoryError - if there is not enough memory.
See Also:
IntVector(int), setArray(int[]), array(), length(), ensureSize(int), resize(int[], int)

ensureSize

public void ensureSize(int size)
Ensures the size (capacity) of this vector. The result is the same as of setArray(ensureSize(array(), size)). This method changes (only if size is greater than length()) the length of this vector to a value not less than size. Important notes: if size (length) of the vector grows then its new elements are set to zero. If an exception is thrown then this vector remains unchanged.

Parameters:
size - the (unsigned) length of this vector to be ensured.
Throws:
java.lang.OutOfMemoryError - if there is not enough memory.
See Also:
array(), length(), setAt(int, int), resize(int), ensureSize(int[], int)

resize

public static final int[] resize(int[] array,
                                 int size)
                          throws java.lang.NullPointerException
Resizes a given array. This method 'changes' (creates a new array and copies the content to it) the length of the specified array to the specified one. Important notes: array elements are not changed; if length of array is the same as size then array is returned else array content is copied into the result (all new elements are set to zero).

Parameters:
array - the array (must be non-null) to be resized.
size - the (unsigned) length of the array to set.
Returns:
the resized array (not null, with length equal to size).
Throws:
java.lang.NullPointerException - if array is null.
java.lang.OutOfMemoryError - if there is not enough memory.
See Also:
resize(int), ensureSize(int[], int), fill(int[], int, int, int)

ensureSize

public static final int[] ensureSize(int[] array,
                                     int size)
                              throws java.lang.NullPointerException
Ensures the length (capacity) of a given array. This method 'grows' (only if size is greater than length of array) the length of array. Important notes: array elements are not changed; if length of array is greater or the same as size then array is returned else array content is copied into the result (all new elements are set to zero).

Parameters:
array - the array (must be non-null) to be length-ensured.
size - the (unsigned) length of the array to ensure.
Returns:
the length-ensured array (not null, with length not less than size).
Throws:
java.lang.NullPointerException - if array is null.
java.lang.OutOfMemoryError - if there is not enough memory.
See Also:
ensureSize(int), resize(int[], int), fill(int[], int, int, int)

fill

public static final void fill(int[] array,
                              int offset,
                              int len,
                              int value)
                       throws java.lang.NullPointerException,
                              java.lang.ArrayIndexOutOfBoundsException
Fills in the region of a given array with the specified value. All the elements in the specified region of array are set to value. Negative len is treated as zero. If an exception is thrown then array remains unchanged. Else array content is altered. Important notes: region filling is performed using arraycopy(Object, int, Object, int, int) method of System class.

Parameters:
array - the array (must be non-null) to be filled in.
offset - the first index (must be in the range) of the region to fill in.
len - the length of the region to be filled.
value - the value to fill with.
Throws:
java.lang.NullPointerException - if array is null.
java.lang.ArrayIndexOutOfBoundsException - if len is positive and (offset is negative or is greater than length of array minus len).
Since:
2.0
See Also:
array(), copyAt(int, int, int), indexOf(int[], int, int, int, int[]), lastIndexOf(int[], int, int, int, int[]), toString(int[], int, int, char, boolean), quickSort(int[], int, int, boolean), binarySearch(int[], int, int, int, boolean)

reverse

public static final void reverse(int[] array)
                          throws java.lang.NullPointerException
Reverses the elements order in a given array. The first element is exchanged with the least one, the second one is exchanged with the element just before the last one, etc. array content is altered.

Parameters:
array - the array (must be non-null) to be reversed.
Throws:
java.lang.NullPointerException - if array is null.
See Also:
array(), addTo(int[], int[]), subtractFrom(int[], int[]), countNonZero(int[]), indexOf(int, int, int[]), lastIndexOf(int, int, int[]), hashCode(int[]), equals(int[], int[]), compare(int[], int, int, int[], int, int, boolean), mismatches(int[], int, int[], int, int)

and

public static final void and(int[] arrayA,
                             int[] arrayB)
                      throws java.lang.NullPointerException
Performs logical 'and' operation on two given arrays. Every element of int arrays is treated here as a container of JavaConsts INT_SIZE separate bits. For every 0 bit of the second array the corresponding bit (if not missing) of the first array is set to 0 too. arrayA content is altered.

Parameters:
arrayA - the first array (must be non-null) of packed bits.
arrayB - the second array (must be non-null) of packed bits.
Throws:
java.lang.NullPointerException - if arrayA is null or arrayB is null.
Since:
2.0
See Also:
array(), andNot(int[], int[]), or(int[], int[]), orNot(int[], int[]), xor(int[], int[]), invert(int[]), addTo(int[], int[]), subtractFrom(int[], int[])

andNot

public static final void andNot(int[] arrayA,
                                int[] arrayB)
                         throws java.lang.NullPointerException
Performs logical 'and not' operation on two given arrays. Every element of int arrays is treated here as a container of JavaConsts INT_SIZE separate bits. For every 1 bit of the second array the corresponding bit (if not missing) of the first array is set to 0. arrayA content is altered.

Parameters:
arrayA - the first array (must be non-null) of packed bits.
arrayB - the second array (must be non-null) of packed bits.
Throws:
java.lang.NullPointerException - if arrayA is null or arrayB is null.
Since:
2.0
See Also:
array(), fill(int[], int, int, int), and(int[], int[]), or(int[], int[]), orNot(int[], int[]), xor(int[], int[]), invert(int[]), addTo(int[], int[]), subtractFrom(int[], int[])

or

public static final void or(int[] arrayA,
                            int[] arrayB)
                     throws java.lang.NullPointerException
Performs logical 'or' operation on two given arrays. Every element of int arrays is treated here as a container of JavaConsts INT_SIZE separate bits. For every 1 bit of the second array the corresponding bit (if not missing) of the first array is set to 1 too. arrayA content is altered.

Parameters:
arrayA - the first array (must be non-null) of packed bits.
arrayB - the second array (must be non-null) of packed bits.
Throws:
java.lang.NullPointerException - if arrayA is null or arrayB is null.
Since:
2.0
See Also:
array(), and(int[], int[]), andNot(int[], int[]), orNot(int[], int[]), xor(int[], int[]), invert(int[]), addTo(int[], int[]), subtractFrom(int[], int[])

orNot

public static final void orNot(int[] arrayA,
                               int[] arrayB)
                        throws java.lang.NullPointerException
Performs logical 'or not' operation on two given arrays. Every element of int arrays is treated here as a container of JavaConsts INT_SIZE separate bits. For every 0 bit of the second array the corresponding bit (if not missing) of the first array is set to 1. arrayA content is altered.

Parameters:
arrayA - the first array (must be non-null) of packed bits.
arrayB - the second array (must be non-null) of packed bits.
Throws:
java.lang.NullPointerException - if arrayA is null or arrayB is null.
Since:
2.0
See Also:
array(), fill(int[], int, int, int), and(int[], int[]), andNot(int[], int[]), or(int[], int[]), xor(int[], int[]), invert(int[]), addTo(int[], int[]), subtractFrom(int[], int[])

xor

public static final void xor(int[] arrayA,
                             int[] arrayB)
                      throws java.lang.NullPointerException
Performs logical 'exclusive or' operation on two given arrays. Every element of int arrays is treated here as a container of JavaConsts INT_SIZE separate bits. Every bit of the first array which differs from the corresponding bit (if not missing) of the second array is set to 1, else it is set to 0 (but only if its corresponding bit of the second array is not missing). arrayA content is altered.

Parameters:
arrayA - the first array (must be non-null) of packed bits.
arrayB - the second array (must be non-null) of packed bits.
Throws:
java.lang.NullPointerException - if arrayA is null or arrayB is null.
Since:
2.0
See Also:
array(), fill(int[], int, int, int), and(int[], int[]), andNot(int[], int[]), or(int[], int[]), orNot(int[], int[]), invert(int[]), addTo(int[], int[]), subtractFrom(int[], int[])

invert

public static final void invert(int[] array)
                         throws java.lang.NullPointerException
Performs logical 'not' operation on a given array. Every element of int array is treated here as a container of JavaConsts INT_SIZE separate bits. Every bit of the specified array is inverted. array content is altered.

Parameters:
array - the array (must be non-null) of packed bits to be inverted.
Throws:
java.lang.NullPointerException - if array is null.
Since:
2.0
See Also:
array(), reverse(int[]), and(int[], int[]), andNot(int[], int[]), or(int[], int[]), orNot(int[], int[]), xor(int[], int[])

addTo

public static final void addTo(int[] arrayA,
                               int[] arrayB)
                        throws java.lang.NullPointerException
Adds a given vector (array) to another one. Every element of the second array (missing element is treated to be zero) is added to the corresponding element (if not missing) of the first array (overflow is not checked). arrayA content is altered.

Parameters:
arrayA - the first array (must be non-null) to be added to.
arrayB - the second array (must be non-null) to add.
Throws:
java.lang.NullPointerException - if arrayA is null or arrayB is null.
Since:
2.0
See Also:
array(), reverse(int[]), subtractFrom(int[], int[]), multiplyBy(int[], int), sumOf(int[], int, int), scalarMul(int[], int[]), polynome(int, int[]), and(int[], int[]), andNot(int[], int[]), or(int[], int[]), orNot(int[], int[]), xor(int[], int[])

subtractFrom

public static final void subtractFrom(int[] arrayA,
                                      int[] arrayB)
                               throws java.lang.NullPointerException
Subtracts a given vector (array) from another one. Every element of the second array (missing element is treated to be zero) is subtracted from the corresponding element (if not missing) of the first array (overflow is not checked). arrayA content is altered.

Parameters:
arrayA - the first array (must be non-null) to be subtracted from.
arrayB - the second array (must be non-null) to subtract.
Throws:
java.lang.NullPointerException - if arrayA is null or arrayB is null.
Since:
2.0
See Also:
array(), fill(int[], int, int, int), reverse(int[]), addTo(int[], int[]), multiplyBy(int[], int), sumOf(int[], int, int), scalarMul(int[], int[]), polynome(int, int[]), and(int[], int[]), andNot(int[], int[]), or(int[], int[]), orNot(int[], int[]), xor(int[], int[])

multiplyBy

public static final void multiplyBy(int[] array,
                                    int value)
                             throws java.lang.NullPointerException
Multiplies a given vector (array) by a value. Every element of the specified array is multiplied by value (overflow is not checked). array content is altered.

Parameters:
array - the array (must be non-null) to be multiplied.
value - the value to multiply by.
Throws:
java.lang.NullPointerException - if array is null.
Since:
2.0
See Also:
array(), fill(int[], int, int, int), reverse(int[]), addTo(int[], int[]), subtractFrom(int[], int[]), sumOf(int[], int, int), scalarMul(int[], int[]), polynome(int, int[]), countNonZero(int[]), invert(int[])

scalarMul

public static final int scalarMul(int[] arrayA,
                                  int[] arrayB)
                           throws java.lang.NullPointerException
Multiplies two given vectors (arrays) in a scalar way. Every element of the first array is multiplied by the corresponding element of the second array (missing element is treated to be zero) and the results of these multiplications are summed together (overflow is not checked).

Parameters:
arrayA - the first array (must be non-null) to multiply.
arrayB - the second array (must be non-null) to multiply.
Returns:
the signed/unsigned multiplication result.
Throws:
java.lang.NullPointerException - if arrayA is null or arrayB is null.
Since:
2.0
See Also:
array(), longScalarMul(int[], int[], boolean), longPolynome(long, int[], boolean), longSumOf(int[], int, int, boolean), addTo(int[], int[]), subtractFrom(int[], int[]), multiplyBy(int[], int), sumOf(int[], int, int), polynome(int, int[]), mismatches(int[], int, int[], int, int), equals(int[], int[])

longScalarMul

public static final long longScalarMul(int[] arrayA,
                                       int[] arrayB,
                                       boolean isUnsigned)
                                throws java.lang.NullPointerException
Multiplies two given vectors (arrays) in a scalar way treating their elements as long values. Every element of the first array is multiplied by the corresponding element of the second array (missing element is treated to be zero) and the results of these multiplications are summed together (overflow is not checked).

Parameters:
arrayA - the first array (must be non-null) to multiply.
arrayB - the second array (must be non-null) to multiply.
isUnsigned - true if and only if array elements are (treated as) unsigned.
Returns:
the signed/unsigned multiplication long result.
Throws:
java.lang.NullPointerException - if arrayA is null or arrayB is null.
Since:
2.0
See Also:
array(), scalarMul(int[], int[]), longPolynome(long, int[], boolean), longSumOf(int[], int, int, boolean), addTo(int[], int[]), subtractFrom(int[], int[]), multiplyBy(int[], int)

polynome

public static final int polynome(int value,
                                 int[] array)
                          throws java.lang.NullPointerException
Computes the result of substitution of a given value into the polynome specified by its coefficients. The result is the same as of sum(array[index] * power(value, index)). Overflow is not checked. If length of array is zero then 0 is returned.

Parameters:
value - the value to be substituted.
array - the array (must be non-null) of the polynome coefficients, arranged by their weight.
Returns:
the signed/unsigned result of the substitution of value.
Throws:
java.lang.NullPointerException - if array is null.
Since:
2.0
See Also:
array(), longScalarMul(int[], int[], boolean), longPolynome(long, int[], boolean), longSumOf(int[], int, int, boolean), addTo(int[], int[]), subtractFrom(int[], int[]), multiplyBy(int[], int), scalarMul(int[], int[]), sumOf(int[], int, int), countNonZero(int[])

longPolynome

public static final long longPolynome(long longValue,
                                      int[] array,
                                      boolean isUnsigned)
                               throws java.lang.NullPointerException
Computes the result of substitution of a given long value into the polynome specified by its coefficients. The result is the same as of sum(array[index] * power(longValue, index)). Overflow is not checked. If length of array is zero then 0 is returned.

Parameters:
longValue - the long value to be substituted.
array - the array (must be non-null) of the polynome coefficients, arranged by their weight.
isUnsigned - true if and only if array elements are (treated as) unsigned.
Returns:
the signed/unsigned long result of the substitution.
Throws:
java.lang.NullPointerException - if array is null.
Since:
2.0
See Also:
array(), polynome(int, int[]), longScalarMul(int[], int[], boolean), longSumOf(int[], int, int, boolean), addTo(int[], int[]), subtractFrom(int[], int[]), multiplyBy(int[], int)

sumOf

public static final int sumOf(int[] array,
                              int offset,
                              int len)
                       throws java.lang.NullPointerException,
                              java.lang.ArrayIndexOutOfBoundsException
Sums the elements in the region of a given array. Negative len is treated as zero. The sum overflow is not checked.

Parameters:
array - the array (must be non-null) which elements to be summed.
offset - the first index (must be in the range) of the region.
len - the length of the region.
Returns:
the signed/unsigned sum value for a given region.
Throws:
java.lang.NullPointerException - if array is null.
java.lang.ArrayIndexOutOfBoundsException - if len is positive and (offset is negative or is greater than length of array minus len).
Since:
2.0
See Also:
array(), fill(int[], int, int, int), longScalarMul(int[], int[], boolean), longPolynome(long, int[], boolean), longSumOf(int[], int, int, boolean), addTo(int[], int[]), subtractFrom(int[], int[]), multiplyBy(int[], int), countNonZero(int[]), hashCode(int[]), mismatches(int[], int, int[], int, int), scalarMul(int[], int[]), polynome(int, int[])

longSumOf

public static final long longSumOf(int[] array,
                                   int offset,
                                   int len,
                                   boolean isUnsigned)
                            throws java.lang.NullPointerException,
                                   java.lang.ArrayIndexOutOfBoundsException
Sums the elements in the region of a given array as long values. The elements in the region are summed as either signed or unsigned values. Negative len is treated as zero. The sum overflow is not checked.

Parameters:
array - the array (must be non-null) which elements to be summed.
offset - the first index (must be in the range) of the region.
len - the length of the region.
isUnsigned - true if and only if array elements are (treated as) unsigned.
Returns:
the signed/unsigned sum (long value) for a given region.
Throws:
java.lang.NullPointerException - if array is null.
java.lang.ArrayIndexOutOfBoundsException - if len is positive and (offset is negative or is greater than length of array minus len).
Since:
2.0
See Also:
array(), fill(int[], int, int, int), sumOf(int[], int, int), longScalarMul(int[], int[], boolean), longPolynome(long, int[], boolean), addTo(int[], int[]), subtractFrom(int[], int[]), multiplyBy(int[], int), countNonZero(int[])

countNonZero

public static final int countNonZero(int[] array)
                              throws java.lang.NullPointerException
Count non-zero elements in a given array. This method returns the count of elements of array which are not equal to zero.

Parameters:
array - the array (must be non-null) to count non-zero elements in.
Returns:
the count (non-negative and not greater than length of array) of non-zero elements.
Throws:
java.lang.NullPointerException - if array is null.
Since:
2.0
See Also:
array(), fill(int[], int, int, int), sumOf(int[], int, int), scalarMul(int[], int[]), polynome(int, int[]), equals(int[], int[]), compare(int[], int, int, int[], int, int, boolean), mismatches(int[], int, int[], int, int)

indexOf

public static final int indexOf(int value,
                                int index,
                                int[] array)
                         throws java.lang.NullPointerException
Searches forward for value in a given array. Negative index is treated as zero, too big index is treated as length of array. If value is not found then the result is -1.

Parameters:
value - the value to sequentially search for.
index - the first index, from which to begin forward searching.
array - the array (must be non-null) to be searched in.
Returns:
the index (non-negative) of the found value or -1 (if not found).
Throws:
java.lang.NullPointerException - if array is null.
See Also:
array(), lastIndexOf(int, int, int[]), indexOf(int[], int, int, int, int[]), binarySearch(int[], int, int, int, boolean), equals(int[], int[]), compare(int[], int, int, int[], int, int, boolean)

lastIndexOf

public static final int lastIndexOf(int value,
                                    int index,
                                    int[] array)
                             throws java.lang.NullPointerException
Searches backward for value in a given array. Negative index is treated as -1, too big index is treated as length of array minus one. If value is not found then the result is -1.

Parameters:
value - the value to sequentially search for.
index - the first index, from which to begin backward searching.
array - the array (must be non-null) to be searched in.
Returns:
the index (non-negative) of the found value or -1 (if not found).
Throws:
java.lang.NullPointerException - if array is null.
See Also:
array(), indexOf(int, int, int[]), lastIndexOf(int[], int, int, int, int[]), binarySearch(int[], int, int, int, boolean), reverse(int[]), equals(int[], int[]), compare(int[], int, int, int[], int, int, boolean)

indexOf

public static final int indexOf(int[] subArray,
                                int offset,
                                int len,
                                int index,
                                int[] array)
                         throws java.lang.NullPointerException,
                                java.lang.ArrayIndexOutOfBoundsException
Searches forward for the specified sequence in a given array. The searched sequence of values is specified by subArray, offset and len. Negative len is treated as zero. Negative index is treated as zero, too big index is treated as length of array. If the sequence is not found then the result is -1.

Parameters:
subArray - the array (must be non-null) specifying the sequence of values to search for.
offset - the offset (must be in the range) of the sequence in subArray.
len - the length of the sequence.
index - the first index, from which to begin forward searching.
array - the array (must be non-null) to be searched in.
Returns:
the index (non-negative) of the found sequence or -1 (if not found).
Throws:
java.lang.NullPointerException - if subArray is null or array is null.
java.lang.ArrayIndexOutOfBoundsException - if len is positive and (offset is negative or is greater than length of subArray minus len).
See Also:
array(), indexOf(int, int, int[]), lastIndexOf(int[], int, int, int, int[]), equals(int[], int[]), compare(int[], int, int, int[], int, int, boolean)

lastIndexOf

public static final int lastIndexOf(int[] subArray,
                                    int offset,
                                    int len,
                                    int index,
                                    int[] array)
                             throws java.lang.NullPointerException,
                                    java.lang.ArrayIndexOutOfBoundsException
Searches backward for the specified sequence in a given array. The searched sequence of values is specified by subArray, offset and len. Negative len is treated as zero. Negative index is treated as -1, too big index is treated as length of array minus one. If the sequence is not found then the result is -1.

Parameters:
subArray - the array (must be non-null) specifying the sequence of values to search for.
offset - the offset (must be in the range) of the sequence in subArray.
len - the length of the sequence.
index - the first index, from which to begin backward searching.
array - the array (must be non-null) to be searched in.
Returns:
the index (non-negative) of the found sequence or -1 (if not found).
Throws:
java.lang.NullPointerException - if subArray is null or array is null.
java.lang.ArrayIndexOutOfBoundsException - if len is positive and (offset is negative or is greater than length of subArray minus len).
See Also:
array(), lastIndexOf(int, int, int[]), indexOf(int[], int, int, int, int[]), equals(int[], int[]), compare(int[], int, int, int[], int, int, boolean)

toString

public static final java.lang.String toString(int[] array,
                                              int offset,
                                              int len,
                                              char separator,
                                              boolean isUnsigned)
                                       throws java.lang.NullPointerException,
                                              java.lang.ArrayIndexOutOfBoundsException
Converts the region of a given array to its 'in-line' string representation. The decimal string representations of signed or unsigned int values (of the specified region of array) are placed into the resulting string in the direct index order, delimited by a single separator character. Negative len is treated as zero.

Parameters:
array - the array (must be non-null) to be converted.
offset - the first index (must be in the range) of the region to be converted.
len - the length of the region to be converted.
separator - the delimiter character.
isUnsigned - true if and only if array elements are (treated as) unsigned.
Returns:
the string representation (not null) of the specified region.
Throws:
java.lang.NullPointerException - if array is null.
java.lang.ArrayIndexOutOfBoundsException - if len is positive and (offset is negative or is greater than length of array minus len).
java.lang.OutOfMemoryError - if there is not enough memory.
See Also:
array(), toString(), fill(int[], int, int, int), quickSort(int[], int, int, boolean), binarySearch(int[], int, int, int, boolean)

hashCode

public static final int hashCode(int[] array)
                          throws java.lang.NullPointerException
Produces a hash code value for a given array. This method mixes all the elements of array to produce a single hash code value.

Parameters:
array - the array (must be non-null) to evaluate hash of.
Returns:
the hash code value for array.
Throws:
java.lang.NullPointerException - if array is null.
See Also:
array(), hashCode(), fill(int[], int, int, int), reverse(int[]), sumOf(int[], int, int), countNonZero(int[]), indexOf(int, int, int[]), lastIndexOf(int, int, int[]), equals(int[], int[]), compare(int[], int, int, int[], int, int, boolean), mismatches(int[], int, int[], int, int)

equals

public static final boolean equals(int[] arrayA,
                                   int[] arrayB)
                            throws java.lang.NullPointerException
Tests whether or not the specified two arrays are equal. This method returns true if and only if both of the arrays are of the same length and all the elements of the first array are equal to the corresponding elements of the second array.

Parameters:
arrayA - the first array (must be non-null) to be compared.
arrayB - the second array (must be non-null) to compare with.
Returns:
true if and only if arrayA content is the same as arrayB content.
Throws:
java.lang.NullPointerException - if arrayA is null or arrayB is null.
Since:
2.0
See Also:
array(), equals(java.lang.Object), fill(int[], int, int, int), reverse(int[]), subtractFrom(int[], int[]), scalarMul(int[], int[]), sumOf(int[], int, int), indexOf(int, int, int[]), lastIndexOf(int, int, int[]), indexOf(int[], int, int, int, int[]), lastIndexOf(int[], int, int, int, int[]), hashCode(int[]), compare(int[], int, int, int[], int, int, boolean), mismatches(int[], int, int[], int, int)

mismatches

public static final int mismatches(int[] arrayA,
                                   int offsetA,
                                   int[] arrayB,
                                   int offsetB,
                                   int len)
                            throws java.lang.NullPointerException,
                                   java.lang.ArrayIndexOutOfBoundsException
Count the mismatches of two given array regions. This method returns the count of elements of the first array region which are not equal to the corresponding elements of the second array region. Negative len is treated as zero.

Parameters:
arrayA - the first array (must be non-null) to be compared.
offsetA - the first index (must be in the range) of the first region.
arrayB - the second array (must be non-null) to compare with.
offsetB - the first index (must be in the range) of the second region.
len - the length of the regions.
Returns:
the count (non-negative) of found mismatches of the regions.
Throws:
java.lang.NullPointerException - if arrayA is null or arrayB is null.
java.lang.ArrayIndexOutOfBoundsException - if len is positive and (offsetA is negative or is greater than length of arrayA minus len, or offsetB is negative or is greater than length of arrayB minus len).
Since:
2.0
See Also:
array(), fill(int[], int, int, int), reverse(int[]), subtractFrom(int[], int[]), scalarMul(int[], int[]), sumOf(int[], int, int), countNonZero(int[]), hashCode(int[]), equals(int[], int[]), compare(int[], int, int, int[], int, int, boolean)

compare

public static final int compare(int[] arrayA,
                                int offsetA,
                                int lenA,
                                int[] arrayB,
                                int offsetB,
                                int lenB,
                                boolean isUnsigned)
                         throws java.lang.NullPointerException,
                                java.lang.ArrayIndexOutOfBoundsException
Compares two given array regions. This method returns a signed integer indicating 'less-equal-greater' relation between the specified array regions of signed or unsigned int values (the absolute value of the result, in fact, is the distance between the first found mismatch and the end of the bigger-length region). Negative lenA is treated as zero. Negative lenB is treated as zero. Important notes: the content of array regions is compared before comparing their length.

Parameters:
arrayA - the first array (must be non-null) to be compared.
offsetA - the first index (must be in the range) of the first region.
lenA - the length of the first region.
arrayB - the second array (must be non-null) to compare with.
offsetB - the first index (must be in the range) of the second region.
lenB - the length of the second region.
isUnsigned - true if and only if array elements are (treated as) unsigned.
Returns:
a negative integer, zero, or a positive integer as arrayA region is less than, equal to, or greater than arrayB one.
Throws:
java.lang.NullPointerException - if arrayA is null or arrayB is null.
java.lang.ArrayIndexOutOfBoundsException - if lenA is positive and (offsetA is negative or is greater than length of arrayA minus lenA), or if lenB is positive and (offsetB is negative or is greater than length of arrayB minus lenB).
See Also:
array(), greaterThan(java.lang.Object), fill(int[], int, int, int), reverse(int[]), sumOf(int[], int, int), longScalarMul(int[], int[], boolean), longPolynome(long, int[], boolean), longSumOf(int[], int, int, boolean), indexOf(int, int, int[]), lastIndexOf(int, int, int[]), hashCode(int[]), equals(int[], int[]), mismatches(int[], int, int[], int, int)

quickSort

public static final void quickSort(int[] array,
                                   int offset,
                                   int len,
                                   boolean isUnsigned)
                            throws java.lang.NullPointerException,
                                   java.lang.ArrayIndexOutOfBoundsException
Sorts the elements in the region of a given array using 'Quick' algorithm. Elements in the region are sorted into ascending signed or unsigned order. But equal elements may be reordered (since the algorithm is not 'stable'). A small working stack is allocated (since the algorithm is 'in-place' and recursive). The algorithm cost is O(log(len) * len) typically, but may be of O(len * len) in the worst case (which is rare, in fact). Negative len is treated as zero. If an exception is thrown then array remains unchanged. Else the region content is altered.

Parameters:
array - the array (must be non-null) to be sorted.
offset - the first index (must be in the range) of the region to sort.
len - the length of the region to sort.
isUnsigned - true if and only if array elements are (treated as) unsigned.
Throws:
java.lang.NullPointerException - if array is null.
java.lang.ArrayIndexOutOfBoundsException - if len is positive and (offset is negative or is greater than length of array minus len).
java.lang.OutOfMemoryError - if there is not enough memory.
See Also:
array(), binarySearch(int[], int, int, int, boolean), fill(int[], int, int, int), toString(int[], int, int, char, boolean)

binarySearch

public static final int binarySearch(int[] array,
                                     int offset,
                                     int len,
                                     int value,
                                     boolean isUnsigned)
                              throws java.lang.NullPointerException,
                                     java.lang.ArrayIndexOutOfBoundsException
Searches (fast) for value in a given sorted array. array (or its specified range) must be sorted ascending, or the result is undefined. The algorithm cost is of O(log(len)). Negative len is treated as zero. If value is not found then (-result - 1) is the offset of the insertion point for value.

Parameters:
array - the sorted array (must be non-null) to be searched in.
offset - the first index (must be in the range) of the region to search in.
len - the length of the region to search in.
value - the value to search for.
isUnsigned - true if and only if value and array elements are (treated as) unsigned.
Returns:
the index (non-negative) of the found value or (-insertionOffset - 1) (a negative integer) if not found.
Throws:
java.lang.NullPointerException - if array is null.
java.lang.ArrayIndexOutOfBoundsException - if len is positive and (offset is negative or is greater than length of array minus len).
See Also:
array(), indexOf(int, int, int[]), lastIndexOf(int, int, int[]), quickSort(int[], int, int, boolean), fill(int[], int, int, int), toString(int[], int, int, char, boolean)

clone

public java.lang.Object clone()
Creates and returns a copy of this object. This method creates a new instance of the class of this object and initializes its array with a copy of array of this vector.

Specified by:
clone in interface ReallyCloneable
Overrides:
clone in class java.lang.Object
Returns:
a copy (not null and != this) of this instance.
Throws:
java.lang.OutOfMemoryError - if there is not enough memory.
See Also:
IntVector(), array(), getIntAt(int), equals(java.lang.Object)

hashCode

public int hashCode()
Computes and returns a hash code value for the object. This method mixes all the elements of this vector to produce a single hash code value.

Overrides:
hashCode in class java.lang.Object
Returns:
a hash code value for this object.
See Also:
hashCode(int[]), array(), length(), getIntAt(int), equals(java.lang.Object)

equals

public boolean equals(java.lang.Object obj)
Indicates whether this object is equal to the specified one. This method returns true if and only if obj is instance of this vector class and all elements of this vector are equal to the corresponding elements of obj vector.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the object (may be null) with which to compare.
Returns:
true if and only if this value is the same as obj value.
See Also:
IntVector(), equals(int[], int[]), array(), length(), getIntAt(int), hashCode(), greaterThan(java.lang.Object)

greaterThan

public boolean greaterThan(java.lang.Object obj)
Tests for being semantically greater than the argument. The result is true if and only if obj is instance of this class and this object is greater than the specified object. Vectors are compared in the element-by-element (signed) manner, starting at index 0.

Specified by:
greaterThan in interface Sortable
Parameters:
obj - the second compared object (may be null).
Returns:
true if obj is comparable with this and this object is greater than obj, else false.
Since:
2.0
See Also:
compare(int[], int, int, int[], int, int, boolean), array(), length(), getIntAt(int), equals(java.lang.Object)

toString

public java.lang.String toString()
Converts this vector to its 'in-line' string representation. The decimal string representations of signed int values of the wrapped array are placed into the resulting string in the direct index order, delimited by a single space.

Overrides:
toString in class java.lang.Object
Returns:
the string representation (not null) of this object.
Throws:
java.lang.OutOfMemoryError - if there is not enough memory.
See Also:
toString(int[], int, int, char, boolean), array(), length()

integrityCheck

public void integrityCheck()
Verifies this object for its integrity. For debug purpose only.

Specified by:
integrityCheck in interface Verifiable
Throws:
java.lang.InternalError - if integrity violation is detected.
Since:
2.0
See Also:
IntVector(int[]), setArray(int[]), array()