aboutsummaryrefslogtreecommitdiff
path: root/src/passwordmaker/base_conversion/iterative_conversion_impl
diff options
context:
space:
mode:
authorAndreas Grois <andi@grois.info>2022-10-23 15:22:20 +0200
committerAndreas Grois <andi@grois.info>2022-10-23 15:22:20 +0200
commit53fff5d2f7fc007476e4c4850bd4f974f488b13e (patch)
treeb110bf2dc3c7d8631821c7435d27fea3aeca10ef /src/passwordmaker/base_conversion/iterative_conversion_impl
parentd5b30baf4dd8ff8dbc4c0bd22b9178c914cbe973 (diff)
Rename "potency" to "power", the English term.
It seems English doesn't use the word potency in this context, but rather uses power.
Diffstat (limited to 'src/passwordmaker/base_conversion/iterative_conversion_impl')
-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
2 files changed, 33 insertions, 33 deletions
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