com.alexkasko.unsafe.offheapstruct
public class OffHeapStructBinarySearchWithComparator extends Object
https://android.googlesource.com/platform/libcore/+/android-4.2.2_r1/luni/src/main/java/java/util/Arrays.java
and adapted to OffHeapStructCollection
with comparators.
Search methods are not static in this class to prevent internal comparator wrapper object creation on each search call.
All operations on instances of this class are NOT thread-safe.Modifier and Type | Field and Description |
---|---|
private OffHeapStructCollection |
col |
private OffHeapStructComparator |
comp |
Constructor and Description |
---|
OffHeapStructBinarySearchWithComparator(OffHeapStructCollection collection,
Comparator<OffHeapStructAccessor> comparator)
Constructor
|
Modifier and Type | Method and Description |
---|---|
long |
binarySearch(byte[] struct)
Performs a binary search for
value in the ascending sorted off-heap struct collection
comparing provided struct using comparator (both collection and comparator are bound to searcher instance). |
long |
binarySearch(long startIndex,
long endIndex,
byte[] struct)
Performs a binary search for
value in the ascending sorted off-heap struct collection
comparing provided struct using comparator (both collection and comparator are bound to searcher instance). |
void |
binarySearchRange(byte[] struct,
OffHeapStructBinarySearch.IndexRange out)
Performs a binary search for
value in the ascending sorted off-heap struct collection
comparing provided struct using comparator (both collection and comparator are bound to searcher instance). |
void |
binarySearchRange(long startIndex,
long endIndex,
byte[] struct,
OffHeapStructBinarySearch.IndexRange out)
Performs a binary search for
value in the ascending sorted off-heap struct collection
comparing provided struct using comparator (both collection and comparator are bound to searcher instance). |
String |
toString() |
private final OffHeapStructCollection col
private final OffHeapStructComparator comp
public OffHeapStructBinarySearchWithComparator(OffHeapStructCollection collection, Comparator<OffHeapStructAccessor> comparator)
collection
- collection to search overcomparator
- comparator to use for comparing provided structure while searchingpublic long binarySearch(byte[] struct)
value
in the ascending sorted off-heap struct collection
comparing provided struct using comparator (both collection and comparator are bound to searcher instance).
Searching in an unsorted collection has an undefined result. It's also undefined which element
is found if there are multiple occurrences of the same element.struct
- the structure to find-index - 1
where the element would be inserted.public long binarySearch(long startIndex, long endIndex, byte[] struct)
value
in the ascending sorted off-heap struct collection
comparing provided struct using comparator (both collection and comparator are bound to searcher instance).
in the range specified by fromIndex (inclusive) and toIndex (exclusive).
Searching in an unsorted collection has an undefined result. It's also undefined which element
is found if there are multiple occurrences of the same element.startIndex
- the inclusive start index.endIndex
- the exclusive end index.struct
- the structure to find-index - 1
where the element would be inserted.IllegalArgumentException
- if (startIndex < 0 || startIndex > endIndex || endIndex > collection.size()
public void binarySearchRange(byte[] struct, OffHeapStructBinarySearch.IndexRange out)
value
in the ascending sorted off-heap struct collection
comparing provided struct using comparator (both collection and comparator are bound to searcher instance).
Returns range of indices having given value or empty range.
Searching in an unsorted collection has an undefined result. It's also undefined which element
is found if there are multiple occurrences of the same element.struct
- the structure to findout
- range instance, will be set with start/end indices having given value or with empty valuepublic void binarySearchRange(long startIndex, long endIndex, byte[] struct, OffHeapStructBinarySearch.IndexRange out)
value
in the ascending sorted off-heap struct collection
comparing provided struct using comparator (both collection and comparator are bound to searcher instance).
Returns range of indices having given value or empty range.
Searching in an unsorted collection has an undefined result. It's also undefined which element
is found if there are multiple occurrences of the same element.startIndex
- the inclusive start index.endIndex
- the exclusive end index.struct
- the structure to findout
- range instance, will be set with start/end indices having given value or with empty valueCopyright © 2014. All Rights Reserved.