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>
    ) -> Result<BTreeMap<T, usize>, 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 will be returned as a map from prime factors to their exponents. If the factorization failed, then a list of found factors (not necessarily primes) will be returned. A prime factor will repeat if its exponent is larget than one, and it’s ensured that the product of the list of factors is equal to the original target.

TODO(v0.next): Return two lists when failed, one for prime factors, another one for remaining cofactors

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