BinarySearch

class Object
trait Matchable
class Any

Type members

Classlikes

sealed trait ComparisonResult
case object Equal extends ComparisonResult
case object Greater extends ComparisonResult
case object Smaller extends ComparisonResult

Value members

Concrete methods

def array[T](array: Array[T], compare: T => ComparisonResult): Option[T]

Binary search using a custom compare function.

Binary search using a custom compare function.

scala.util.Searching does not support the ability to search an IndexedSeq by a custom mapping function, you must search by an element of the same type as the elements of the Seq.

Value parameters:
array

Must be sorted according to compare function so that for all i > j, compare(array(i), array(i)) == Greater.

compare

Callback used at every guess index to determine whether the search element has been found, or whether to search above or below the guess index.

Returns:

The first element where compare(element) == Equal. There is no guarantee which element is chosen if many elements return Equal.