Template Function mrpt::containers::find_closest

Function Documentation

template<typename Container>
std::optional<std::pair<typename Container::key_type, typename Container::mapped_type>> mrpt::containers::find_closest(const Container &data, const typename Container::key_type x)

For an associate container Container mapping real number keys to T values, searchs for the closest key within a given tolerance, that is, the key closest to x within the interval [x-tolerace, x+tolerance].

An empty std::optional is returned if none is found, i.e. if the container was empty.

Computational cost: O(log(N)) with N the total size of the container.

Note

(New in MRPT 2.5.0)