Sorts a sequence of items by comparing their corresponding byte-slice representations. The size of the permutation is inferred from the length of the `order` slice. # Example ```rust use stringzilla::stringzilla as sz; #[derive(Debug)] struct Person { name: &'static str, age: u32 } let people = [ Person { name: "Charlie", age: 20 }, Person { name: "Alice", age: 25 }, Person { name: "Bob", age:
(mapper: F, order: &mut [SortedIdx])
| 2211 | /// assert_eq!(&order, &[1, 2, 0]); // "Alice", "Bob", "Charlie" |
| 2212 | /// ``` |
| 2213 | pub fn argsort_permutation_by<F, A>(mapper: F, order: &mut [SortedIdx]) -> Result<(), Status> |
| 2214 | where |
| 2215 | F: Fn(usize) -> A, |
| 2216 | A: AsRef<[u8]>, |
| 2217 | { |
| 2218 | // Adapter closure: given an index, call the provided mapper and then transmute the |
| 2219 | // resulting slice to have a `'static` lifetime. This transmute is safe as long as |
| 2220 | // the FFI call is synchronous and the returned slices are only used during the call. |
| 2221 | let adapter = move |i: usize| -> &'static [u8] { |
| 2222 | let binding = mapper(i); |
| 2223 | let slice = binding.as_ref(); |
| 2224 | unsafe { core::mem::transmute(slice) } |
| 2225 | }; |
| 2226 | |
| 2227 | _argsort_permutation_impl(adapter, order) |
| 2228 | } |
| 2229 | |
| 2230 | /// Helper that takes an adapter (with a concrete type) and performs the FFI call. |
| 2231 | fn _argsort_permutation_impl<FAdapter>(adapter: FAdapter, order: &mut [SortedIdx]) -> Result<(), Status> |
searching dependent graphs…