Trait primes::PrimeSet

source ·
pub trait PrimeSet: PrimeSetBasics + Sized {
    // Provided methods
    fn len(&self) -> usize { ... }
    fn is_empty(&self) -> bool { ... }
    fn generator(&mut self) -> PrimeSetIter<'_, Self>  { ... }
    fn iter(&mut self) -> PrimeSetIter<'_, Self>  { ... }
    fn iter_vec(&self) -> Iter<'_, u64> { ... }
    fn find(&mut self, n: u64) -> (usize, u64) { ... }
    fn is_prime(&mut self, n: u64) -> bool { ... }
    fn find_vec(&self, n: u64) -> Option<(usize, u64)> { ... }
    fn get(&mut self, index: usize) -> u64 { ... }
    fn prime_factors(&mut self, n: u64) -> Vec<u64> { ... }
}

Provided Methods§

source

fn len(&self) -> usize

Number of primes found so far

source

fn is_empty(&self) -> bool

source

fn generator(&mut self) -> PrimeSetIter<'_, Self>

Iterator over all primes not yet found

source

fn iter(&mut self) -> PrimeSetIter<'_, Self>

Iterator over all primes, starting with 2. If you don’t care about the “state” of the PrimeSet, this is what you want!

source

fn iter_vec(&self) -> Iter<'_, u64>

Iterator over just the primes found so far

source

fn find(&mut self, n: u64) -> (usize, u64)

Find the next largest prime from a number

Returns (idx, prime)

Note that if n is prime, then the output will be (idx, n)

source

fn is_prime(&mut self, n: u64) -> bool

Check if a number is prime

Note that this only requires primes up to n.sqrt() to be generated, and will generate them as necessary on its own.

source

fn find_vec(&self, n: u64) -> Option<(usize, u64)>

Find the next largest prime from a number, if it is within the already-found list

Returns (idx, prime)

Note that if n is prime, then the output will be (idx, n)

source

fn get(&mut self, index: usize) -> u64

Get the nth prime, even if we haven’t yet found it

source

fn prime_factors(&mut self, n: u64) -> Vec<u64>

Get the prime factors of a number, starting from 2, including repeats

Object Safety§

This trait is not object safe.

Implementors§