aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/passwordmaker/base_conversion/iterative_conversion.rs32
-rw-r--r--src/passwordmaker/base_conversion/iterative_conversion_impl/mod.rs4
-rw-r--r--src/passwordmaker/base_conversion/iterative_conversion_impl/precomputed_constants.rs62
-rw-r--r--src/passwordmaker/base_conversion/mod.rs4
4 files changed, 51 insertions, 51 deletions
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<V,B>{
current_value : V,
- current_base_potency : V,
+ current_base_power : V,
remaining_digits : usize,
base : B,
}
impl<V,B> IterativeBaseConversion<V,B>
where V: for<'a> From<&'a B> + //could be replaced by num::traits::identities::One.
- ConstantMaxPotencyCache<B>,
- for<'a> &'a V : Mul<&'a B, Output = Option<V>> + //used to get the first current_base_potency.
+ ConstantMaxPowerCache<B>,
+ for<'a> &'a V : Mul<&'a B, Output = Option<V>> + //used to get the first current_base_power.
Mul<&'a V, Output = Option<V>>
{
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> {
- V::lookup(base).map(|(potency,count)| PotencyAndExponent{ power: potency, exponent: count })
+ fn find_highest_fitting_power(base : &B) -> PowerAndExponent<V> {
+ 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<V> {
+ pub(super) fn find_highest_fitting_power_non_cached(base : &B) -> PowerAndExponent<V> {
let base_v = base.into();
let exp_result = successors(Some((base_v, 1)), |(p, e)| {
@@ -49,15 +49,15 @@ impl<V,B> IterativeBaseConversion<V,B>
}).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<B>) and there's no filtering.");
- PotencyAndExponent{ power : result.0, exponent : result.1 }
+ PowerAndExponent{ power : result.0, exponent : result.1 }
}
}
impl<V,B> std::iter::Iterator for IterativeBaseConversion<V,B>
- 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<B> //used to convert the result of each step. We _know_ this cannot fail, but requiring Into would be wrong.
{
@@ -67,9 +67,9 @@ impl<V,B> std::iter::Iterator for IterativeBaseConversion<V,B>
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<V,B> std::iter::ExactSizeIterator for IterativeBaseConversion<V,B>
where IterativeBaseConversion<V,B> : Iterator
{}
-pub(super) struct PotencyAndExponent<V>{
+pub(super) struct PowerAndExponent<V>{
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<B> where Self : Sized{
+pub(crate) trait ConstantMaxPowerCache<B> where Self : Sized{
fn lookup(_base : &B) -> Option<(Self, usize)> { None }
}
@@ -150,7 +150,7 @@ mod iterative_conversion_tests{
}
}
- impl ConstantMaxPotencyCache<u64> for MyU128{}
+ impl ConstantMaxPowerCache<u64> for MyU128{}
#[test]
fn test_simple_u128_to_hex_conversion(){
diff --git a/src/passwordmaker/base_conversion/iterative_conversion_impl/mod.rs b/src/passwordmaker/base_conversion/iterative_conversion_impl/mod.rs
index 7ab9171..ae4aeca 100644
--- a/src/passwordmaker/base_conversion/iterative_conversion_impl/mod.rs
+++ b/src/passwordmaker/base_conversion/iterative_conversion_impl/mod.rs
@@ -13,7 +13,7 @@ use std::fmt::Display;
use std::error::Error;
use std::iter::once;
-use super::iterative_conversion::{RemAssignWithQuotient, ConstantMaxPotencyCache};
+use super::iterative_conversion::{RemAssignWithQuotient, ConstantMaxPowerCache};
//Type to be used as V, with usize as B.
pub(crate) struct SixteenBytes(u128);
@@ -68,7 +68,7 @@ impl Mul<&SixteenBytes> for &SixteenBytes{
}
}
-impl ConstantMaxPotencyCache<usize> for SixteenBytes{}
+impl ConstantMaxPowerCache<usize> for SixteenBytes{}
//--------------------------------------------------------------------------------------------------------------------------------------
//and now the hard part: The same for [u32;N].
diff --git a/src/passwordmaker/base_conversion/iterative_conversion_impl/precomputed_constants.rs b/src/passwordmaker/base_conversion/iterative_conversion_impl/precomputed_constants.rs
index c5a1809..86b8c56 100644
--- a/src/passwordmaker/base_conversion/iterative_conversion_impl/precomputed_constants.rs
+++ b/src/passwordmaker/base_conversion/iterative_conversion_impl/precomputed_constants.rs
@@ -1,15 +1,15 @@
use super::const_mul_usize;
use super::ArbitraryBytes;
-use super::super::iterative_conversion::ConstantMaxPotencyCache;
+use super::super::iterative_conversion::ConstantMaxPowerCache;
-impl ConstantMaxPotencyCache<usize> for ArbitraryBytes<5>{
+impl ConstantMaxPowerCache<usize> for ArbitraryBytes<5>{
fn lookup(base : &usize) -> Option<(Self, usize)> {
- get_from_cache(base, &CONSTANT_MAX_POTENCY_CACHE_5)
+ get_from_cache(base, &CONSTANT_MAX_POWER_CACHE_5)
}
}
-impl ConstantMaxPotencyCache<usize> for ArbitraryBytes<8>{
+impl ConstantMaxPowerCache<usize> for ArbitraryBytes<8>{
fn lookup(base : &usize) -> Option<(Self, usize)> {
- get_from_cache(base, &CONSTANT_MAX_POTENCY_CACHE_8)
+ get_from_cache(base, &CONSTANT_MAX_POWER_CACHE_8)
}
}
@@ -18,12 +18,12 @@ fn get_from_cache<const N : usize>(base : &usize, cache : &[([u32;N], usize)]) -
.map(|c| (ArbitraryBytes(c.0), c.1))
}
-const CONSTANT_MAX_POTENCY_CACHE_5 : [([u32;5],usize);128] = gen_const_max_potency_cache();
-const CONSTANT_MAX_POTENCY_CACHE_8 : [([u32;8],usize);128] = gen_const_max_potency_cache();
+const CONSTANT_MAX_POWER_CACHE_5 : [([u32;5],usize);128] = gen_const_max_power_cache();
+const CONSTANT_MAX_POWER_CACHE_8 : [([u32;8],usize);128] = gen_const_max_power_cache();
//-----------------------------------------------------------------------------------------
-/// This version of find_highest_fitting_potency is not optimized. But it can run in const contexts. Only use it there, use the normal one everywhere else.
+/// This version of find_highest_fitting_power is not optimized. But it can run in const contexts. Only use it there, use the normal one everywhere else.
const fn const_find_highest_fitting_power<const N : usize>(base : usize) -> ([u32;N],usize){
let start = super::from_usize(&base);
@@ -38,7 +38,7 @@ const fn const_find_highest_fitting_power<const N : usize>(base : usize) -> ([u3
//If anyone could tell me how to implement "~const Clone" in stable Rust, I'd be very happy.
const fn const_clone<const N : usize>(x : &ArbitraryBytes<N>) -> ArbitraryBytes<N>{ArbitraryBytes(x.0)}
-pub(crate) const fn gen_const_max_potency_cache<const N : usize, const CNT : usize>() -> [([u32;N],usize);CNT]{
+pub(crate) const fn gen_const_max_power_cache<const N : usize, const CNT : usize>() -> [([u32;N],usize);CNT]{
let mut result = [([0u32;N],0usize);CNT];
let mut i = 0usize;
loop {
@@ -57,69 +57,69 @@ mod iterative_conversion_constants_tests{
#[test]
fn test_overlows_8()
{
- let entries = super::CONSTANT_MAX_POTENCY_CACHE_8.iter().enumerate()
+ let entries = super::CONSTANT_MAX_POWER_CACHE_8.iter().enumerate()
.map(|(i,(p,e))| (i+2, ArbitraryBytes(*p), *e));
- for (base, potency, _exponent) in entries {
- assert!((potency * base).is_none())
+ for (base, power, _exponent) in entries {
+ assert!((power * base).is_none())
}
}
#[test]
fn test_overlows_5()
{
- let entries = super::CONSTANT_MAX_POTENCY_CACHE_5.iter().enumerate()
+ let entries = super::CONSTANT_MAX_POWER_CACHE_5.iter().enumerate()
.map(|(i,(p,e))| (i+2, ArbitraryBytes(*p), *e));
- for (base, potency, _exponent) in entries {
- assert!((potency * base).is_none())
+ for (base, power, _exponent) in entries {
+ assert!((power * base).is_none())
}
}
#[test]
fn test_exponent_8()
{
- let entries = super::CONSTANT_MAX_POTENCY_CACHE_8.iter().enumerate()
+ let entries = super::CONSTANT_MAX_POWER_CACHE_8.iter().enumerate()
.map(|(i,(p,e))| (i+2, ArbitraryBytes(*p), *e));
- for (base, mut potency, exponent) in entries {
+ for (base, mut power, exponent) in entries {
//exponent is the largest fitting exponent. Soo, if we divide exponent times, we should end up with 1.
for _i in 0..exponent {
- let remainder = potency.div_assign_with_remainder_usize(&base);
+ let remainder = power.div_assign_with_remainder_usize(&base);
assert_eq!(remainder, 0);
}
- assert_eq!(potency, (&1usize).into());
+ assert_eq!(power, (&1usize).into());
}
}
#[test]
fn test_exponent_5()
{
- let entries = super::CONSTANT_MAX_POTENCY_CACHE_5.iter().enumerate()
+ let entries = super::CONSTANT_MAX_POWER_CACHE_5.iter().enumerate()
.map(|(i,(p,e))| (i+2, ArbitraryBytes(*p), *e));
- for (base, mut potency, exponent) in entries {
+ for (base, mut power, exponent) in entries {
//exponent is the largest fitting exponent. Soo, if we divide exponent times, we should end up with 1.
for _i in 0..exponent {
- let remainder = potency.div_assign_with_remainder_usize(&base);
+ let remainder = power.div_assign_with_remainder_usize(&base);
assert_eq!(remainder, 0);
}
- assert_eq!(potency, (&1usize).into());
+ assert_eq!(power, (&1usize).into());
}
}
#[test]
- fn highest_fitting_potency_consistency_5(){
+ fn highest_fitting_power_consistency_5(){
use super::super::super::iterative_conversion::IterativeBaseConversion;
- let entries = super::CONSTANT_MAX_POTENCY_CACHE_5.iter().enumerate()
+ let entries = super::CONSTANT_MAX_POWER_CACHE_5.iter().enumerate()
.map(|(i,(p,e))| (i+2, ArbitraryBytes(*p), *e));
- for (base, potency, exponent) in entries {
+ for (base, power, exponent) in entries {
let non_cached_result = IterativeBaseConversion::<ArbitraryBytes<5>,usize>::find_highest_fitting_power_non_cached(&base);
assert_eq!(non_cached_result.exponent,exponent);
- assert_eq!(non_cached_result.power, potency);
+ assert_eq!(non_cached_result.power, power);
}
}
#[test]
- fn highest_fitting_potency_consistency_8(){
+ fn highest_fitting_power_consistency_8(){
use super::super::super::iterative_conversion::IterativeBaseConversion;
- let entries = super::CONSTANT_MAX_POTENCY_CACHE_8.iter().enumerate()
+ let entries = super::CONSTANT_MAX_POWER_CACHE_8.iter().enumerate()
.map(|(i,(p,e))| (i+2, ArbitraryBytes(*p), *e));
- for (base, potency, exponent) in entries {
+ for (base, power, exponent) in entries {
let non_cached_result = IterativeBaseConversion::<ArbitraryBytes<8>,usize>::find_highest_fitting_power_non_cached(&base);
assert_eq!(non_cached_result.exponent,exponent);
- assert_eq!(non_cached_result.power, potency);
+ assert_eq!(non_cached_result.power, power);
}
}
} \ No newline at end of file
diff --git a/src/passwordmaker/base_conversion/mod.rs b/src/passwordmaker/base_conversion/mod.rs
index bb3fbd6..311f7c5 100644
--- a/src/passwordmaker/base_conversion/mod.rs
+++ b/src/passwordmaker/base_conversion/mod.rs
@@ -3,7 +3,7 @@ use iterative_conversion_impl::PadWithAZero;
pub(super) use iterative_conversion::IterativeBaseConversion;
pub(super) use iterative_conversion_impl::{SixteenBytes, ArbitraryBytes};
-use self::iterative_conversion::ConstantMaxPotencyCache;
+use self::iterative_conversion::ConstantMaxPowerCache;
mod iterative_conversion;
mod iterative_conversion_impl;
@@ -16,7 +16,7 @@ pub(super) trait BaseConversion {
impl<T, const N : usize, const M : usize> BaseConversion for T
where T : ToArbitraryBytes<Output = ArbitraryBytes<N>>,
- for<'a> T::Output: From<&'a usize> + From<&'a u32> + PadWithAZero<Output = ArbitraryBytes<M>> + ConstantMaxPotencyCache<usize>,
+ for<'a> T::Output: From<&'a usize> + From<&'a u32> + PadWithAZero<Output = ArbitraryBytes<M>> + ConstantMaxPowerCache<usize>,
{
type Output = IterativeBaseConversion<ArbitraryBytes<N>, usize>;
fn convert_to_base(self, base : usize) -> Self::Output {