fr.dyade.aaa.common
Class Arrays

java.lang.Object
  extended by fr.dyade.aaa.common.Arrays

public class Arrays
extends java.lang.Object

This class contains various methods for sorting and searching int arrays.


Constructor Summary
Arrays()
           
 
Method Summary
static int binarySearch(short[] a, int key)
          Searches the specified array of ints for the specified value using the binary search algorithm.
static boolean equals(short[] a, short[] a2)
          Returns true if the two specified arrays of shorts are equal to one another.
private static int med3(short[] x, int a, int b, int c)
          Returns the index of the median of the three indexed integers.
private static void rangeCheck(int arrayLen, int fromIndex, int toIndex)
          Check that fromIndex and toIndex are in range, and throw an appropriate exception if they aren't.
static void sort(short[] a)
          Sorts the specified array of ints into ascending numerical order.
static void sort(short[] a, int fromIndex, int toIndex)
          Sorts the specified range of the specified array of ints into ascending numerical order.
private static void sort1(short[] x, int off, int len)
          Sorts the specified sub-array of integers into ascending order.
private static void swap(short[] x, int a, int b)
          Swaps x[a] with x[b].
private static void vecswap(short[] x, int a, int b, int n)
          Swaps x[a ..
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Arrays

public Arrays()
Method Detail

sort

public static void sort(short[] a)
Sorts the specified array of ints into ascending numerical order. The sorting algorithm is a tuned quicksort.

Parameters:
a - the array to be sorted.

sort

public static void sort(short[] a,
                        int fromIndex,
                        int toIndex)
Sorts the specified range of the specified array of ints into ascending numerical order.


sort1

private static void sort1(short[] x,
                          int off,
                          int len)
Sorts the specified sub-array of integers into ascending order.


swap

private static void swap(short[] x,
                         int a,
                         int b)
Swaps x[a] with x[b].


vecswap

private static void vecswap(short[] x,
                            int a,
                            int b,
                            int n)
Swaps x[a .. (a+n-1)] with x[b .. (b+n-1)].


med3

private static int med3(short[] x,
                        int a,
                        int b,
                        int c)
Returns the index of the median of the three indexed integers.


rangeCheck

private static void rangeCheck(int arrayLen,
                               int fromIndex,
                               int toIndex)
Check that fromIndex and toIndex are in range, and throw an appropriate exception if they aren't.


binarySearch

public static int binarySearch(short[] a,
                               int key)
Searches the specified array of ints for the specified value using the binary search algorithm. The array must be sorted (as by the sort method, above) prior to making this call.


equals

public static boolean equals(short[] a,
                             short[] a2)
Returns true if the two specified arrays of shorts are equal to one another.



Copyright © 2010 ScalAgent D.T.. All Rights Reserved.