closest_sum_pair
Fast. Clever. Free of Recursion. No while bound loops, so least runtime strikes.
It expects a sorted list. Time complexity O(N). Space complexity O(1).
Update !
From now multiple types are supported, including floating point numbers. But usize, u64, u128, i64, i128 and f64 are not supported due to f64 cannot exactly capture these values, which is relevant in this context because various
types are attemped to be converted into f64 as a general type in this crate.
But all other types are supported, eg. i8, u8, i16, u16, i32, u32 and f32.
Quick Start
Due to find_pair function expects a sorted list (can be vector or array),
you should sort your list using any preferred algorithm, before passing it as parameter.
The find_pair function also expects your desired sum (The sum you are looking for)
If there is no exact match, it will return the closest sum possible.
use find_pair;
Example with floating point:
use find_pair;
version note: Support multiple types.