use rand::{SeedableRng, seq::SliceRandom};
use rand_pcg::Pcg64;
#[derive(Debug, Clone)]
pub struct Permutation {
pub f: Vec<usize>,
pub n: usize,
}
impl Permutation {
pub(crate) fn new(n: usize, seed: u64) -> Self {
let mut rng = Pcg64::seed_from_u64(seed);
let mut f: Vec<usize> = (0..n).collect();
f.shuffle(&mut rng);
Self { f, n }
}
pub fn corresponding_wmbits_position(&self, block_position: usize, wm_len: usize) -> usize {
self.f[block_position] % wm_len
}
pub fn corresponding_block_positions(
&self,
wmbits_position: usize,
wm_len: usize,
) -> Vec<usize> {
(0..self.n)
.filter(|&i| self.f[i] % wm_len == wmbits_position)
.collect()
}
}