index_permute

Crates.ioindex_permute
lib.rsindex_permute
version0.1.12
created_at2025-07-20 21:30:06.901859+00
updated_at2025-07-22 22:08:08.627144+00
descriptionA library for permuting a slice which elements are not Clone or Copy in Rust
homepage
repositoryhttps://github.com/shenjiangqiu/index_permute
max_upload_size
id1761420
size38,550
Jiangqiu Shen (shenjiangqiu)

documentation

README

GitHub Actions Workflow Status Crates.io Version

🌀 index_permute

A minimal, in-place, and non-cloning array permutation library for Rust.

This crate allows you to reorder a slice in place by an index array, even when the element type is not Clone or Copy. It ensures safety via a wrapper type PermuteIndex that checks index validity ahead of time.


✨ Features

  • ✅ In-place permutation of non-Copy, non-Clone data.
  • ✅ Memory-safe: no element dropped or cloned during permutation.
  • ✅ Index validation: ensures the index is a true permutation (0..N).
  • ✅ Safe, ergonomic API.
  • ✅ parallel feature is defined, but it has limited speedup due to it's memory-bound nature. On benchmarks, it shows a 1.3x speedup on a 10 million element array.

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]);

📦 Installation

Add this to your Cargo.toml:

[dependencies]
index_permute = 0.1
Commit count: 0

cargo fmt