public enum InequalitySearch extends Enum<InequalitySearch>
In order to make the searching unique and unambiguous, we modified the traditional binary search algorithm to search for adjacent pairs of values {A, B} in the values array instead of just a single value, where A and B are the array indices of two adjacent values in the array. For all the search criteria, if the algorithm reaches the ends of the search range, the algorithm calls the resolve() method to determine what to return to the caller. If the key value cannot be resolved, it returns a -1 to the caller.
Given a sorted array of values arr[] and the search key value v, the algorithms for the searching criteria are given with each enum criterion.
| Enum Constant and Description |
|---|
EQ
Given a sorted array of increasing values arr[] and a key value V,
this criterion instructs the binary search algorithm to find the adjacent pair of
values {A,B} such that A ≤ V ≤ B.
|
GE
Given a sorted array of increasing values arr[] and a key value V,
this criterion instructs the binary search algorithm to find the lowest adjacent pair of
values {A,B} such that A < V ≤ B.
Let low = lowest index of the lowest value in the range. Let high = highest index of the highest value in the range. |
GT
Given a sorted array of increasing values arr[] and a key value V,
this criterion instructs the binary search algorithm to find the lowest adjacent pair of
values {A,B} such that A ≤ V < B.
Let low = lowest index of the lowest value in the range. Let high = highest index of the highest value in the range. |
LE
Given a sorted array of increasing values arr[] and a key value V,
this criterion instructs the binary search algorithm to find the highest adjacent pair of
values {A,B} such that A ≤ V < B.
Let low = lowest index of the lowest value in the range. Let high = highest index of the highest value in the range. |
LT
Given a sorted array of increasing values arr[] and a key value v,
this criterion instructs the binary search algorithm to find the highest adjacent pair of
values {A,B} such that A < v ≤ B.
Let low = lowest index of the lowest value in the range. Let high = highest index of the highest value in the range. |
| Modifier and Type | Method and Description |
|---|---|
static int |
find(double[] arr,
int low,
int high,
double v,
InequalitySearch crit)
Binary Search for the index of the double value in the given search range that satisfies
the given InequalitySearch criterion.
|
static int |
find(float[] arr,
int low,
int high,
float v,
InequalitySearch crit)
Binary Search for the index of the float value in the given search range that satisfies
the given InequalitySearch criterion.
|
static int |
find(long[] arr,
int low,
int high,
long v,
InequalitySearch crit)
Binary Search for the index of the long value in the given search range that satisfies
the given InequalitySearch criterion.
|
static InequalitySearch |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static InequalitySearch[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final InequalitySearch LT
If v > arr[high], return arr[high].
If v ≤ arr[low], return -1.
Else return index of A.
public static final InequalitySearch LE
If v ≥ arr[high], return arr[high].
If v < arr[low], return -1.
Else return index of A.
public static final InequalitySearch EQ
public static final InequalitySearch GE
If v ≤ arr[low], return arr[low].
If v > arr[high], return -1.
Else return index of B.
public static final InequalitySearch GT
If v < arr[low], return arr[low].
If v ≥ arr[high], return -1.
Else return index of B.
public static InequalitySearch[] values()
for (InequalitySearch c : InequalitySearch.values()) System.out.println(c);
public static InequalitySearch valueOf(String name)
name - the name of the enum constant to be returned.IllegalArgumentException - if this enum type has no constant with the specified nameNullPointerException - if the argument is nullpublic static int find(double[] arr,
int low,
int high,
double v,
InequalitySearch crit)
arr - the given array that must be sorted.
It must not be null and must not contain any NaN values in the range {low, high} inclusive.low - the lowest index of the lowest value in the search range, inclusive.high - the highest index of the highest value in the search range, inclusive.v - the value to search for. It must not be NaN.crit - one of LT, LE, EQ, GT, GE. It must not be null.public static int find(float[] arr,
int low,
int high,
float v,
InequalitySearch crit)
arr - the given array that must be sorted.
It must not be null and must not contain any NaN values in the range {low, high} inclusive.low - the lowest index of the lowest value in the search range, inclusive.high - the highest index of the highest value in the search range, inclusive.v - the value to search for. It must not be NaN.crit - one of LT, LE, EQ, GT, GEpublic static int find(long[] arr,
int low,
int high,
long v,
InequalitySearch crit)
arr - the given array that must be sorted.low - the lowest index of the lowest value in the search range, inclusive.high - the highest index of the highest value in the search range, inclusive.v - the value to search for.crit - one of LT, LE, EQ, GT, GECopyright © 2015–2020 The Apache Software Foundation. All rights reserved.