Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.bouncycastle.pqc.math.linearalgebra;
  
  
 public final class IntUtils
 {

    
Default constructor (private).
 
     private IntUtils()
     {
         // empty
     }

    
Compare two int arrays. No null checks are performed.

Parameters:
left the first int array
right the second int array
Returns:
the result of the comparison
 
     public static boolean equals(int[] leftint[] right)
     {
         if (left.length != right.length)
         {
             return false;
         }
         boolean result = true;
         for (int i = left.length - 1; i >= 0; i--)
         {
             result &= left[i] == right[i];
         }
         return result;
     }

    
Return a clone of the given int array. No null checks are performed.

Parameters:
array the array to clone
Returns:
the clone of the given array
 
     public static int[] clone(int[] array)
     {
         int[] result = new int[array.length];
         System.arraycopy(array, 0, result, 0, array.length);
         return result;
     }

    
Fill the given int array with the given value.

Parameters:
array the array
value the value
 
     public static void fill(int[] arrayint value)
     {
         for (int i = array.length - 1; i >= 0; i--)
         {
             array[i] = value;
         }
     }

    
Sorts this array of integers according to the Quicksort algorithm. After calling this method this array is sorted in ascending order with the smallest integer taking position 0 in the array.

This implementation is based on the quicksort algorithm as described in Data Structures In Java by Thomas A. Standish, Chapter 10, ISBN 0-201-30564-X.

Parameters:
source the array of integers that needs to be sorted.
 
     public static void quicksort(int[] source)
     {
         quicksort(source, 0, source.length - 1);
     }

    
Sort a subarray of a source array. The subarray is specified by its start and end index.

Parameters:
source the int array to be sorted
left the start index of the subarray
right the end index of the subarray
 
     public static void quicksort(int[] sourceint leftint right)
     {
         if (right > left)
         {
             int index = partition(sourceleftrightright);
             quicksort(sourceleftindex - 1);
             quicksort(sourceindex + 1, right);
        }
    }

    
Split a subarray of a source array into two partitions. The left partition contains elements that have value less than or equal to the pivot element, the right partition contains the elements that have larger value.

Parameters:
source the int array whose subarray will be splitted
left the start position of the subarray
right the end position of the subarray
pivotIndex the index of the pivot element inside the array
Returns:
the new index of the pivot element inside the array
    private static int partition(int[] sourceint leftint right,
                                 int pivotIndex)
    {
        int pivot = source[pivotIndex];
        source[pivotIndex] = source[right];
        source[right] = pivot;
        int index = left;
        for (int i = lefti < righti++)
        {
            if (source[i] <= pivot)
            {
                int tmp = source[index];
                source[index] = source[i];
                source[i] = tmp;
                index++;
            }
        }
        int tmp = source[index];
        source[index] = source[right];
        source[right] = tmp;
        return index;
    }

    
Generates a subarray of a given int array.

Parameters:
input - the input int array
start - the start index
end - the end index
Returns:
a subarray of input, ranging from start to end
    public static int[] subArray(final int[] inputfinal int start,
                                 final int end)
    {
        int[] result = new int[end - start];
        System.arraycopy(inputstartresult, 0, end - start);
        return result;
    }

    
Convert an int array to a FlexiBigInt array.

Parameters:
input the int array
Returns:
the FlexiBigInt array
    public static BigInteger[] toFlexiBigIntArray(int[] input)
    {
        BigInteger[] result = new BigInteger[input.length];
        for (int i = 0; i < input.lengthi++)
        {
            result[i] = BigInteger.valueOf(input[i]);
        }
        return result;
    }

    

Parameters:
input an int array
Returns:
a human readable form of the given int array
    public static String toString(int[] input)
    {
        String result = "";
        for (int i = 0; i < input.lengthi++)
        {
            result += input[i] + " ";
        }
        return result;
    }

    

Parameters:
input an int arary
Returns:
the int array as hex string
    public static String toHexString(int[] input)
    {
        return ByteUtils.toHexString(BigEndianConversions.toByteArray(input));
    }
New to GrepCode? Check out our FAQ X