pub trait Primes {
type I: Iterator<Item = Self>;
type LI: Iterator<Item = Self>;
// Required methods
fn primes_less_than(n: &Self) -> Self::LI;
fn primes_less_than_or_equal_to(n: &Self) -> Self::LI;
fn primes() -> Self::I;
}
Expand description
A trait for producing iterators of primes.
Required Associated Types§
Required Methods§
fn primes_less_than(n: &Self) -> Self::LI
fn primes_less_than_or_equal_to(n: &Self) -> Self::LI
fn primes() -> Self::I
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.
Implementations on Foreign Types§
Source§impl Primes for u8
impl Primes for u8
Source§fn primes_less_than(n: &u8) -> PrimesLessThanIterator<u8> ⓘ
fn primes_less_than(n: &u8) -> PrimesLessThanIterator<u8> ⓘ
Returns an iterator that generates all primes less than a given value.
The iterator produced by primes_less_than(n)
generates the same primes as the
iterator produced by primes().take_while(|&p| p < n)
, but the latter would be
slower because it doesn’t know in advance how large its prime sieve should be, and
might have to create larger and larger prime sieves.
§Worst-case complexity (amortized)
$T(i) = O(\log \log i)$
$M(i) = O(1)$
where $T$ is time, $M$ is additional memory, and $i$ is the iteration index.
§Examples
See here.
Source§fn primes_less_than_or_equal_to(n: &u8) -> PrimesLessThanIterator<u8> ⓘ
fn primes_less_than_or_equal_to(n: &u8) -> PrimesLessThanIterator<u8> ⓘ
Returns an iterator that generates all primes less than or equal to a given value.
The iterator produced by primes_less_than_or_equal_to(n)
generates the same primes
as the iterator produced by primes().take_while(|&p| p <= n)
, but the latter would
be slower because it doesn’t know in advance how large its prime sieve should be,
and might have to create larger and larger prime sieves.
§Worst-case complexity (amortized)
$T(i) = O(\log \log i)$
$M(i) = O(1)$
where $T$ is time, $M$ is additional memory, and $i$ is the iteration index.
§Examples
See here.
Source§fn primes() -> PrimesIterator<u8> ⓘ
fn primes() -> PrimesIterator<u8> ⓘ
Returns all primes that fit into the specified type.
The iterator produced by primes(n)
generates the same primes as the iterator
produced by primes_less_than_or_equal_to(T::MAX)
. If you really need to generate
every prime, and T
is u32
or smaller, then you should use the latter, as it
will allocate all the needed memory at once. If T
is u64
or larger, or if you
probably don’t need every prime, then primes()
will be faster as it won’t allocate
too much memory right away.
§Worst-case complexity (amortized)
$T(i) = O(\log \log i)$
$M(i) = O(1)$
where $T$ is time, $M$ is additional memory, and $i$ is the iteration index.
§Examples
See here.
type I = PrimesIterator<u8>
type LI = PrimesLessThanIterator<u8>
Source§impl Primes for u16
impl Primes for u16
Source§fn primes_less_than(n: &u16) -> PrimesLessThanIterator<u16> ⓘ
fn primes_less_than(n: &u16) -> PrimesLessThanIterator<u16> ⓘ
Returns an iterator that generates all primes less than a given value.
The iterator produced by primes_less_than(n)
generates the same primes as the
iterator produced by primes().take_while(|&p| p < n)
, but the latter would be
slower because it doesn’t know in advance how large its prime sieve should be, and
might have to create larger and larger prime sieves.
§Worst-case complexity (amortized)
$T(i) = O(\log \log i)$
$M(i) = O(1)$
where $T$ is time, $M$ is additional memory, and $i$ is the iteration index.
§Examples
See here.
Source§fn primes_less_than_or_equal_to(n: &u16) -> PrimesLessThanIterator<u16> ⓘ
fn primes_less_than_or_equal_to(n: &u16) -> PrimesLessThanIterator<u16> ⓘ
Returns an iterator that generates all primes less than or equal to a given value.
The iterator produced by primes_less_than_or_equal_to(n)
generates the same primes
as the iterator produced by primes().take_while(|&p| p <= n)
, but the latter would
be slower because it doesn’t know in advance how large its prime sieve should be,
and might have to create larger and larger prime sieves.
§Worst-case complexity (amortized)
$T(i) = O(\log \log i)$
$M(i) = O(1)$
where $T$ is time, $M$ is additional memory, and $i$ is the iteration index.
§Examples
See here.
Source§fn primes() -> PrimesIterator<u16> ⓘ
fn primes() -> PrimesIterator<u16> ⓘ
Returns all primes that fit into the specified type.
The iterator produced by primes(n)
generates the same primes as the iterator
produced by primes_less_than_or_equal_to(T::MAX)
. If you really need to generate
every prime, and T
is u32
or smaller, then you should use the latter, as it
will allocate all the needed memory at once. If T
is u64
or larger, or if you
probably don’t need every prime, then primes()
will be faster as it won’t allocate
too much memory right away.
§Worst-case complexity (amortized)
$T(i) = O(\log \log i)$
$M(i) = O(1)$
where $T$ is time, $M$ is additional memory, and $i$ is the iteration index.
§Examples
See here.
type I = PrimesIterator<u16>
type LI = PrimesLessThanIterator<u16>
Source§impl Primes for u32
impl Primes for u32
Source§fn primes_less_than(n: &u32) -> PrimesLessThanIterator<u32> ⓘ
fn primes_less_than(n: &u32) -> PrimesLessThanIterator<u32> ⓘ
Returns an iterator that generates all primes less than a given value.
The iterator produced by primes_less_than(n)
generates the same primes as the
iterator produced by primes().take_while(|&p| p < n)
, but the latter would be
slower because it doesn’t know in advance how large its prime sieve should be, and
might have to create larger and larger prime sieves.
§Worst-case complexity (amortized)
$T(i) = O(\log \log i)$
$M(i) = O(1)$
where $T$ is time, $M$ is additional memory, and $i$ is the iteration index.
§Examples
See here.
Source§fn primes_less_than_or_equal_to(n: &u32) -> PrimesLessThanIterator<u32> ⓘ
fn primes_less_than_or_equal_to(n: &u32) -> PrimesLessThanIterator<u32> ⓘ
Returns an iterator that generates all primes less than or equal to a given value.
The iterator produced by primes_less_than_or_equal_to(n)
generates the same primes
as the iterator produced by primes().take_while(|&p| p <= n)
, but the latter would
be slower because it doesn’t know in advance how large its prime sieve should be,
and might have to create larger and larger prime sieves.
§Worst-case complexity (amortized)
$T(i) = O(\log \log i)$
$M(i) = O(1)$
where $T$ is time, $M$ is additional memory, and $i$ is the iteration index.
§Examples
See here.
Source§fn primes() -> PrimesIterator<u32> ⓘ
fn primes() -> PrimesIterator<u32> ⓘ
Returns all primes that fit into the specified type.
The iterator produced by primes(n)
generates the same primes as the iterator
produced by primes_less_than_or_equal_to(T::MAX)
. If you really need to generate
every prime, and T
is u32
or smaller, then you should use the latter, as it
will allocate all the needed memory at once. If T
is u64
or larger, or if you
probably don’t need every prime, then primes()
will be faster as it won’t allocate
too much memory right away.
§Worst-case complexity (amortized)
$T(i) = O(\log \log i)$
$M(i) = O(1)$
where $T$ is time, $M$ is additional memory, and $i$ is the iteration index.
§Examples
See here.
type I = PrimesIterator<u32>
type LI = PrimesLessThanIterator<u32>
Source§impl Primes for u64
impl Primes for u64
Source§fn primes_less_than(n: &u64) -> PrimesLessThanIterator<u64> ⓘ
fn primes_less_than(n: &u64) -> PrimesLessThanIterator<u64> ⓘ
Returns an iterator that generates all primes less than a given value.
The iterator produced by primes_less_than(n)
generates the same primes as the
iterator produced by primes().take_while(|&p| p < n)
, but the latter would be
slower because it doesn’t know in advance how large its prime sieve should be, and
might have to create larger and larger prime sieves.
§Worst-case complexity (amortized)
$T(i) = O(\log \log i)$
$M(i) = O(1)$
where $T$ is time, $M$ is additional memory, and $i$ is the iteration index.
§Examples
See here.
Source§fn primes_less_than_or_equal_to(n: &u64) -> PrimesLessThanIterator<u64> ⓘ
fn primes_less_than_or_equal_to(n: &u64) -> PrimesLessThanIterator<u64> ⓘ
Returns an iterator that generates all primes less than or equal to a given value.
The iterator produced by primes_less_than_or_equal_to(n)
generates the same primes
as the iterator produced by primes().take_while(|&p| p <= n)
, but the latter would
be slower because it doesn’t know in advance how large its prime sieve should be,
and might have to create larger and larger prime sieves.
§Worst-case complexity (amortized)
$T(i) = O(\log \log i)$
$M(i) = O(1)$
where $T$ is time, $M$ is additional memory, and $i$ is the iteration index.
§Examples
See here.
Source§fn primes() -> PrimesIterator<u64> ⓘ
fn primes() -> PrimesIterator<u64> ⓘ
Returns all primes that fit into the specified type.
The iterator produced by primes(n)
generates the same primes as the iterator
produced by primes_less_than_or_equal_to(T::MAX)
. If you really need to generate
every prime, and T
is u32
or smaller, then you should use the latter, as it
will allocate all the needed memory at once. If T
is u64
or larger, or if you
probably don’t need every prime, then primes()
will be faster as it won’t allocate
too much memory right away.
§Worst-case complexity (amortized)
$T(i) = O(\log \log i)$
$M(i) = O(1)$
where $T$ is time, $M$ is additional memory, and $i$ is the iteration index.
§Examples
See here.
type I = PrimesIterator<u64>
type LI = PrimesLessThanIterator<u64>
Source§impl Primes for u128
impl Primes for u128
Source§fn primes_less_than(n: &u128) -> PrimesLessThanIterator<u128> ⓘ
fn primes_less_than(n: &u128) -> PrimesLessThanIterator<u128> ⓘ
Returns an iterator that generates all primes less than a given value.
The iterator produced by primes_less_than(n)
generates the same primes as the
iterator produced by primes().take_while(|&p| p < n)
, but the latter would be
slower because it doesn’t know in advance how large its prime sieve should be, and
might have to create larger and larger prime sieves.
§Worst-case complexity (amortized)
$T(i) = O(\log \log i)$
$M(i) = O(1)$
where $T$ is time, $M$ is additional memory, and $i$ is the iteration index.
§Examples
See here.
Source§fn primes_less_than_or_equal_to(n: &u128) -> PrimesLessThanIterator<u128> ⓘ
fn primes_less_than_or_equal_to(n: &u128) -> PrimesLessThanIterator<u128> ⓘ
Returns an iterator that generates all primes less than or equal to a given value.
The iterator produced by primes_less_than_or_equal_to(n)
generates the same primes
as the iterator produced by primes().take_while(|&p| p <= n)
, but the latter would
be slower because it doesn’t know in advance how large its prime sieve should be,
and might have to create larger and larger prime sieves.
§Worst-case complexity (amortized)
$T(i) = O(\log \log i)$
$M(i) = O(1)$
where $T$ is time, $M$ is additional memory, and $i$ is the iteration index.
§Examples
See here.
Source§fn primes() -> PrimesIterator<u128> ⓘ
fn primes() -> PrimesIterator<u128> ⓘ
Returns all primes that fit into the specified type.
The iterator produced by primes(n)
generates the same primes as the iterator
produced by primes_less_than_or_equal_to(T::MAX)
. If you really need to generate
every prime, and T
is u32
or smaller, then you should use the latter, as it
will allocate all the needed memory at once. If T
is u64
or larger, or if you
probably don’t need every prime, then primes()
will be faster as it won’t allocate
too much memory right away.
§Worst-case complexity (amortized)
$T(i) = O(\log \log i)$
$M(i) = O(1)$
where $T$ is time, $M$ is additional memory, and $i$ is the iteration index.
§Examples
See here.
type I = PrimesIterator<u128>
type LI = PrimesLessThanIterator<u128>
Source§impl Primes for usize
impl Primes for usize
Source§fn primes_less_than(n: &usize) -> PrimesLessThanIterator<usize> ⓘ
fn primes_less_than(n: &usize) -> PrimesLessThanIterator<usize> ⓘ
Returns an iterator that generates all primes less than a given value.
The iterator produced by primes_less_than(n)
generates the same primes as the
iterator produced by primes().take_while(|&p| p < n)
, but the latter would be
slower because it doesn’t know in advance how large its prime sieve should be, and
might have to create larger and larger prime sieves.
§Worst-case complexity (amortized)
$T(i) = O(\log \log i)$
$M(i) = O(1)$
where $T$ is time, $M$ is additional memory, and $i$ is the iteration index.
§Examples
See here.
Source§fn primes_less_than_or_equal_to(n: &usize) -> PrimesLessThanIterator<usize> ⓘ
fn primes_less_than_or_equal_to(n: &usize) -> PrimesLessThanIterator<usize> ⓘ
Returns an iterator that generates all primes less than or equal to a given value.
The iterator produced by primes_less_than_or_equal_to(n)
generates the same primes
as the iterator produced by primes().take_while(|&p| p <= n)
, but the latter would
be slower because it doesn’t know in advance how large its prime sieve should be,
and might have to create larger and larger prime sieves.
§Worst-case complexity (amortized)
$T(i) = O(\log \log i)$
$M(i) = O(1)$
where $T$ is time, $M$ is additional memory, and $i$ is the iteration index.
§Examples
See here.
Source§fn primes() -> PrimesIterator<usize> ⓘ
fn primes() -> PrimesIterator<usize> ⓘ
Returns all primes that fit into the specified type.
The iterator produced by primes(n)
generates the same primes as the iterator
produced by primes_less_than_or_equal_to(T::MAX)
. If you really need to generate
every prime, and T
is u32
or smaller, then you should use the latter, as it
will allocate all the needed memory at once. If T
is u64
or larger, or if you
probably don’t need every prime, then primes()
will be faster as it won’t allocate
too much memory right away.
§Worst-case complexity (amortized)
$T(i) = O(\log \log i)$
$M(i) = O(1)$
where $T$ is time, $M$ is additional memory, and $i$ is the iteration index.
§Examples
See here.