diff --git a/src/uu/factor/src/miller_rabin.rs b/src/uu/factor/src/miller_rabin.rs index d133bc674..45f4243ba 100644 --- a/src/uu/factor/src/miller_rabin.rs +++ b/src/uu/factor/src/miller_rabin.rs @@ -2,10 +2,27 @@ use crate::numeric::*; -// Small set of bases for the Miller-Rabin prime test, valid for all 64b integers; -// discovered by Jim Sinclair on 2011-04-20, see miller-rabin.appspot.com -#[allow(clippy::unreadable_literal)] -const BASIS: [u64; 7] = [2, 325, 9375, 28178, 450775, 9780504, 1795265022]; +pub(crate) trait Basis { + const BASIS: &'static [u64]; +} + +impl Basis for Montgomery { + // Small set of bases for the Miller-Rabin prime test, valid for all 64b integers; + // discovered by Jim Sinclair on 2011-04-20, see miller-rabin.appspot.com + #[allow(clippy::unreadable_literal)] + const BASIS: &'static [u64] = &[2, 325, 9375, 28178, 450775, 9780504, 1795265022]; +} + +impl Basis for Montgomery32 { + // Small set of bases for the Miller-Rabin prime test, valid for all 32b integers; + // discovered by Steve Worley on 2013-05-27, see miller-rabin.appspot.com + #[allow(clippy::unreadable_literal)] + const BASIS: &'static [u64] = &[ + 4230279247111683200, + 14694767155120705706, + 16641139526367750375, + ]; +} #[derive(Eq, PartialEq)] pub(crate) enum Result { @@ -23,7 +40,7 @@ impl Result { // Deterministic Miller-Rabin primality-checking algorithm, adapted to extract // (some) dividers; it will fail to factor strong pseudoprimes. #[allow(clippy::many_single_char_names)] -pub(crate) fn test(m: A) -> Result { +pub(crate) fn test(m: A) -> Result { use self::Result::*; let n = m.modulus(); @@ -41,7 +58,7 @@ pub(crate) fn test(m: A) -> Result { let one = m.one(); let minus_one = m.minus_one(); - for _a in BASIS.iter() { + for _a in A::BASIS.iter() { let _a = _a % n; if _a == 0 { break; diff --git a/src/uu/factor/src/rho.rs b/src/uu/factor/src/rho.rs index d2023f70f..29c58feb8 100644 --- a/src/uu/factor/src/rho.rs +++ b/src/uu/factor/src/rho.rs @@ -15,7 +15,7 @@ use crate::miller_rabin::Result::*; use crate::numeric::*; use crate::{miller_rabin, Factors}; -fn find_divisor(n: A) -> u64 { +fn find_divisor(n: A) -> u64 { #![allow(clippy::many_single_char_names)] let mut rand = { let range = Uniform::new(1, n.modulus()); @@ -48,7 +48,7 @@ fn find_divisor(n: A) -> u64 { } } -fn _factor(num: u64) -> Factors { +fn _factor(num: u64) -> Factors { // Shadow the name, so the recursion automatically goes from “Big” arithmetic to small. let _factor = |n| { if n < (1 << 32) {