Trait malachite_base::num::arithmetic::traits::ModPowPrecomputed
source · pub trait ModPowPrecomputed<RHS = Self, M = Self>where
Self: Sized,{
type Output;
type Data;
// Required methods
fn precompute_mod_pow_data(m: &M) -> Self::Data;
fn mod_pow_precomputed(
self,
exp: RHS,
m: M,
data: &Self::Data,
) -> Self::Output;
}
Expand description
Raises a number to a power modulo another number $m$. The base must be already reduced modulo $m$.
If multiple modular exponentiations with the same modulus are necessary, it can be quicker to precompute some piece of data and reuse it in the exponentiation calls. This trait provides a function for precomputing the data and a function for using it during exponentiation.
Required Associated Types§
Required Methods§
sourcefn precompute_mod_pow_data(m: &M) -> Self::Data
fn precompute_mod_pow_data(m: &M) -> Self::Data
Precomputes some data to use for modular exponentiation.
fn mod_pow_precomputed(self, exp: RHS, m: M, data: &Self::Data) -> Self::Output
Object Safety§
Implementations on Foreign Types§
source§impl ModPowPrecomputed for u64
impl ModPowPrecomputed for u64
source§fn precompute_mod_pow_data(m: &u64) -> (u64, u64)
fn precompute_mod_pow_data(m: &u64) -> (u64, u64)
Precomputes data for modular exponentiation.
See mod_pow_precomputed
and
mod_pow_precomputed_assign
.
§Worst-case complexity
Constant time and additional memory.
source§fn mod_pow_precomputed(self, exp: u64, m: u64, data: &(u64, u64)) -> u64
fn mod_pow_precomputed(self, exp: u64, m: u64, data: &(u64, u64)) -> u64
Raises a number to a power modulo another number $m$. The base must be already reduced modulo $m$.
Some precomputed data is provided; this speeds up computations involving several
modular exponentiations with the same modulus. The precomputed data should be
obtained using
precompute_mod_pow_data
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is exp.significant_bits()
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = u64
type Data = (u64, u64)
source§impl ModPowPrecomputed<u64> for u8
impl ModPowPrecomputed<u64> for u8
source§fn precompute_mod_pow_data(m: &u8) -> (u32, u64)
fn precompute_mod_pow_data(m: &u8) -> (u32, u64)
Precomputes data for modular exponentiation.
See mod_pow_precomputed
and
mod_pow_precomputed_assign
.
§Worst-case complexity
Constant time and additional memory.
source§fn mod_pow_precomputed(self, exp: u64, m: u8, data: &(u32, u64)) -> u8
fn mod_pow_precomputed(self, exp: u64, m: u8, data: &(u32, u64)) -> u8
Raises a number to a power modulo another number $m$. The base must be already reduced modulo $m$.
Some precomputed data is provided; this speeds up computations involving several
modular exponentiations with the same modulus. The precomputed data should be
obtained using
precompute_mod_pow_data
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is exp.significant_bits()
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = u8
type Data = (u32, u64)
source§impl ModPowPrecomputed<u64> for u16
impl ModPowPrecomputed<u64> for u16
source§fn precompute_mod_pow_data(m: &u16) -> (u32, u64)
fn precompute_mod_pow_data(m: &u16) -> (u32, u64)
Precomputes data for modular exponentiation.
See mod_pow_precomputed
and
mod_pow_precomputed_assign
.
§Worst-case complexity
Constant time and additional memory.
source§fn mod_pow_precomputed(self, exp: u64, m: u16, data: &(u32, u64)) -> u16
fn mod_pow_precomputed(self, exp: u64, m: u16, data: &(u32, u64)) -> u16
Raises a number to a power modulo another number $m$. The base must be already reduced modulo $m$.
Some precomputed data is provided; this speeds up computations involving several
modular exponentiations with the same modulus. The precomputed data should be
obtained using
precompute_mod_pow_data
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is exp.significant_bits()
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = u16
type Data = (u32, u64)
source§impl ModPowPrecomputed<u64> for u32
impl ModPowPrecomputed<u64> for u32
source§fn precompute_mod_pow_data(m: &u32) -> (u32, u64)
fn precompute_mod_pow_data(m: &u32) -> (u32, u64)
Precomputes data for modular exponentiation.
See mod_pow_precomputed
and
mod_pow_precomputed_assign
.
§Worst-case complexity
Constant time and additional memory.
source§fn mod_pow_precomputed(self, exp: u64, m: u32, data: &(u32, u64)) -> u32
fn mod_pow_precomputed(self, exp: u64, m: u32, data: &(u32, u64)) -> u32
Raises a number to a power modulo another number $m$. The base must be already reduced modulo $m$.
Some precomputed data is provided; this speeds up computations involving several
modular exponentiations with the same modulus. The precomputed data should be
obtained using
precompute_mod_pow_data
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is exp.significant_bits()
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = u32
type Data = (u32, u64)
source§impl ModPowPrecomputed<u64> for u128
impl ModPowPrecomputed<u64> for u128
source§fn precompute_mod_pow_data(_m: &u128)
fn precompute_mod_pow_data(_m: &u128)
Precomputes data for modular exponentiation.
See mod_pow_precomputed
and
mod_pow_precomputed_assign
.
§Worst-case complexity
Constant time and additional memory.
source§fn mod_pow_precomputed(self, exp: u64, m: u128, _data: &()) -> u128
fn mod_pow_precomputed(self, exp: u64, m: u128, _data: &()) -> u128
Raises a number to a power modulo another number $m$. The base must be already reduced modulo $m$.
Some precomputed data is provided; this speeds up computations involving several modular
exponentiations with the same modulus. The precomputed data should be obtained using
precompute_mod_pow_data
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is exp.significant_bits()
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = u128
type Data = ()
source§impl ModPowPrecomputed<u64> for usize
impl ModPowPrecomputed<u64> for usize
source§fn precompute_mod_pow_data(m: &usize) -> (usize, u64)
fn precompute_mod_pow_data(m: &usize) -> (usize, u64)
Precomputes data for modular exponentiation.
See mod_pow_precomputed
and
mod_pow_precomputed_assign
.
§Worst-case complexity
Constant time and additional memory.
source§fn mod_pow_precomputed(self, exp: u64, m: usize, data: &(usize, u64)) -> usize
fn mod_pow_precomputed(self, exp: u64, m: usize, data: &(usize, u64)) -> usize
Raises a number to a power modulo another number $m$. The base must be already reduced modulo $m$.
Some precomputed data is provided; this speeds up computations involving several modular
exponentiations with the same modulus. The precomputed data should be obtained using
precompute_mod_pow_data
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is exp.significant_bits()
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.