Skip to main content

Crate index_permute

Crate index_permute 

Source
Expand description
  • A tool to reorder an array by an index array inplace when the elements are not Clone or Copy.
  • lock-free parallel implementation.

§Example

use index_permute::PermuteIndex;
let index = PermuteIndex::try_new(&[2, 0, 1
]).unwrap();
let mut data = vec![10, 20, 30];
index_permute::order_by_index_inplace(&mut data, index);
assert_eq!(data, vec![30, 10, 20]);

Macros§

cfg_parallel
A macro to conditionally compile items based on the parallel feature.

Structs§

PermuteIndex
A struct to hold a permutation index. The index must be unique and in the range of 0..len, where len is the length of the data to be permuted. This struct is used to ensure that the index is valid before performing any operations on the data. It can be created using PermuteIndex::try_new, which checks the validity of the index. If the index is invalid, it returns a PermuteError::InvalidIndex error. The index can be used to permute data using the try_order_by_index_inplace function. The index length must match the data length, otherwise it returns a PermuteError::LengthMismatch error. The order_by_index_inplace function is a convenience function that panics if the index is invalid or the lengths do not match.

Enums§

PermuteError
An error type for PermuteIndex and try_order_by_index_inplace.

Functions§

order_by_index_inplace
A convenience function that panics if the index is invalid or the lengths do not match. It is recommended to use try_order_by_index_inplace for error handling.
try_order_by_index_inplace
Reorders the data in place according to the given index. First create a PermuteIndex, then, it reorders the data in place
try_order_by_index_parallel_inplaceparallel
Same as try_order_by_index_parallel_inplace_with_threads but uses the number of available CPU cores. Only valid when features parallel is enabled.
try_order_by_index_parallel_inplace_with_threadsparallel
Only valid when features parallel is enabled. A parallel version of try_order_by_index_inplace.