pub trait PrimeBufferExt: for<'a> PrimeBuffer<'a> {
    fn is_prime<T: PrimalityBase>(
        &self,
        target: &T,
        config: Option<PrimalityTestConfig>
    ) -> Primality
    where
        for<'r> &'r T: PrimalityRefBase<T>
, { ... } fn factors<T: PrimalityBase>(
        &self,
        target: T,
        config: Option<FactorizationConfig>
    ) -> (BTreeMap<T, usize>, Option<Vec<T>>)
    where
        for<'r> &'r T: PrimalityRefBase<T>
, { ... } fn factorize<T: PrimalityBase>(&self, target: T) -> BTreeMap<T, usize>
    where
        for<'r> &'r T: PrimalityRefBase<T>
, { ... } fn divisor<T: PrimalityBase>(
        &self,
        target: &T,
        config: &mut FactorizationConfig
    ) -> Option<T>
    where
        for<'r> &'r T: PrimalityRefBase<T>
, { ... } }
Expand description

Extension functions that can utilize pre-generated primes

Provided Methods

Test if an integer is a prime.

For targets smaller than 2^64, the deterministic is_prime64 will be used, otherwise the primality test algorithms can be specified by the config argument.

The primality test can be either deterministic or probabilistic for large integers depending on the config. The return value is represented by the enum Primality, which tells whether the primality test is deterministic or probabilistic.

Factorize an integer.

For targets smaller than 2^64, the efficient [factorize64] will be used, otherwise the primality test and factorization algorithms can be specified by the config argument.

The factorization result consists of two parts. The first is a map from prime factors to their exponents. If the factorization failed, the second part will be the remaining cofactors that are not factored, otherwise None is returned for the second part. It’s ensured that the product of prime factors (and remaining cofactors if exist) is equal to the original target.

Factorize an integer until all prime factors are found.

This function will try to call [factors] function repeatedly until the target is fully factorized.

Return a proper divisor of target (randomly), even works for very large numbers. Return None if no factor is found.

Note: this method will not do a primality check

Implementors