CallableBinarySearch
Finds the first equal element or lower-bound insertion position with a concrete comparator.
Module std.iteration
import std.iteration;Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.
BinarySearch
pub fn BinarySearch<T, C>(Values: readonly T[], Key: readonly T&,
mut Compare: C) -> Result<usize, usize>
where C: BinaryCallable<readonly T&, readonly T&, i32>, MovableFinds the first equal element or lower-bound insertion position with a concrete comparator.
Owns the concrete callback during O(log n) borrowed comparisons. Uses O(1) state and introduces no allocation, element copies/moves, mutation or lock. Captured backing and sorted storage remain live and unchanged throughout the call. Duplicates return the first matching index; empty input inserts at zero. T: Exact stored element type, including non-Copy owners. C: Movable safe readonly binary comparator, inferred from Compare. Values: Readonly contiguous storage sorted by this same ordering. Key: Borrowed target, not retained in the result. Compare: Owned concrete comparator; non-Copy named state requires move. Return: Ok first matching index or Err insertion position in [0,Length]. Pre: Compare supplies a consistent ordering and never invalidates Values or Key. Warning: No linear ordering validation occurs; callback/backing costs remain their contracts.