Trait 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

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§