pub struct FuncPerm<B> { /* private fields */ }Expand description
Cycle-walking functional permutation on [0 . . n), given a bijection on [0 . . m), where m ≥ n.
The bijection must map [0 . . m) to itself. The get
method applies the bijection repeatedly until the result falls in
[0 . . n), producing a permutation of [0 . . n).
PartialEq, Eq, and Hash cannot be derived because the bijection
is typically a closure.
§Examples
Using a custom bijection (XOR with a constant on 4-bit values):
let perm = FuncPerm::new(10, |x: u64| x ^ 0b1010);
assert!(perm.get(0) < 10);Implementations§
Source§impl<B> FuncPerm<B>
impl<B> FuncPerm<B>
Sourcepub const fn new(n: u64, bijection: B) -> Self
pub const fn new(n: u64, bijection: B) -> Self
Creates a new cycle-walking functional permutation on [0 . . n) using the given bijection, which must have domain [0 . . m), where m ≥ n.
Note that providing a function that does not satisfy the bijection
requirement may lead to non-termination of the get
method.
Trait Implementations§
impl<B: Copy> Copy for FuncPerm<B>
Auto Trait Implementations§
impl<B> Freeze for FuncPerm<B>where
B: Freeze,
impl<B> RefUnwindSafe for FuncPerm<B>where
B: RefUnwindSafe,
impl<B> Send for FuncPerm<B>where
B: Send,
impl<B> Sync for FuncPerm<B>where
B: Sync,
impl<B> Unpin for FuncPerm<B>where
B: Unpin,
impl<B> UnsafeUnpin for FuncPerm<B>where
B: UnsafeUnpin,
impl<B> UnwindSafe for FuncPerm<B>where
B: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more