pub fn stable_sort<T>(
objs: impl IntoIterator<Item = T>,
key: impl Fn(&T) -> usize,
descending: bool,
) -> (Vec<usize>, Vec<T>)
Expand description
Stable sorts a collection of objects based on a key function and an optional descending flag.
This function takes a collection of objects, sorts them stably based on the value returned by a key function, and can optionally use descending sort order. It returns a tuple containing a vector of the original indices of the objects and a vector of the sorted objects.
§Arguments
objs
: An iterable collection of objects to be sorted.key
: A function that takes a reference to an object and returns ausize
value used for sorting.descending
: A boolean flag indicating whether to sort in descending order.
§Returns
A tuple where the first element is a vector of the original indices of the objects and the second element is a vector of the sorted objects.
§Note
This function uses stable sorting to ensure consistency in ordering objects that compare as equal.