Skip to main content

FuncPerm

Struct FuncPerm 

Source
pub struct FuncPerm<B> { /* private fields */ }
Expand description

Cycle-walking functional permutation on [0 . . n), given a bijection on [0 . . m), where mn.

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>

Source

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 mn.

Note that providing a function that does not satisfy the bijection requirement may lead to non-termination of the get method.

Source

pub const fn len(&self) -> u64

Returns the size of the permutation domain.

Source

pub const fn is_empty(&self) -> bool

Returns true if the permutation domain is empty.

Source§

impl<B: Fn(u64) -> u64> FuncPerm<B>

Source

pub fn get(&self, x: u64) -> u64

Returns the image of x under the permutation.

§Panics

Panics if xn.

Trait Implementations§

Source§

impl<B: Clone> Clone for FuncPerm<B>

Source§

fn clone(&self) -> FuncPerm<B>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<B> Debug for FuncPerm<B>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.