num_modular

Trait Reducer

Source
pub trait Reducer<T> {
Show 17 methods // Required methods fn new(m: &T) -> Self; fn transform(&self, target: T) -> T; fn check(&self, target: &T) -> bool; fn modulus(&self) -> T; fn residue(&self, target: T) -> T; fn is_zero(&self, target: &T) -> bool; fn add(&self, lhs: &T, rhs: &T) -> T; fn dbl(&self, target: T) -> T; fn sub(&self, lhs: &T, rhs: &T) -> T; fn neg(&self, target: T) -> T; fn mul(&self, lhs: &T, rhs: &T) -> T; fn inv(&self, target: T) -> Option<T>; fn sqr(&self, target: T) -> T; fn pow(&self, base: T, exp: &T) -> T; // Provided methods fn add_in_place(&self, lhs: &mut T, rhs: &T) { ... } fn sub_in_place(&self, lhs: &mut T, rhs: &T) { ... } fn mul_in_place(&self, lhs: &mut T, rhs: &T) { ... }
}
Expand description

A modular reducer that can ensure that the operations on integers are all performed in a modular ring.

Essential information for performing the modulo operation will be stored in the reducer.

Required Methods§

Source

fn new(m: &T) -> Self

Create a reducer for a modulus m

Source

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

Transform a normal integer into reduced form

Source

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

Check whether target is a valid reduced form

Source

fn modulus(&self) -> T

Get the modulus in original integer type

Source

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

Transform a reduced form back to normal integer

Source

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

Test if the residue() == 0

Source

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

Calculate (lhs + rhs) mod m in reduced form

Source

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

Calculate 2*target mod m

Source

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

Calculate (lhs - rhs) mod m in reduced form

Source

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

Calculate -monty mod m in reduced form

Source

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

Calculate (lhs * rhs) mod m in reduced form

Source

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

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

Source

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

Calculate target^2 mod m in reduced form

Source

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

Calculate base ^ exp mod m in reduced form

Provided Methods§

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)

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§