ternary_search

Function ternary_search 

Source
pub fn ternary_search<K, V, F>(range: RangeInclusive<K>, f: F) -> (K, V)
where K: Trisect, V: PartialOrd, F: FnMut(K) -> V,
Expand description

Returns the element that gives the minimum value from the strictly concave up function and the minimum value.

Examples found in repository?
crates/competitive/src/algorithm/ternary_search.rs (line 147)
139pub fn piecewise_ternary_search<const N: usize, K, V, F>(piece: [K; N], mut f: F) -> (K, V)
140where
141    K: Trisect,
142    V: PartialOrd,
143    F: FnMut(K) -> V,
144{
145    piece
146        .windows(2)
147        .map(|w| ternary_search(w[0].clone()..=w[1].clone(), &mut f))
148        .min_by(|a, b| a.1.partial_cmp(&b.1).unwrap())
149        .unwrap_or_else(|| (piece[0].clone(), f(piece[0].clone())))
150}