public class BinarySearch
extends java.lang.Object
Modifier | Constructor and Description |
---|---|
protected |
BinarySearch() |
Modifier and Type | Method and Description |
---|---|
static <T,K> int |
lowerBound(T[] a,
K key,
Function1<T,K> keySelector,
java.util.Comparator<K> comparator)
Performs binary search of the lower bound in the given array.
|
static <T,K> int |
lowerBound(T[] a,
K key,
int imin,
int imax,
Function1<T,K> keySelector,
java.util.Comparator<K> comparator)
Taken from http://en.wikipedia.org/wiki/Binary_search_algorithm
#Deferred_detection_of_equality
|
static <T> int |
lowerBound(T[] a,
T key,
java.util.Comparator<T> comparator)
Performs binary search of the lower bound in the given array.
|
static <T> int |
lowerBound(T[] a,
T key,
int imin,
int imax,
java.util.Comparator<T> comparator)
Performs binary search of the lower bound in the given section of array.
|
static <T,K> int |
upperBound(T[] a,
K key,
Function1<T,K> keySelector,
java.util.Comparator<K> comparator)
Performs binary search of the upper bound in the given array.
|
static <T,K> int |
upperBound(T[] a,
K key,
int imin,
int imax,
Function1<T,K> keySelector,
java.util.Comparator<K> comparator)
Taken from http://en.wikipedia.org/wiki/Binary_search_algorithm
#Deferred_detection_of_equality
Adapted to find upper bound.
|
static <T> int |
upperBound(T[] a,
T key,
java.util.Comparator<T> comparator)
Performs binary search of the upper bound in the given array.
|
static <T> int |
upperBound(T[] a,
T key,
int imin,
int imax,
java.util.Comparator<T> comparator)
Performs binary search of the upper bound in the given array.
|
public static <T> int lowerBound(T[] a, T key, java.util.Comparator<T> comparator)
T
- the type of elements in arraya
- array that holds the valueskey
- element to look forcomparator
- comparator that compares keysa.length
when all
elements are less than the given key.public static <T> int upperBound(T[] a, T key, java.util.Comparator<T> comparator)
T
- the type of elements in arraya
- array that holds the valueskey
- element to look forcomparator
- comparator that compares keysa.length
when
all elements exceed the given key.public static <T,K> int lowerBound(T[] a, K key, Function1<T,K> keySelector, java.util.Comparator<K> comparator)
T
- the type of elements in arrayK
- the type of lookup keya
- array that holds the valueskey
- element to look forkeySelector
- function that transforms array contents to the type
of the keycomparator
- comparator that compares keysa.length
when all
elements are less than the given key.public static <T,K> int upperBound(T[] a, K key, Function1<T,K> keySelector, java.util.Comparator<K> comparator)
T
- the type of elements in arrayK
- the type of lookup keya
- array that holds the valueskey
- element to look forkeySelector
- function that transforms array contents to the type
of the keycomparator
- comparator that compares keysa.length
when
all elements exceed the given key.public static <T> int lowerBound(T[] a, T key, int imin, int imax, java.util.Comparator<T> comparator)
T
- the type of elements in arraya
- array that holds the valueskey
- element to look forimin
- the minimal index (inclusive) to look forimax
- the maximum index (inclusive) to look forcomparator
- comparator that compares keysa.length
when all
elements are less than the given key.public static <T> int upperBound(T[] a, T key, int imin, int imax, java.util.Comparator<T> comparator)
T
- the type of elements in arraya
- array that holds the valueskey
- element to look forimin
- the minimal index (inclusive) to look forimax
- the maximum index (inclusive) to look forcomparator
- comparator that compares keysa.length
when
all elements exceed the given key.public static <T,K> int lowerBound(T[] a, K key, int imin, int imax, Function1<T,K> keySelector, java.util.Comparator<K> comparator)
public static <T,K> int upperBound(T[] a, K key, int imin, int imax, Function1<T,K> keySelector, java.util.Comparator<K> comparator)
Copyright © 2012–2019 The Apache Software Foundation. All rights reserved.