run rustfmt on the code

This commit is contained in:
Sylvestre Ledru
2026-02-18 20:43:00 +01:00
parent 48c099b7bb
commit a3186d0944
6 changed files with 17783 additions and 3199 deletions
+6 -3
View File
@@ -265,7 +265,8 @@ impl Default for NaiveBuffer {
impl NaiveBuffer {
#[inline]
#[must_use] pub fn new() -> Self {
#[must_use]
pub fn new() -> Self {
let list = SMALL_PRIMES.iter().map(|&p| u64::from(p)).collect();
NaiveBuffer {
list,
@@ -359,7 +360,8 @@ impl NaiveBuffer {
}
/// Returns all primes ≤ `limit` and takes ownership. The primes are sorted.
#[must_use] pub fn into_primes(mut self, limit: u64) -> std::vec::IntoIter<u64> {
#[must_use]
pub fn into_primes(mut self, limit: u64) -> std::vec::IntoIter<u64> {
self.reserve(limit);
let position = match self.list.binary_search(&limit) {
Ok(p) => p + 1,
@@ -379,7 +381,8 @@ impl NaiveBuffer {
}
/// Returns primes of certain amount counting from 2 and takes ownership. The primes are sorted.
#[must_use] pub fn into_nprimes(mut self, count: usize) -> std::vec::IntoIter<u64> {
#[must_use]
pub fn into_nprimes(mut self, count: usize) -> std::vec::IntoIter<u64> {
let (_, bound) = nth_prime_bounds(&(count as u64))
.expect("Estimated size of the largest prime will be larger than u64 limit");
self.reserve(bound);
-1
View File
@@ -157,7 +157,6 @@ impl ExactRoots for BigInt {
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn exact_root_test() {
+1376 -1367
View File
File diff suppressed because it is too large Load Diff
+9 -3
View File
@@ -83,7 +83,10 @@ impl_randprime_prim!(u8 u16 u32 u64);
impl<R: Rng> RandPrime<u128> for R {
#[inline]
fn gen_prime(&mut self, bit_size: usize, config: Option<PrimalityTestConfig>) -> u128 {
assert!(bit_size <= (u128::BITS as usize), "The given bit size limit exceeded the capacity of the integer type!");
assert!(
bit_size <= (u128::BITS as usize),
"The given bit size limit exceeded the capacity of the integer type!"
);
loop {
let t: u128 = self.gen();
@@ -99,7 +102,10 @@ impl<R: Rng> RandPrime<u128> for R {
#[inline]
fn gen_prime_exact(&mut self, bit_size: usize, config: Option<PrimalityTestConfig>) -> u128 {
assert!(bit_size <= (u128::BITS as usize), "The given bit size limit exceeded the capacity of the integer type!");
assert!(
bit_size <= (u128::BITS as usize),
"The given bit size limit exceeded the capacity of the integer type!"
);
loop {
let t: u128 = self.gen();
@@ -255,7 +261,7 @@ mod tests {
let p: u128 = rng.gen_prime_exact(128, None);
assert!(is_prime(&p, None).probably());
assert_eq!(p.leading_zeros(), 0);
// test random safe prime generation
let p: u8 = rng.gen_safe_prime_exact(8);
assert!(is_safe_prime(&p).probably());
+16384 -1821
View File
File diff suppressed because it is too large Load Diff
+8 -4
View File
@@ -34,7 +34,8 @@ impl Primality {
/// Check whether the resule indicates that the number is
/// (very) probably a prime. Return false only on [`Primality::No`]
#[inline(always)]
#[must_use] pub fn probably(self) -> bool {
#[must_use]
pub fn probably(self) -> bool {
match self {
Primality::No => false,
_ => true,
@@ -112,14 +113,16 @@ impl PrimalityTestConfig {
/// Create a configuration with a very strong primality check. It's based on
/// the **strongest deterministic primality testing** and some SPRP tests with
/// random bases.
#[must_use] pub fn strict() -> Self {
#[must_use]
pub fn strict() -> Self {
let mut config = Self::bpsw();
config.sprp_random_trials = 1;
config
}
/// Create a configuration for Baillie-PSW test (base 2 SPRP test + SLPRP test)
#[must_use] pub fn bpsw() -> Self {
#[must_use]
pub fn bpsw() -> Self {
Self {
sprp_trials: 1,
sprp_random_trials: 0,
@@ -172,7 +175,8 @@ impl Default for FactorizationConfig {
impl FactorizationConfig {
/// Same as the default configuration but with strict primality check
#[must_use] pub fn strict() -> Self {
#[must_use]
pub fn strict() -> Self {
let mut config = Self::default();
config.primality_config = PrimalityTestConfig::strict();
config