From 934025cd3dc22049285ac37ebe5b298716511200 Mon Sep 17 00:00:00 2001 From: Hesam Pakdaman Date: Sun, 28 Apr 2024 21:29:34 +0200 Subject: [PATCH] Use TWO and ONE instead of U512::from(..) --- src/algorithms/pollards_rho.rs | 4 ++-- src/algorithms/pollards_rho/utils.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/algorithms/pollards_rho.rs b/src/algorithms/pollards_rho.rs index 7fd0cbe..3f17e43 100644 --- a/src/algorithms/pollards_rho.rs +++ b/src/algorithms/pollards_rho.rs @@ -10,9 +10,9 @@ pub struct PollardsRho; impl Factorize for PollardsRho { fn factorize(n: &U512) -> U512 { - let init = U512::from(2u8); + let init = U512::TWO; let pseudorandom_fn = utils::generate_pseudorandom_fn(n); - let finished = move |x: &U512, y: &U512| x.abs_diff(*y).gcd(n) != U512::from(1u8); + let finished = move |x: &U512, y: &U512| x.abs_diff(*y).gcd(n) != U512::ONE; let (tortoise, hare) = utils::floyds_cycle_detection(init, &pseudorandom_fn, &finished); hare.abs_diff(tortoise).gcd(n) } diff --git a/src/algorithms/pollards_rho/utils.rs b/src/algorithms/pollards_rho/utils.rs index c7b7cc0..9ee3474 100644 --- a/src/algorithms/pollards_rho/utils.rs +++ b/src/algorithms/pollards_rho/utils.rs @@ -21,5 +21,5 @@ pub fn generate_pseudorandom_fn(n: &'_ U512) -> impl Fn(&U512) -> U512 + '_ { } fn random_integer(bound: &U512) -> U512 { - rand::thread_rng().gen_range(U512::from(2u8)..*bound) + rand::thread_rng().gen_range(U512::TWO..*bound) }