1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 11:07:44 +00:00

Use Iterator::copied() in sieve.rs (#1774)

This commit is contained in:
est31 2021-04-02 23:30:07 +02:00 committed by GitHub
parent 31f5666727
commit 14a49edd1c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,7 +7,7 @@
// spell-checker:ignore (ToDO) filts, minidx, minkey paridx // spell-checker:ignore (ToDO) filts, minidx, minkey paridx
use std::iter::{Chain, Cycle, Map}; use std::iter::{Chain, Cycle, Copied};
use std::slice::Iter; use std::slice::Iter;
/// A lazy Sieve of Eratosthenes. /// A lazy Sieve of Eratosthenes.
@ -68,27 +68,17 @@ impl Sieve {
#[allow(dead_code)] #[allow(dead_code)]
#[inline] #[inline]
pub fn primes() -> PrimeSieve { pub fn primes() -> PrimeSieve {
#[allow(clippy::trivially_copy_pass_by_ref)] INIT_PRIMES.iter().copied().chain(Sieve::new())
fn deref(x: &u64) -> u64 {
*x
}
let deref = deref as fn(&u64) -> u64;
INIT_PRIMES.iter().map(deref).chain(Sieve::new())
} }
#[allow(dead_code)] #[allow(dead_code)]
#[inline] #[inline]
pub fn odd_primes() -> PrimeSieve { pub fn odd_primes() -> PrimeSieve {
#[allow(clippy::trivially_copy_pass_by_ref)] (&INIT_PRIMES[1..]).iter().copied().chain(Sieve::new())
fn deref(x: &u64) -> u64 {
*x
}
let deref = deref as fn(&u64) -> u64;
(&INIT_PRIMES[1..]).iter().map(deref).chain(Sieve::new())
} }
} }
pub type PrimeSieve = Chain<Map<Iter<'static, u64>, fn(&u64) -> u64>, Sieve>; pub type PrimeSieve = Chain<Copied<Iter<'static, u64>>, Sieve>;
/// An iterator that generates an infinite list of numbers that are /// An iterator that generates an infinite list of numbers that are
/// not divisible by any of 2, 3, 5, or 7. /// not divisible by any of 2, 3, 5, or 7.