Expand description
§smallperm
High-performance pseudo-random permutations using Feistel networks.
This library provides O(1) memory and O(1) expected time per element for generating pseudo-random permutations, making it ideal for shuffling large datasets in machine learning contexts where time-to-first-sample and memory overhead are critical.
§Features
- O(1) memory: No need to store the entire permutation
- O(1) random access: Get any element of the permutation instantly
- Invertible: Map both forward and backward between indices and values
- Deterministic: Same seed produces same permutation across runs
- Supports up to 2^128 elements
§Example
use smallperm::Permutation;
// Create a permutation of 1000 elements with seed 42
let perm = Permutation::new(1000, 42);
// Iterate through the permutation
for (i, value) in perm.iter().enumerate().take(10) {
println!("perm[{}] = {}", i, value);
}
// Random access
let value = perm.get(500).unwrap();
println!("perm[500] = {}", value);
// Inverse lookup
let index = perm.index_of(value).unwrap();
assert_eq!(index, 500);Structs§
- Feistel
Network - Implements a Feistel network, which can take a non-invertible pseudo-random function (PRF) and turn it into an invertible pseudo-random permutation (PRP).
- Permutation
- A pseudo-random permutation with O(1) memory and O(1) access time.
- Permutation
Iter - Iterator over a permutation.
- Permutor
Functions§
- sample
- Sample
kunique random elements from a slice. - sample_
indices - Sample
kunique random indices from[0, n). - shuffle
- Shuffle a slice and return a new Vec with the shuffled elements.
- shuffle_
in_ place - Shuffle a mutable slice in place.