Skip to main content

find_limit

Function find_limit 

Source
fn find_limit<T, F>(f: F) -> T
where T: SaturatingTime, F: Fn(&T, Duration) -> Option<T>,
Expand description

Internal algorithm of find_max() and find_min().

It works by performing f with a very large Duration onto SaturatingTime::anchor() until this call returns None, in which case this Duration gets halved. This process is repeated until f returns None and the Duration has reached 1ns.

ยงAlgorithm

  1. Set step to INITIAL_STEP and res to SaturatingTime::anchor().
  2. Call f(&res, step).
    1. If Some, set res to the returned value and continue.
    2. If None and step == 1ns, return res.
    3. Else, set step to MAX{1ns, step / 2} and continue.