in midst of refactor

This commit is contained in:
2024-04-29 21:46:42 +02:00
parent ed0d64d52e
commit aa3f7e99ab
221 changed files with 5431 additions and 685 deletions

View File

@@ -0,0 +1,20 @@
//! Generate valid names from numbers and a character set. For small numbers,
//! the results should be substantially more memorable than the plain numbers.
fn string_from_charset_rec(val: u64, digits: &str) -> String {
let radix = digits.len() as u64;
let mut prefix =
if val > radix { string_from_charset_rec(val / radix, digits) } else { String::new() };
let digit = digits
.chars()
.nth(val as usize - 1)
.unwrap_or_else(|| panic!("Overindexed digit set \"{}\" with {}", digits, val - 1));
prefix.push(digit);
prefix
}
/// Generate alphabetized names from numbers using a set of permitted
/// characters. Especially practical in combination with De Bruijn indices
pub fn string_from_charset(val: u64, digits: &str) -> String {
string_from_charset_rec(val + 1, digits)
}