From 53fff5d2f7fc007476e4c4850bd4f974f488b13e Mon Sep 17 00:00:00 2001 From: Andreas Grois Date: Sun, 23 Oct 2022 15:22:20 +0200 Subject: Rename "potency" to "power", the English term. It seems English doesn't use the word potency in this context, but rather uses power. --- .../base_conversion/iterative_conversion.rs | 32 +++++++++++----------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'src/passwordmaker/base_conversion/iterative_conversion.rs') diff --git a/src/passwordmaker/base_conversion/iterative_conversion.rs b/src/passwordmaker/base_conversion/iterative_conversion.rs index f5db0f7..e88f379 100644 --- a/src/passwordmaker/base_conversion/iterative_conversion.rs +++ b/src/passwordmaker/base_conversion/iterative_conversion.rs @@ -14,34 +14,34 @@ use std::iter::successors; pub(crate) struct IterativeBaseConversion{ current_value : V, - current_base_potency : V, + current_base_power : V, remaining_digits : usize, base : B, } impl IterativeBaseConversion where V: for<'a> From<&'a B> + //could be replaced by num::traits::identities::One. - ConstantMaxPotencyCache, - for<'a> &'a V : Mul<&'a B, Output = Option> + //used to get the first current_base_potency. + ConstantMaxPowerCache, + for<'a> &'a V : Mul<&'a B, Output = Option> + //used to get the first current_base_power. Mul<&'a V, Output = Option> { pub(super) fn new(value : V, base : B) -> Self{ - let PotencyAndExponent{power : current_base_potency, exponent : highest_fitting_exponent} = Self::find_highest_fitting_power(&base); + let PowerAndExponent{power : current_base_power, exponent : highest_fitting_exponent} = Self::find_highest_fitting_power(&base); Self{ current_value : value, - current_base_potency, + current_base_power, remaining_digits: highest_fitting_exponent + 1, //to the power of 0 is a digit too. Soo, if base^n is the largest fitting exponent, n+1 digits. base, } } - fn find_highest_fitting_power(base : &B) -> PotencyAndExponent { - V::lookup(base).map(|(potency,count)| PotencyAndExponent{ power: potency, exponent: count }) + fn find_highest_fitting_power(base : &B) -> PowerAndExponent { + V::lookup(base).map(|(power,count)| PowerAndExponent{ power, exponent: count }) .unwrap_or_else(|| Self::find_highest_fitting_power_non_cached(base)) } //public for unit tests in cache, which is not a sub-module of this. - pub(super) fn find_highest_fitting_power_non_cached(base : &B) -> PotencyAndExponent { + pub(super) fn find_highest_fitting_power_non_cached(base : &B) -> PowerAndExponent { let base_v = base.into(); let exp_result = successors(Some((base_v, 1)), |(p, e)| { @@ -49,15 +49,15 @@ impl IterativeBaseConversion }).last(); - let result = successors(exp_result, |(potency, count)| (potency * base).map(|v| (v, count + 1))) + let result = successors(exp_result, |(power, count)| (power * base).map(|v| (v, count + 1))) .last() .expect("Cannot fail, first entry is Some (required V : From) and there's no filtering."); - PotencyAndExponent{ power : result.0, exponent : result.1 } + PowerAndExponent{ power : result.0, exponent : result.1 } } } impl std::iter::Iterator for IterativeBaseConversion - where V : for<'a> DivAssign<&'a B> + //used between steps to go to next-lower current_base_potency + where V : for<'a> DivAssign<&'a B> + //used between steps to go to next-lower current_base_power RemAssignWithQuotient+ //used to get the result of each step. TryInto //used to convert the result of each step. We _know_ this cannot fail, but requiring Into would be wrong. { @@ -67,9 +67,9 @@ impl std::iter::Iterator for IterativeBaseConversion if self.remaining_digits == 0 { None } else { - let result = self.current_value.rem_assign_with_quotient(&self.current_base_potency); + let result = self.current_value.rem_assign_with_quotient(&self.current_base_power); - self.current_base_potency /= &self.base; + self.current_base_power /= &self.base; self.remaining_digits = self.remaining_digits - 1; //this cannot ever yield None. @@ -86,7 +86,7 @@ impl std::iter::ExactSizeIterator for IterativeBaseConversion where IterativeBaseConversion : Iterator {} -pub(super) struct PotencyAndExponent{ +pub(super) struct PowerAndExponent{ pub(super) power : V, pub(super) exponent : usize, } @@ -96,7 +96,7 @@ pub(crate) trait RemAssignWithQuotient{ fn rem_assign_with_quotient(&mut self, divisor : &Self) -> Self; } -pub(crate) trait ConstantMaxPotencyCache where Self : Sized{ +pub(crate) trait ConstantMaxPowerCache where Self : Sized{ fn lookup(_base : &B) -> Option<(Self, usize)> { None } } @@ -150,7 +150,7 @@ mod iterative_conversion_tests{ } } - impl ConstantMaxPotencyCache for MyU128{} + impl ConstantMaxPowerCache for MyU128{} #[test] fn test_simple_u128_to_hex_conversion(){ -- cgit v1.2.3