pub struct FixedMersenne<const P: u8, const K: umax>();
Expand description

A modular reducer for (pseudo) Mersenne numbers 2^P - K as modulus. It supports P up to 127 and K < 2^(P-1)

The P is limited to 127 so that it’s not necessary to check overflow. This limit won’t be a problem for any Mersenne primes within the range of umax (i.e. u128).

Implementations§

source§

impl<const P: u8, const K: umax> FixedMersenne<P, K>

source

pub const MODULUS: umax = _

Trait Implementations§

source§

impl<const P: u8, const K: umax> Clone for FixedMersenne<P, K>

source§

fn clone(&self) -> FixedMersenne<P, K>

Returns a copy 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<const P: u8, const K: umax> Debug for FixedMersenne<P, K>

source§

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

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

impl<const P: u8, const K: umax> Reducer<u128> for FixedMersenne<P, K>

source§

fn new(m: &umax) -> Self

Create a reducer for a modulus m
source§

fn transform(&self, target: umax) -> umax

Transform a normal integer into reduced form
source§

fn check(&self, target: &umax) -> bool

Check whether target is a valid reduced form
source§

fn residue(&self, target: umax) -> umax

Transform a reduced form back to normal integer
source§

fn modulus(&self) -> umax

Get the modulus in original integer type
source§

fn is_zero(&self, target: &umax) -> bool

Test if the residue() == 0
source§

fn add(&self, lhs: &umax, rhs: &umax) -> umax

Calculate (lhs + rhs) mod m in reduced form
source§

fn sub(&self, lhs: &umax, rhs: &umax) -> umax

Calculate (lhs - rhs) mod m in reduced form
source§

fn dbl(&self, target: umax) -> umax

Calculate 2*target mod m
source§

fn neg(&self, target: umax) -> umax

Calculate -monty mod m in reduced form
source§

fn mul(&self, lhs: &umax, rhs: &umax) -> umax

Calculate (lhs * rhs) mod m in reduced form
source§

fn inv(&self, target: umax) -> Option<umax>

Calculate target^-1 mod m in reduced form, it may return None when there is no modular inverse.
source§

fn sqr(&self, target: umax) -> umax

Calculate target^2 mod m in reduced form
source§

fn pow(&self, base: umax, exp: &umax) -> umax

Calculate base ^ exp mod m in reduced form
source§

fn add_in_place(&self, lhs: &mut T, rhs: &T)

source§

fn sub_in_place(&self, lhs: &mut T, rhs: &T)

source§

fn mul_in_place(&self, lhs: &mut T, rhs: &T)

source§

impl<const P: u8, const K: umax> Copy for FixedMersenne<P, K>

Auto Trait Implementations§

§

impl<const P: u8, const K: u128> RefUnwindSafe for FixedMersenne<P, K>

§

impl<const P: u8, const K: u128> Send for FixedMersenne<P, K>

§

impl<const P: u8, const K: u128> Sync for FixedMersenne<P, K>

§

impl<const P: u8, const K: u128> Unpin for FixedMersenne<P, K>

§

impl<const P: u8, const K: u128> UnwindSafe for FixedMersenne<P, K>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.