Struct primes::Sieve

source ·
pub struct Sieve { /* private fields */ }
Expand description

A prime generator, using the Sieve of Eratosthenes method. This is asymptotically more efficient than the Trial Division method, but slower earlier on.

Create with let mut pset = Sieve::new(), and then use pset.iter() to iterate over all primes.

Implementations§

source§

impl Sieve

source

pub fn new() -> Sieve

A new prime generator, primed with 2 and 3

Trait Implementations§

source§

impl Clone for Sieve

source§

fn clone(&self) -> Sieve

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Default for Sieve

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl PrimeSetBasics for Sieve

source§

fn expand(&mut self)

Finds one more prime, and adds it to the list

source§

fn list(&self) -> &[u64]

Return all primes found so far as a slice

Auto Trait Implementations§

§

impl Freeze for Sieve

§

impl RefUnwindSafe for Sieve

§

impl Send for Sieve

§

impl Sync for Sieve

§

impl Unpin for Sieve

§

impl UnwindSafe for Sieve

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<P> PrimeSet for P
where P: PrimeSetBasics,

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 Read more
source§

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

Check if a number is prime Read more
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 Read more
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
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.