ck/binsearch▲toc

Binary search

.

fun binsearch( ok : intstd/core/types/int: V, ng : intstd/core/types/int: V, p : (intstd/core/types/int: V) -> e boolstd/core/types/bool: V ) : e intstd/core/types/int: V

Binary search on the interval of integers between ok and ng. If ng < ok, the result is the smallest integer satisfying p. Otherwise, the result is the largest integer satisfying p. p must be monotone such that p(ok) = Truestd/core/types/True: bool and p(ng) = Falsestd/core/types/False: bool.

fun binsearch-f64( ok : float64std/core/types/float64: V, ng : float64std/core/types/float64: V, t : intstd/core/types/int: V, p : (float64std/core/types/float64: V) -> e boolstd/core/types/bool: V ) : e float64std/core/types/float64: V

Binary search on the interval of float64 between ok and ng. This function halves the interval t times, and returns a number close to the boundary of p, which divides a set of numbers into two intervals, all numbers in an interval satisfy p, and all numbers in another one do not. p must be monotone such that p(ok) = Truestd/core/types/True: bool and p(ng) = Falsestd/core/types/False: bool.

private import std/core/typesstd/core/types, std/core/hndstd/core/hnd, std/core/exnstd/core/exn, std/core/boolstd/core/bool, std/core/orderstd/core/order, std/core/charstd/core/char, std/core/intstd/core/int, std/core/vectorstd/core/vector, std/core/stringstd/core/string, std/core/sslicestd/core/sslice, std/core/liststd/core/list, std/core/maybestd/core/maybe, std/core/maybe2std/core/maybe2, std/core/eitherstd/core/either, std/core/tuplestd/core/tuple, std/core/lazystd/core/lazy, std/core/showstd/core/show, std/core/debugstd/core/debug, std/core/delayedstd/core/delayed, std/core/consolestd/core/console, std/corestd/core, std/core/undivstd/core/undiv, std/num/float64std/num/float64