MCPcopy Create free account
hub / github.com/ashvardanian/StringZilla / argsort_permutation

Function argsort_permutation

rust/stringzilla.rs:2186–2191  ·  view source on GitHub ↗

Sorts a sequence of items by comparing their byte-slice representations. The caller must supply an output buffer `order` whose length is at least equal to the length of `data`. On success, the function writes the sorted permutation indices into `order`. # Example ```rust use stringzilla::stringzilla as sz; let fruits = ["banana", "apple", "cherry"]; let mut order = [0; 3]; sz::argsort_permutat

(data: &[T], order: &mut [SortedIdx])

Source from the content-addressed store, hash-verified

2184/// assert_eq!(&order, &[1, 0, 2]); // "apple", "banana", "cherry"
2185/// ```
2186pub fn argsort_permutation<T: AsRef<[u8]>>(data: &[T], order: &mut [SortedIdx]) -> Result<(), Status> {
2187 if data.len() > order.len() {
2188 return Err(Status::BadAlloc);
2189 }
2190 argsort_permutation_by(|i| data[i].as_ref(), order[..data.len()].as_mut())
2191}
2192
2193/// Sorts a sequence of items by comparing their corresponding byte-slice representations.
2194/// The size of the permutation is inferred from the length of the `order` slice.

Callers 1

Calls 2

argsort_permutation_byFunction · 0.85
lenMethod · 0.80

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…