Package edu.rit.util
Class Searching
java.lang.Object
edu.rit.util.Searching
Class Searching provides static methods for searching arrays of primitive
types and object types.
Note: The operations in class Searching are not multiple thread safe.
- Version:
- 22-Nov-2011
- Author:
- Alan Kaminsky
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classClass Searching.Byte is the base class for a helper object used to search an array of typebyte[].static classClass Searching.Character is the base class for a helper object used to search an array of typechar[].static classClass Searching.Double is the base class for a helper object used to search an array of typedouble[].static classClass Searching.Float is the base class for a helper object used to search an array of typefloat[].static classClass Searching.Integer is the base class for a helper object used to search an array of typeint[].static classClass Searching.Long is the base class for a helper object used to search an array of typelong[].static classClass Searching.Object is the base class for a helper object used to search an array of typeT[].static classClass Searching.Short is the base class for a helper object used to search an array of typeshort[]. -
Method Summary
Modifier and TypeMethodDescriptionstatic intsearchSorted(byte[] x, byte a, Searching.Byte helper) Search the given ordered array of typebyte[]for the given element.static intsearchSorted(char[] x, char a, Searching.Character helper) Search the given ordered array of typechar[]for the given element.static intsearchSorted(double[] x, double a, Searching.Double helper) Search the given ordered array of typedouble[]for the given element.static intsearchSorted(float[] x, float a, Searching.Float helper) Search the given ordered array of typefloat[]for the given element.static intsearchSorted(int[] x, int a, Searching.Integer helper) Search the given ordered array of typeint[]for the given element.static intsearchSorted(long[] x, long a, Searching.Long helper) Search the given ordered array of typelong[]for the given element.static intsearchSorted(short[] x, short a, Searching.Short helper) Search the given ordered array of typeshort[]for the given element.static <T extends Comparable<T>>
intsearchSorted(T[] x, T a) Search the given ordered array of typeT[]for the given element.static <T> intsearchSorted(T[] x, T a, Searching.Object<T> helper) Search the given ordered array of typeT[]for the given element.static <T> intsearchSorted(T[] x, T a, Comparator<T> comp) Search the given ordered array of typeT[]for the given element.static intsearchUnsorted(byte[] x, byte a, Searching.Byte helper) Search the given unordered array of typebyte[]for the given element.static intsearchUnsorted(char[] x, char a, Searching.Character helper) Search the given unordered array of typechar[]for the given element.static intsearchUnsorted(double[] x, double a, Searching.Double helper) Search the given unordered array of typedouble[]for the given element.static intsearchUnsorted(float[] x, float a, Searching.Float helper) Search the given unordered array of typefloat[]for the given element.static intsearchUnsorted(int[] x, int a, Searching.Integer helper) Search the given unordered array of typeint[]for the given element.static intsearchUnsorted(long[] x, long a, Searching.Long helper) Search the given unordered array of typelong[]for the given element.static intsearchUnsorted(short[] x, short a, Searching.Short helper) Search the given unordered array of typeshort[]for the given element.static <T extends Comparable<T>>
intsearchUnsorted(T[] x, T a) Search the given unordered array of typeT[]for the given element.static <T> intsearchUnsorted(T[] x, T a, Searching.Object<T> helper) Search the given unordered array of typeT[]for the given element.static <T> intsearchUnsorted(T[] x, T a, Comparator<T> comp) Search the given unordered array of typeT[]for the given element.
-
Method Details
-
searchUnsorted
Search the given unordered array of typebyte[]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
aexists inx, then the index of that element is returned. Otherwise, −1 is returned.
-
searchSorted
Search the given ordered array of typebyte[]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, thesearchSorted()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
aexists inx, then the index of that element is returned. Otherwise, −1 is returned.
-
searchUnsorted
Search the given unordered array of typechar[]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
aexists inx, then the index of that element is returned. Otherwise, −1 is returned.
-
searchSorted
Search the given ordered array of typechar[]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, thesearchSorted()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
aexists inx, then the index of that element is returned. Otherwise, −1 is returned.
-
searchUnsorted
Search the given unordered array of typeshort[]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
aexists inx, then the index of that element is returned. Otherwise, −1 is returned.
-
searchSorted
Search the given ordered array of typeshort[]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, thesearchSorted()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
aexists inx, then the index of that element is returned. Otherwise, −1 is returned.
-
searchUnsorted
Search the given unordered array of typeint[]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
aexists inx, then the index of that element is returned. Otherwise, −1 is returned.
-
searchSorted
Search the given ordered array of typeint[]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, thesearchSorted()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
aexists inx, then the index of that element is returned. Otherwise, −1 is returned.
-
searchUnsorted
Search the given unordered array of typelong[]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
aexists inx, then the index of that element is returned. Otherwise, −1 is returned.
-
searchSorted
Search the given ordered array of typelong[]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, thesearchSorted()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
aexists inx, then the index of that element is returned. Otherwise, −1 is returned.
-
searchUnsorted
Search the given unordered array of typefloat[]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
aexists inx, then the index of that element is returned. Otherwise, −1 is returned.
-
searchSorted
Search the given ordered array of typefloat[]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, thesearchSorted()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
aexists inx, then the index of that element is returned. Otherwise, −1 is returned.
-
searchUnsorted
Search the given unordered array of typedouble[]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
aexists inx, then the index of that element is returned. Otherwise, −1 is returned.
-
searchSorted
Search the given ordered array of typedouble[]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, thesearchSorted()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
aexists inx, then the index of that element is returned. Otherwise, −1 is returned.
-
searchUnsorted
Search the given unordered array of typeT[]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
aexists inx, then the index of that element is returned. Otherwise, −1 is returned.
-
searchSorted
Search the given ordered array of typeT[]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, thesearchSorted()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
aexists inx, then the index of that element is returned. Otherwise, −1 is returned.
-
searchUnsorted
Search the given unordered array of typeT[]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
aexists inx, then the index of that element is returned. Otherwise, −1 is returned.
-
searchSorted
Search the given ordered array of typeT[]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, thesearchSorted()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
aexists inx, then the index of that element is returned. Otherwise, −1 is returned.
-
searchUnsorted
Search the given unordered array of typeT[]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- Class that extends Comparable.- Parameters:
x- Array to be searched.a- Element to be searched for.- Returns:
- If an element the same as
aexists inx, then the index of that element is returned. Otherwise, −1 is returned.
-
searchSorted
Search the given ordered array of typeT[]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, thesearchSorted()method's behavior is not specified. An O(log n) binary search algorithm is used.- Type Parameters:
T- Class that extends Comparable.- Parameters:
x- Array to be searched.a- Element to be searched for.- Returns:
- If an element the same as
aexists inx, then the index of that element is returned. Otherwise, −1 is returned.
-