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
Modifier and TypeClassDescriptionstatic class
Class Searching.Byte is the base class for a helper object used to search an array of typebyte[]
.static class
Class Searching.Character is the base class for a helper object used to search an array of typechar[]
.static class
Class Searching.Double is the base class for a helper object used to search an array of typedouble[]
.static class
Class Searching.Float is the base class for a helper object used to search an array of typefloat[]
.static class
Class Searching.Integer is the base class for a helper object used to search an array of typeint[]
.static class
Class Searching.Long is the base class for a helper object used to search an array of typelong[]
.static class
Class Searching.Object is the base class for a helper object used to search an array of typeT[]
.static class
Class Searching.Short is the base class for a helper object used to search an array of typeshort[]
. -
Method Summary
Modifier and TypeMethodDescriptionstatic int
searchSorted
(byte[] x, byte a, Searching.Byte helper) Search the given ordered array of typebyte[]
for the given element.static int
searchSorted
(char[] x, char a, Searching.Character helper) Search the given ordered array of typechar[]
for the given element.static int
searchSorted
(double[] x, double a, Searching.Double helper) Search the given ordered array of typedouble[]
for the given element.static int
searchSorted
(float[] x, float a, Searching.Float helper) Search the given ordered array of typefloat[]
for the given element.static int
searchSorted
(int[] x, int a, Searching.Integer helper) Search the given ordered array of typeint[]
for the given element.static int
searchSorted
(long[] x, long a, Searching.Long helper) Search the given ordered array of typelong[]
for the given element.static int
searchSorted
(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> int
searchSorted
(T[] x, T a, Searching.Object<T> helper) Search the given ordered array of typeT[]
for the given element.static <T> int
searchSorted
(T[] x, T a, Comparator<T> comp) Search the given ordered array of typeT[]
for the given element.static int
searchUnsorted
(byte[] x, byte a, Searching.Byte helper) Search the given unordered array of typebyte[]
for the given element.static int
searchUnsorted
(char[] x, char a, Searching.Character helper) Search the given unordered array of typechar[]
for the given element.static int
searchUnsorted
(double[] x, double a, Searching.Double helper) Search the given unordered array of typedouble[]
for the given element.static int
searchUnsorted
(float[] x, float a, Searching.Float helper) Search the given unordered array of typefloat[]
for the given element.static int
searchUnsorted
(int[] x, int a, Searching.Integer helper) Search the given unordered array of typeint[]
for the given element.static int
searchUnsorted
(long[] x, long a, Searching.Long helper) Search the given unordered array of typelong[]
for the given element.static int
searchUnsorted
(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> int
searchUnsorted
(T[] x, T a, Searching.Object<T> helper) Search the given unordered array of typeT[]
for the given element.static <T> int
searchUnsorted
(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
a
exists 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
a
exists 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
a
exists 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
a
exists 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
a
exists 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
a
exists 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
a
exists 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
a
exists 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
a
exists 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
a
exists 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
a
exists 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
a
exists 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
a
exists 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
a
exists 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
a
exists 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
a
exists 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
a
exists 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
a
exists 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
a
exists 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
a
exists inx
, then the index of that element is returned. Otherwise, −1 is returned.
-