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 indicies 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 an array of values arr[] and the search key value v, the algorithms for the searching criteria are as follows:
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.
|
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.
|
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.
|
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.
|
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
public static final InequalitySearch LE
public static final InequalitySearch EQ
public static final InequalitySearch GE
public static final InequalitySearch GT
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.low
- the index of the lowest value in the search rangehigh
- the index of the highest value in the search rangev
- the value to search for.crit
- one of LT, LE, EQ, GT, GEpublic static int find(float[] arr, int low, int high, float v, InequalitySearch crit)
arr
- the given array that must be sorted.low
- the index of the lowest value in the search rangehigh
- the index of the highest value in the search rangev
- the value to search for.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 index of the lowest value in the search rangehigh
- the index of the highest value in the search rangev
- the value to search for.crit
- one of LT, LE, EQ, GT, GECopyright © 2015–2021 The Apache Software Foundation. All rights reserved.