Enum Class BufferSearch

java.lang.Object
java.lang.Enum<BufferSearch>
tech.bitey.bufferstuff.BufferSearch
All Implemented Interfaces:
Serializable, Comparable<BufferSearch>, Constable

public enum BufferSearch extends Enum<BufferSearch>
Provides the primitive array binary search implementations from java.util.Arrays, modified with minimal changes to support nio buffers.

Also provides methods for finding the first or last index of a sequence of duplicate values.

Author:
biteytech@protonmail.com, adapted from java.util.Arrays
  • Method Details

    • values

      public static BufferSearch[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static BufferSearch valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • binarySearch

      public static int binarySearch(IntBuffer b, int fromIndex, int toIndex, int key)
      Searches a range of the specified IntBuffer for the specified value using the binary search algorithm. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined. If the range contains multiple elements with the specified value, there is no guarantee which one will be found.
      Parameters:
      b - the buffer to be searched
      fromIndex - the index of the first element (inclusive) to be searched
      toIndex - the index of the last element (exclusive) to be searched
      key - the value to be searched for
      Returns:
      index of the search key, if it is contained in the buffer within the specified range; otherwise, (-(<i>insertion point</i>) - 1). The insertion point is defined as the point at which the key would be inserted into the buffer: the index of the first element in the range greater than the key, or toIndex if all elements in the range are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found.
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • binarySearch

      public static int binarySearch(LongBuffer b, int fromIndex, int toIndex, long key)
      Searches a range of the specified LongBuffer for the specified value using the binary search algorithm. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined. If the range contains multiple elements with the specified value, there is no guarantee which one will be found.
      Parameters:
      b - the buffer to be searched
      fromIndex - the index of the first element (inclusive) to be searched
      toIndex - the index of the last element (exclusive) to be searched
      key - the value to be searched for
      Returns:
      index of the search key, if it is contained in the buffer within the specified range; otherwise, (-(<i>insertion point</i>) - 1). The insertion point is defined as the point at which the key would be inserted into the buffer: the index of the first element in the range greater than the key, or toIndex if all elements in the range are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found.
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • binarySearch

      public static int binarySearch(ShortBuffer b, int fromIndex, int toIndex, short key)
      Searches a range of the specified ShortBuffer for the specified value using the binary search algorithm. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined. If the range contains multiple elements with the specified value, there is no guarantee which one will be found.
      Parameters:
      b - the buffer to be searched
      fromIndex - the index of the first element (inclusive) to be searched
      toIndex - the index of the last element (exclusive) to be searched
      key - the value to be searched for
      Returns:
      index of the search key, if it is contained in the buffer within the specified range; otherwise, (-(<i>insertion point</i>) - 1). The insertion point is defined as the point at which the key would be inserted into the buffer: the index of the first element in the range greater than the key, or toIndex if all elements in the range are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found.
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • binarySearch

      public static int binarySearch(ByteBuffer b, int fromIndex, int toIndex, byte key)
      Searches a range of the specified ByteBuffer for the specified value using the binary search algorithm. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined. If the range contains multiple elements with the specified value, there is no guarantee which one will be found.
      Parameters:
      b - the buffer to be searched
      fromIndex - the index of the first element (inclusive) to be searched
      toIndex - the index of the last element (exclusive) to be searched
      key - the value to be searched for
      Returns:
      index of the search key, if it is contained in the buffer within the specified range; otherwise, (-(<i>insertion point</i>) - 1). The insertion point is defined as the point at which the key would be inserted into the buffer: the index of the first element in the range greater than the key, or toIndex if all elements in the range are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found.
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • binarySearch

      public static int binarySearch(FloatBuffer b, int fromIndex, int toIndex, float key)
      Searches a range of the specified FloatBuffer for the specified value using the binary search algorithm. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined. If the range contains multiple elements with the specified value, there is no guarantee which one will be found. This method considers all NaN values to be equivalent and equal.
      Parameters:
      b - the buffer to be searched
      fromIndex - the index of the first element (inclusive) to be searched
      toIndex - the index of the last element (exclusive) to be searched
      key - the value to be searched for
      Returns:
      index of the search key, if it is contained in the buffer within the specified range; otherwise, (-(<i>insertion point</i>) - 1). The insertion point is defined as the point at which the key would be inserted into the buffer: the index of the first element in the range greater than the key, or toIndex if all elements in the range are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found.
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • binarySearch

      public static int binarySearch(DoubleBuffer b, int fromIndex, int toIndex, double key)
      Searches a range of the specified DoubleBuffer for the specified value using the binary search algorithm. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined. If the range contains multiple elements with the specified value, there is no guarantee which one will be found. This method considers all NaN values to be equivalent and equal.
      Parameters:
      b - the buffer to be searched
      fromIndex - the index of the first element (inclusive) to be searched
      toIndex - the index of the last element (exclusive) to be searched
      key - the value to be searched for
      Returns:
      index of the search key, if it is contained in the buffer within the specified range; otherwise, (-(<i>insertion point</i>) - 1). The insertion point is defined as the point at which the key would be inserted into the buffer: the index of the first element in the range greater than the key, or toIndex if all elements in the range are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found.
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • binaryFindFirst

      public static int binaryFindFirst(IntBuffer b, int minIndex, int keyIndex)
      Searches a range of the specified IntBuffer for the first occurrence of the value at the given keyIndex. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined.

      This method is useful as a post-processing step after a binary search on a buffer which contains duplicate elements.

      Parameters:
      b - the buffer to be searched
      minIndex - the lowest index to be searched
      keyIndex - an index of the value for which to find the first occurrence (inclusive)
      Returns:
      index of the first occurrence of the value at keyIndex
      Throws:
      IllegalArgumentException - if minIndex > keyIndex
      IndexOutOfBoundsException - if minIndex < 0 or keyIndex >= b.capacity()
    • binaryFindLast

      public static int binaryFindLast(IntBuffer b, int maxIndex, int keyIndex)
      Searches a range of the specified IntBuffer for the last occurrence of the value at the given keyIndex. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined.

      This method is useful as a post-processing step after a binary search on a buffer which contains duplicate elements.

      Parameters:
      b - the buffer to be searched
      maxIndex - the highest index to be searched (exclusive)
      keyIndex - an index of the value for which to find the first occurrence (inclusive)
      Returns:
      index of the last occurrence of the value at keyIndex
      Throws:
      IllegalArgumentException - if maxIndex < keyIndex
      IndexOutOfBoundsException - if keyIndex < 0 or maxIndex > b.capacity()
    • binaryFindFirst

      public static int binaryFindFirst(LongBuffer b, int minIndex, int keyIndex)
      Searches a range of the specified LongBuffer for the first occurrence of the value at the given keyIndex. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined.

      This method is useful as a post-processing step after a binary search on a buffer which contains duplicate elements.

      Parameters:
      b - the buffer to be searched
      minIndex - the lowest index to be searched
      keyIndex - an index of the value for which to find the first occurrence (inclusive)
      Returns:
      index of the first occurrence of the value at keyIndex
      Throws:
      IllegalArgumentException - if minIndex > keyIndex
      IndexOutOfBoundsException - if minIndex < 0 or keyIndex >= b.capacity()
    • binaryFindLast

      public static int binaryFindLast(LongBuffer b, int maxIndex, int keyIndex)
      Searches a range of the specified LongBuffer for the last occurrence of the value at the given keyIndex. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined.

      This method is useful as a post-processing step after a binary search on a buffer which contains duplicate elements.

      Parameters:
      b - the buffer to be searched
      maxIndex - the highest index to be searched (exclusive)
      keyIndex - an index of the value for which to find the first occurrence (inclusive)
      Returns:
      index of the last occurrence of the value at keyIndex
      Throws:
      IllegalArgumentException - if maxIndex < keyIndex
      IndexOutOfBoundsException - if keyIndex < 0 or maxIndex > b.capacity()
    • binaryFindFirst

      public static int binaryFindFirst(ShortBuffer b, int minIndex, int keyIndex)
      Searches a range of the specified ShortBuffer for the first occurrence of the value at the given keyIndex. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined.

      This method is useful as a post-processing step after a binary search on a buffer which contains duplicate elements.

      Parameters:
      b - the buffer to be searched
      minIndex - the lowest index to be searched
      keyIndex - an index of the value for which to find the first occurrence (inclusive)
      Returns:
      index of the first occurrence of the value at keyIndex
      Throws:
      IllegalArgumentException - if minIndex > keyIndex
      IndexOutOfBoundsException - if minIndex < 0 or keyIndex >= b.capacity()
    • binaryFindLast

      public static int binaryFindLast(ShortBuffer b, int maxIndex, int keyIndex)
      Searches a range of the specified ShortBuffer for the last occurrence of the value at the given keyIndex. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined.

      This method is useful as a post-processing step after a binary search on a buffer which contains duplicate elements.

      Parameters:
      b - the buffer to be searched
      maxIndex - the highest index to be searched (exclusive)
      keyIndex - an index of the value for which to find the first occurrence (inclusive)
      Returns:
      index of the last occurrence of the value at keyIndex
      Throws:
      IllegalArgumentException - if maxIndex < keyIndex
      IndexOutOfBoundsException - if keyIndex < 0 or maxIndex > b.capacity()
    • binaryFindFirst

      public static int binaryFindFirst(ByteBuffer b, int minIndex, int keyIndex)
      Searches a range of the specified ByteBuffer for the first occurrence of the value at the given keyIndex. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined.

      This method is useful as a post-processing step after a binary search on a buffer which contains duplicate elements.

      Parameters:
      b - the buffer to be searched
      minIndex - the lowest index to be searched
      keyIndex - an index of the value for which to find the first occurrence (inclusive)
      Returns:
      index of the first occurrence of the value at keyIndex
      Throws:
      IllegalArgumentException - if minIndex > keyIndex
      IndexOutOfBoundsException - if minIndex < 0 or keyIndex >= b.capacity()
    • binaryFindLast

      public static int binaryFindLast(ByteBuffer b, int maxIndex, int keyIndex)
      Searches a range of the specified ByteBuffer for the last occurrence of the value at the given keyIndex. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined.

      This method is useful as a post-processing step after a binary search on a buffer which contains duplicate elements.

      Parameters:
      b - the buffer to be searched
      maxIndex - the highest index to be searched (exclusive)
      keyIndex - an index of the value for which to find the first occurrence (inclusive)
      Returns:
      index of the last occurrence of the value at keyIndex
      Throws:
      IllegalArgumentException - if maxIndex < keyIndex
      IndexOutOfBoundsException - if keyIndex < 0 or maxIndex > b.capacity()
    • binaryFindFirst

      public static int binaryFindFirst(FloatBuffer b, int minIndex, int keyIndex)
      Searches a range of the specified FloatBuffer for the first occurrence of the value at the given keyIndex. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined. This method considers all NaN values to be equivalent and equal.

      This method is useful as a post-processing step after a binary search on a buffer which contains duplicate elements.

      Parameters:
      b - the buffer to be searched
      minIndex - the lowest index to be searched
      keyIndex - an index of the value for which to find the first occurrence (inclusive)
      Returns:
      index of the first occurrence of the value at keyIndex
      Throws:
      IllegalArgumentException - if minIndex > keyIndex
      IndexOutOfBoundsException - if minIndex < 0 or keyIndex >= b.capacity()
    • binaryFindLast

      public static int binaryFindLast(FloatBuffer b, int maxIndex, int keyIndex)
      Searches a range of the specified FloatBuffer for the last occurrence of the value at the given keyIndex. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined. This method considers all NaN values to be equivalent and equal.

      This method is useful as a post-processing step after a binary search on a buffer which contains duplicate elements.

      Parameters:
      b - the buffer to be searched
      maxIndex - the highest index to be searched (exclusive)
      keyIndex - an index of the value for which to find the first occurrence (inclusive)
      Returns:
      index of the last occurrence of the value at keyIndex
      Throws:
      IllegalArgumentException - if maxIndex < keyIndex
      IndexOutOfBoundsException - if keyIndex < 0 or maxIndex > b.capacity()
    • binaryFindFirst

      public static int binaryFindFirst(DoubleBuffer b, int minIndex, int keyIndex)
      Searches a range of the specified DoubleBuffer for the first occurrence of the value at the given keyIndex. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined. This method considers all NaN values to be equivalent and equal.

      This method is useful as a post-processing step after a binary search on a buffer which contains duplicate elements.

      Parameters:
      b - the buffer to be searched
      minIndex - the lowest index to be searched
      keyIndex - an index of the value for which to find the first occurrence (inclusive)
      Returns:
      index of the first occurrence of the value at keyIndex
      Throws:
      IllegalArgumentException - if minIndex > keyIndex
      IndexOutOfBoundsException - if minIndex < 0 or keyIndex >= b.capacity()
    • binaryFindLast

      public static int binaryFindLast(DoubleBuffer b, int maxIndex, int keyIndex)
      Searches a range of the specified DoubleBuffer for the last occurrence of the value at the given keyIndex. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined. This method considers all NaN values to be equivalent and equal.

      This method is useful as a post-processing step after a binary search on a buffer which contains duplicate elements.

      Parameters:
      b - the buffer to be searched
      maxIndex - the highest index to be searched (exclusive)
      keyIndex - an index of the value for which to find the first occurrence (inclusive)
      Returns:
      index of the last occurrence of the value at keyIndex
      Throws:
      IllegalArgumentException - if maxIndex < keyIndex
      IndexOutOfBoundsException - if keyIndex < 0 or maxIndex > b.capacity()
    • binarySearch

      public static int binarySearch(SmallIntBuffer b, int fromIndex, int toIndex, int key)
      Searches a range of the specified SmallIntBuffer for the specified value using the binary search algorithm. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined. If the range contains multiple elements with the specified value, there is no guarantee which one will be found.
      Parameters:
      b - the buffer to be searched
      fromIndex - the index of the first element (inclusive) to be searched
      toIndex - the index of the last element (exclusive) to be searched
      key - the value to be searched for
      Returns:
      index of the search key, if it is contained in the buffer within the specified range; otherwise, (-(<i>insertion point</i>) - 1). The insertion point is defined as the point at which the key would be inserted into the buffer: the index of the first element in the range greater than the key, or toIndex if all elements in the range are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found.
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • binarySearch

      public static int binarySearch(SmallLongBuffer b, int fromIndex, int toIndex, long key)
      Searches a range of the specified SmallLongBuffer for the specified value using the binary search algorithm. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined. If the range contains multiple elements with the specified value, there is no guarantee which one will be found.
      Parameters:
      b - the buffer to be searched
      fromIndex - the index of the first element (inclusive) to be searched
      toIndex - the index of the last element (exclusive) to be searched
      key - the value to be searched for
      Returns:
      index of the search key, if it is contained in the buffer within the specified range; otherwise, (-(<i>insertion point</i>) - 1). The insertion point is defined as the point at which the key would be inserted into the buffer: the index of the first element in the range greater than the key, or toIndex if all elements in the range are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found.
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • binarySearch

      public static int binarySearch(SmallShortBuffer b, int fromIndex, int toIndex, short key)
      Searches a range of the specified SmallShortBuffer for the specified value using the binary search algorithm. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined. If the range contains multiple elements with the specified value, there is no guarantee which one will be found.
      Parameters:
      b - the buffer to be searched
      fromIndex - the index of the first element (inclusive) to be searched
      toIndex - the index of the last element (exclusive) to be searched
      key - the value to be searched for
      Returns:
      index of the search key, if it is contained in the buffer within the specified range; otherwise, (-(<i>insertion point</i>) - 1). The insertion point is defined as the point at which the key would be inserted into the buffer: the index of the first element in the range greater than the key, or toIndex if all elements in the range are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found.
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • binarySearch

      public static int binarySearch(SmallByteBuffer b, int fromIndex, int toIndex, byte key)
      Searches a range of the specified SmallByteBuffer for the specified value using the binary search algorithm. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined. If the range contains multiple elements with the specified value, there is no guarantee which one will be found.
      Parameters:
      b - the buffer to be searched
      fromIndex - the index of the first element (inclusive) to be searched
      toIndex - the index of the last element (exclusive) to be searched
      key - the value to be searched for
      Returns:
      index of the search key, if it is contained in the buffer within the specified range; otherwise, (-(<i>insertion point</i>) - 1). The insertion point is defined as the point at which the key would be inserted into the buffer: the index of the first element in the range greater than the key, or toIndex if all elements in the range are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found.
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • binarySearch

      public static int binarySearch(SmallFloatBuffer b, int fromIndex, int toIndex, float key)
      Searches a range of the specified SmallFloatBuffer for the specified value using the binary search algorithm. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined. If the range contains multiple elements with the specified value, there is no guarantee which one will be found. This method considers all NaN values to be equivalent and equal.
      Parameters:
      b - the buffer to be searched
      fromIndex - the index of the first element (inclusive) to be searched
      toIndex - the index of the last element (exclusive) to be searched
      key - the value to be searched for
      Returns:
      index of the search key, if it is contained in the buffer within the specified range; otherwise, (-(<i>insertion point</i>) - 1). The insertion point is defined as the point at which the key would be inserted into the buffer: the index of the first element in the range greater than the key, or toIndex if all elements in the range are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found.
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • binarySearch

      public static int binarySearch(SmallDoubleBuffer b, int fromIndex, int toIndex, double key)
      Searches a range of the specified SmallDoubleBuffer for the specified value using the binary search algorithm. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined. If the range contains multiple elements with the specified value, there is no guarantee which one will be found. This method considers all NaN values to be equivalent and equal.
      Parameters:
      b - the buffer to be searched
      fromIndex - the index of the first element (inclusive) to be searched
      toIndex - the index of the last element (exclusive) to be searched
      key - the value to be searched for
      Returns:
      index of the search key, if it is contained in the buffer within the specified range; otherwise, (-(<i>insertion point</i>) - 1). The insertion point is defined as the point at which the key would be inserted into the buffer: the index of the first element in the range greater than the key, or toIndex if all elements in the range are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found.
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • binaryFindFirst

      public static int binaryFindFirst(SmallIntBuffer b, int minIndex, int keyIndex)
      Searches a range of the specified SmallIntBuffer for the first occurrence of the value at the given keyIndex. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined.

      This method is useful as a post-processing step after a binary search on a buffer which contains duplicate elements.

      Parameters:
      b - the buffer to be searched
      minIndex - the lowest index to be searched
      keyIndex - an index of the value for which to find the first occurrence (inclusive)
      Returns:
      index of the first occurrence of the value at keyIndex
      Throws:
      IllegalArgumentException - if minIndex > keyIndex
      IndexOutOfBoundsException - if minIndex < 0 or keyIndex >= b.capacity()
    • binaryFindLast

      public static int binaryFindLast(SmallIntBuffer b, int maxIndex, int keyIndex)
      Searches a range of the specified SmallIntBuffer for the last occurrence of the value at the given keyIndex. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined.

      This method is useful as a post-processing step after a binary search on a buffer which contains duplicate elements.

      Parameters:
      b - the buffer to be searched
      maxIndex - the highest index to be searched (exclusive)
      keyIndex - an index of the value for which to find the first occurrence (inclusive)
      Returns:
      index of the last occurrence of the value at keyIndex
      Throws:
      IllegalArgumentException - if maxIndex < keyIndex
      IndexOutOfBoundsException - if keyIndex < 0 or maxIndex > b.capacity()
    • binaryFindFirst

      public static int binaryFindFirst(SmallLongBuffer b, int minIndex, int keyIndex)
      Searches a range of the specified SmallLongBuffer for the first occurrence of the value at the given keyIndex. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined.

      This method is useful as a post-processing step after a binary search on a buffer which contains duplicate elements.

      Parameters:
      b - the buffer to be searched
      minIndex - the lowest index to be searched
      keyIndex - an index of the value for which to find the first occurrence (inclusive)
      Returns:
      index of the first occurrence of the value at keyIndex
      Throws:
      IllegalArgumentException - if minIndex > keyIndex
      IndexOutOfBoundsException - if minIndex < 0 or keyIndex >= b.capacity()
    • binaryFindLast

      public static int binaryFindLast(SmallLongBuffer b, int maxIndex, int keyIndex)
      Searches a range of the specified SmallLongBuffer for the last occurrence of the value at the given keyIndex. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined.

      This method is useful as a post-processing step after a binary search on a buffer which contains duplicate elements.

      Parameters:
      b - the buffer to be searched
      maxIndex - the highest index to be searched (exclusive)
      keyIndex - an index of the value for which to find the first occurrence (inclusive)
      Returns:
      index of the last occurrence of the value at keyIndex
      Throws:
      IllegalArgumentException - if maxIndex < keyIndex
      IndexOutOfBoundsException - if keyIndex < 0 or maxIndex > b.capacity()
    • binaryFindFirst

      public static int binaryFindFirst(SmallShortBuffer b, int minIndex, int keyIndex)
      Searches a range of the specified SmallShortBuffer for the first occurrence of the value at the given keyIndex. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined.

      This method is useful as a post-processing step after a binary search on a buffer which contains duplicate elements.

      Parameters:
      b - the buffer to be searched
      minIndex - the lowest index to be searched
      keyIndex - an index of the value for which to find the first occurrence (inclusive)
      Returns:
      index of the first occurrence of the value at keyIndex
      Throws:
      IllegalArgumentException - if minIndex > keyIndex
      IndexOutOfBoundsException - if minIndex < 0 or keyIndex >= b.capacity()
    • binaryFindLast

      public static int binaryFindLast(SmallShortBuffer b, int maxIndex, int keyIndex)
      Searches a range of the specified SmallShortBuffer for the last occurrence of the value at the given keyIndex. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined.

      This method is useful as a post-processing step after a binary search on a buffer which contains duplicate elements.

      Parameters:
      b - the buffer to be searched
      maxIndex - the highest index to be searched (exclusive)
      keyIndex - an index of the value for which to find the first occurrence (inclusive)
      Returns:
      index of the last occurrence of the value at keyIndex
      Throws:
      IllegalArgumentException - if maxIndex < keyIndex
      IndexOutOfBoundsException - if keyIndex < 0 or maxIndex > b.capacity()
    • binaryFindFirst

      public static int binaryFindFirst(SmallByteBuffer b, int minIndex, int keyIndex)
      Searches a range of the specified SmallByteBuffer for the first occurrence of the value at the given keyIndex. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined.

      This method is useful as a post-processing step after a binary search on a buffer which contains duplicate elements.

      Parameters:
      b - the buffer to be searched
      minIndex - the lowest index to be searched
      keyIndex - an index of the value for which to find the first occurrence (inclusive)
      Returns:
      index of the first occurrence of the value at keyIndex
      Throws:
      IllegalArgumentException - if minIndex > keyIndex
      IndexOutOfBoundsException - if minIndex < 0 or keyIndex >= b.capacity()
    • binaryFindLast

      public static int binaryFindLast(SmallByteBuffer b, int maxIndex, int keyIndex)
      Searches a range of the specified SmallByteBuffer for the last occurrence of the value at the given keyIndex. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined.

      This method is useful as a post-processing step after a binary search on a buffer which contains duplicate elements.

      Parameters:
      b - the buffer to be searched
      maxIndex - the highest index to be searched (exclusive)
      keyIndex - an index of the value for which to find the first occurrence (inclusive)
      Returns:
      index of the last occurrence of the value at keyIndex
      Throws:
      IllegalArgumentException - if maxIndex < keyIndex
      IndexOutOfBoundsException - if keyIndex < 0 or maxIndex > b.capacity()
    • binaryFindFirst

      public static int binaryFindFirst(SmallFloatBuffer b, int minIndex, int keyIndex)
      Searches a range of the specified SmallFloatBuffer for the first occurrence of the value at the given keyIndex. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined. This method considers all NaN values to be equivalent and equal.

      This method is useful as a post-processing step after a binary search on a buffer which contains duplicate elements.

      Parameters:
      b - the buffer to be searched
      minIndex - the lowest index to be searched
      keyIndex - an index of the value for which to find the first occurrence (inclusive)
      Returns:
      index of the first occurrence of the value at keyIndex
      Throws:
      IllegalArgumentException - if minIndex > keyIndex
      IndexOutOfBoundsException - if minIndex < 0 or keyIndex >= b.capacity()
    • binaryFindLast

      public static int binaryFindLast(SmallFloatBuffer b, int maxIndex, int keyIndex)
      Searches a range of the specified SmallFloatBuffer for the last occurrence of the value at the given keyIndex. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined. This method considers all NaN values to be equivalent and equal.

      This method is useful as a post-processing step after a binary search on a buffer which contains duplicate elements.

      Parameters:
      b - the buffer to be searched
      maxIndex - the highest index to be searched (exclusive)
      keyIndex - an index of the value for which to find the first occurrence (inclusive)
      Returns:
      index of the last occurrence of the value at keyIndex
      Throws:
      IllegalArgumentException - if maxIndex < keyIndex
      IndexOutOfBoundsException - if keyIndex < 0 or maxIndex > b.capacity()
    • binaryFindFirst

      public static int binaryFindFirst(SmallDoubleBuffer b, int minIndex, int keyIndex)
      Searches a range of the specified SmallDoubleBuffer for the first occurrence of the value at the given keyIndex. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined. This method considers all NaN values to be equivalent and equal.

      This method is useful as a post-processing step after a binary search on a buffer which contains duplicate elements.

      Parameters:
      b - the buffer to be searched
      minIndex - the lowest index to be searched
      keyIndex - an index of the value for which to find the first occurrence (inclusive)
      Returns:
      index of the first occurrence of the value at keyIndex
      Throws:
      IllegalArgumentException - if minIndex > keyIndex
      IndexOutOfBoundsException - if minIndex < 0 or keyIndex >= b.capacity()
    • binaryFindLast

      public static int binaryFindLast(SmallDoubleBuffer b, int maxIndex, int keyIndex)
      Searches a range of the specified SmallDoubleBuffer for the last occurrence of the value at the given keyIndex. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined. This method considers all NaN values to be equivalent and equal.

      This method is useful as a post-processing step after a binary search on a buffer which contains duplicate elements.

      Parameters:
      b - the buffer to be searched
      maxIndex - the highest index to be searched (exclusive)
      keyIndex - an index of the value for which to find the first occurrence (inclusive)
      Returns:
      index of the last occurrence of the value at keyIndex
      Throws:
      IllegalArgumentException - if maxIndex < keyIndex
      IndexOutOfBoundsException - if keyIndex < 0 or maxIndex > b.capacity()