edu.rit.util
Class Searching
- java.lang.Object
-
- edu.rit.util.Searching
-
public class Searching extends java.lang.ObjectClass Searching provides static methods for searching arrays of primitive types and object types.Note: The operations in class Searching are not multiple thread safe.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static classSearching.ByteClass Searching.Byte is the base class for a helper object used to search an array of type byte[].static classSearching.CharacterClass Searching.Character is the base class for a helper object used to search an array of type char[].static classSearching.DoubleClass Searching.Double is the base class for a helper object used to search an array of type double[].static classSearching.FloatClass Searching.Float is the base class for a helper object used to search an array of type float[].static classSearching.IntegerClass Searching.Integer is the base class for a helper object used to search an array of type int[].static classSearching.LongClass Searching.Long is the base class for a helper object used to search an array of type long[].static classSearching.Object<T>Class Searching.Object is the base class for a helper object used to search an array of type T[].static classSearching.ShortClass Searching.Short is the base class for a helper object used to search an array of type short[].
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static intsearchSorted(byte[] x, byte a, Searching.Byte helper)Search the given ordered array of type byte[] for the given element.static intsearchSorted(char[] x, char a, Searching.Character helper)Search the given ordered array of type char[] for the given element.static intsearchSorted(double[] x, double a, Searching.Double helper)Search the given ordered array of type double[] for the given element.static intsearchSorted(float[] x, float a, Searching.Float helper)Search the given ordered array of type float[] for the given element.static intsearchSorted(int[] x, int a, Searching.Integer helper)Search the given ordered array of type int[] for the given element.static intsearchSorted(long[] x, long a, Searching.Long helper)Search the given ordered array of type long[] for the given element.static intsearchSorted(short[] x, short a, Searching.Short helper)Search the given ordered array of type short[] for the given element.static <T extends java.lang.Comparable>
intsearchSorted(T[] x, T a)Search the given ordered array of type T[] for the given element.static <T> intsearchSorted(T[] x, T a, java.util.Comparator<T> comp)Search the given ordered array of type T[] for the given element.static <T> intsearchSorted(T[] x, T a, Searching.Object<T> helper)Search the given ordered array of type T[] for the given element.static intsearchUnsorted(byte[] x, byte a, Searching.Byte helper)Search the given unordered array of type byte[] for the given element.static intsearchUnsorted(char[] x, char a, Searching.Character helper)Search the given unordered array of type char[] for the given element.static intsearchUnsorted(double[] x, double a, Searching.Double helper)Search the given unordered array of type double[] for the given element.static intsearchUnsorted(float[] x, float a, Searching.Float helper)Search the given unordered array of type float[] for the given element.static intsearchUnsorted(int[] x, int a, Searching.Integer helper)Search the given unordered array of type int[] for the given element.static intsearchUnsorted(long[] x, long a, Searching.Long helper)Search the given unordered array of type long[] for the given element.static intsearchUnsorted(short[] x, short a, Searching.Short helper)Search the given unordered array of type short[] for the given element.static <T extends java.lang.Comparable>
intsearchUnsorted(T[] x, T a)Search the given unordered array of type T[] for the given element.static <T> intsearchUnsorted(T[] x, T a, java.util.Comparator<T> comp)Search the given unordered array of type T[] for the given element.static <T> intsearchUnsorted(T[] x, T a, Searching.Object<T> helper)Search the given unordered array of type T[] for the given element.
-
-
-
Method Detail
-
searchUnsorted
public static int searchUnsorted(byte[] x, byte a, Searching.Byte helper)Search the given unordered array of type byte[] for the given element. The given helper object is used to compare elements for equality only. An O(n) linear search algorithm is used.- Parameters:
x- Array to be searched.a- Element to be searched for.helper- Helper object.- Returns:
- If an element the same as a exists in x, then the index of that element is returned. Otherwise, −1 is returned.
-
searchSorted
public static int searchSorted(byte[] x, byte a, Searching.Byte helper)Search the given ordered array of type byte[] for the given element. The given helper object is used to compare elements for order and equality. It is assumed that the array is sorted in the order determined by the helper object; otherwise, the searchSorted() method's behavior is not specified. An O(log n) binary search algorithm is used.- Parameters:
x- Array to be searched.a- Element to be searched for.helper- Helper object.- Returns:
- If an element the same as a exists in x, then the index of that element is returned. Otherwise, −1 is returned.
-
searchUnsorted
public static int searchUnsorted(char[] x, char a, Searching.Character helper)Search the given unordered array of type char[] for the given element. The given helper object is used to compare elements for equality only. An O(n) linear search algorithm is used.- Parameters:
x- Array to be searched.a- Element to be searched for.helper- Helper object.- Returns:
- If an element the same as a exists in x, then the index of that element is returned. Otherwise, −1 is returned.
-
searchSorted
public static int searchSorted(char[] x, char a, Searching.Character helper)Search the given ordered array of type char[] for the given element. The given helper object is used to compare elements for order and equality. It is assumed that the array is sorted in the order determined by the helper object; otherwise, the searchSorted() method's behavior is not specified. An O(log n) binary search algorithm is used.- Parameters:
x- Array to be searched.a- Element to be searched for.helper- Helper object.- Returns:
- If an element the same as a exists in x, then the index of that element is returned. Otherwise, −1 is returned.
-
searchUnsorted
public static int searchUnsorted(short[] x, short a, Searching.Short helper)Search the given unordered array of type short[] for the given element. The given helper object is used to compare elements for equality only. An O(n) linear search algorithm is used.- Parameters:
x- Array to be searched.a- Element to be searched for.helper- Helper object.- Returns:
- If an element the same as a exists in x, then the index of that element is returned. Otherwise, −1 is returned.
-
searchSorted
public static int searchSorted(short[] x, short a, Searching.Short helper)Search the given ordered array of type short[] for the given element. The given helper object is used to compare elements for order and equality. It is assumed that the array is sorted in the order determined by the helper object; otherwise, the searchSorted() method's behavior is not specified. An O(log n) binary search algorithm is used.- Parameters:
x- Array to be searched.a- Element to be searched for.helper- Helper object.- Returns:
- If an element the same as a exists in x, then the index of that element is returned. Otherwise, −1 is returned.
-
searchUnsorted
public static int searchUnsorted(int[] x, int a, Searching.Integer helper)Search the given unordered array of type int[] for the given element. The given helper object is used to compare elements for equality only. An O(n) linear search algorithm is used.- Parameters:
x- Array to be searched.a- Element to be searched for.helper- Helper object.- Returns:
- If an element the same as a exists in x, then the index of that element is returned. Otherwise, −1 is returned.
-
searchSorted
public static int searchSorted(int[] x, int a, Searching.Integer helper)Search the given ordered array of type int[] for the given element. The given helper object is used to compare elements for order and equality. It is assumed that the array is sorted in the order determined by the helper object; otherwise, the searchSorted() method's behavior is not specified. An O(log n) binary search algorithm is used.- Parameters:
x- Array to be searched.a- Element to be searched for.helper- Helper object.- Returns:
- If an element the same as a exists in x, then the index of that element is returned. Otherwise, −1 is returned.
-
searchUnsorted
public static int searchUnsorted(long[] x, long a, Searching.Long helper)Search the given unordered array of type long[] for the given element. The given helper object is used to compare elements for equality only. An O(n) linear search algorithm is used.- Parameters:
x- Array to be searched.a- Element to be searched for.helper- Helper object.- Returns:
- If an element the same as a exists in x, then the index of that element is returned. Otherwise, −1 is returned.
-
searchSorted
public static int searchSorted(long[] x, long a, Searching.Long helper)Search the given ordered array of type long[] for the given element. The given helper object is used to compare elements for order and equality. It is assumed that the array is sorted in the order determined by the helper object; otherwise, the searchSorted() method's behavior is not specified. An O(log n) binary search algorithm is used.- Parameters:
x- Array to be searched.a- Element to be searched for.helper- Helper object.- Returns:
- If an element the same as a exists in x, then the index of that element is returned. Otherwise, −1 is returned.
-
searchUnsorted
public static int searchUnsorted(float[] x, float a, Searching.Float helper)Search the given unordered array of type float[] for the given element. The given helper object is used to compare elements for equality only. An O(n) linear search algorithm is used.- Parameters:
x- Array to be searched.a- Element to be searched for.helper- Helper object.- Returns:
- If an element the same as a exists in x, then the index of that element is returned. Otherwise, −1 is returned.
-
searchSorted
public static int searchSorted(float[] x, float a, Searching.Float helper)Search the given ordered array of type float[] for the given element. The given helper object is used to compare elements for order and equality. It is assumed that the array is sorted in the order determined by the helper object; otherwise, the searchSorted() method's behavior is not specified. An O(log n) binary search algorithm is used.- Parameters:
x- Array to be searched.a- Element to be searched for.helper- Helper object.- Returns:
- If an element the same as a exists in x, then the index of that element is returned. Otherwise, −1 is returned.
-
searchUnsorted
public static int searchUnsorted(double[] x, double a, Searching.Double helper)Search the given unordered array of type double[] for the given element. The given helper object is used to compare elements for equality only. An O(n) linear search algorithm is used.- Parameters:
x- Array to be searched.a- Element to be searched for.helper- Helper object.- Returns:
- If an element the same as a exists in x, then the index of that element is returned. Otherwise, −1 is returned.
-
searchSorted
public static int searchSorted(double[] x, double a, Searching.Double helper)Search the given ordered array of type double[] for the given element. The given helper object is used to compare elements for order and equality. It is assumed that the array is sorted in the order determined by the helper object; otherwise, the searchSorted() method's behavior is not specified. An O(log n) binary search algorithm is used.- Parameters:
x- Array to be searched.a- Element to be searched for.helper- Helper object.- Returns:
- If an element the same as a exists in x, then the index of that element is returned. Otherwise, −1 is returned.
-
searchUnsorted
public static <T> int searchUnsorted(T[] x, T a, Searching.Object<T> helper)Search the given unordered array of type T[] for the given element. The given helper object is used to compare elements for equality only. An O(n) linear search algorithm is used.- Type Parameters:
T- Array element data type.- Parameters:
x- Array to be searched.a- Element to be searched for.helper- Helper object.- Returns:
- If an element the same as a exists in x, then the index of that element is returned. Otherwise, −1 is returned.
-
searchSorted
public static <T> int searchSorted(T[] x, T a, Searching.Object<T> helper)Search the given ordered array of type T[] for the given element. The given helper object is used to compare elements for order and equality. It is assumed that the array is sorted in the order determined by the helper object; otherwise, the searchSorted() method's behavior is not specified. An O(log n) binary search algorithm is used.- Type Parameters:
T- Array element data type.- Parameters:
x- Array to be searched.a- Element to be searched for.helper- Helper object.- Returns:
- If an element the same as a exists in x, then the index of that element is returned. Otherwise, −1 is returned.
-
searchUnsorted
public static <T> int searchUnsorted(T[] x, T a, java.util.Comparator<T> comp)Search the given unordered array of type T[] for the given element. The given comparator is used to compare elements for equality only. An O(n) linear search algorithm is used.- Type Parameters:
T- Array element data type.- Parameters:
x- Array to be searched.a- Element to be searched for.comp- Comparator.- Returns:
- If an element the same as a exists in x, then the index of that element is returned. Otherwise, −1 is returned.
-
searchSorted
public static <T> int searchSorted(T[] x, T a, java.util.Comparator<T> comp)Search the given ordered array of type T[] for the given element. The given comparator is used to compare elements for order and equality. It is assumed that the array is sorted in the order determined by the comparator; otherwise, the searchSorted() method's behavior is not specified. An O(log n) binary search algorithm is used.- Type Parameters:
T- Array element data type.- Parameters:
x- Array to be searched.a- Element to be searched for.comp- Comparator.- Returns:
- If an element the same as a exists in x, then the index of that element is returned. Otherwise, −1 is returned.
-
searchUnsorted
public static <T extends java.lang.Comparable> int searchUnsorted(T[] x, T a)Search the given unordered array of type T[] for the given element. The array element's natural ordering (compareTo() method) is used to compare elements for equality only. An O(n) linear search algorithm is used.- Type Parameters:
T- Array element data type.- Parameters:
x- Array to be searched.a- Element to be searched for.- Returns:
- If an element the same as a exists in x, then the index of that element is returned. Otherwise, −1 is returned.
-
searchSorted
public static <T extends java.lang.Comparable> int searchSorted(T[] x, T a)Search the given ordered array of type T[] for the given element. The array element's natural ordering (compareTo() method) is used to compare elements for order and equality. It is assumed that the array is sorted in the order determined by the natural ordering; otherwise, the searchSorted() method's behavior is not specified. An O(log n) binary search algorithm is used.- Type Parameters:
T- Array element data type.- Parameters:
x- Array to be searched.a- Element to be searched for.- Returns:
- If an element the same as a exists in x, then the index of that element is returned. Otherwise, −1 is returned.
-
-
DMelt 3.0 © DataMelt by jWork.ORG