change sub-byte selection

pull/1/head
Avril 4 years ago
parent 73752743ec
commit 22b4928bbe
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -1,7 +1,7 @@
[package] [package]
name = "khash" name = "khash"
description = "Kana hashes" description = "Kana hashes"
version = "1.0.0" version = "1.1.0"
authors = ["Avril <flanchan@cumallover.me>"] authors = ["Avril <flanchan@cumallover.me>"]
edition = "2018" edition = "2018"
license = "GPL-3.0-or-later" license = "GPL-3.0-or-later"

@ -32,7 +32,7 @@ extern "C" {
uint8_t salt_type; uint8_t salt_type;
uint32_t size; uint32_t size;
uint8_t* body; uint8_t* body;
} khash_salt _deprecated("Use `khash_ctx` instead."); } khash_salt;
/// A valid context for khash functinos. Instantiated with `khash_new_context`. /// A valid context for khash functinos. Instantiated with `khash_new_context`.
typedef struct { typedef struct {

@ -19,7 +19,8 @@ mod tests {
let context = ctx::Context::default(); let context = ctx::Context::default();
let kana = generate(&context, input)?; let kana = generate(&context, input)?;
println!("kana: {}", kana); println!("kana: {}", kana);
assert_eq!(kana, "ワイトひはっトと");
assert_eq!(kana, "ワイトひはぇトョ");
Ok(()) Ok(())
} }
#[test] #[test]

@ -75,7 +75,23 @@ pub fn find_sub(kana: char) -> Option<Vec<char>>
} }
/// Find subs by index. /// Find subs by index.
pub fn sub(i: usize) -> Option<Vec<char>> pub fn sub(i: usize) -> Option<[Option<char>; KANA_SUB.len()]>
{
if i < KANA.len() {
let mut output = [None; KANA_SUB.len()];
for (j, (def,sub)) in (0..).zip(KANA_SUB_VALID_FOR.iter().zip(KANA_SUB.iter()))
{
if def.contains(i) {
output[j] = Some(sub.clone());
}
}
Some(output)
} else {
None
}
}
pub fn sub_old(i: usize) -> Option<Vec<char>>
{ {
if i < KANA.len() { if i < KANA.len() {
let mut output = Vec::with_capacity(KANA_SUB.len()); let mut output = Vec::with_capacity(KANA_SUB.len());

@ -17,6 +17,23 @@ impl Digest {
{ {
let mut d = Self::default(); let mut d = Self::default();
let oneesan = usize::from(from[0]) % map::KANA.len();
d.0 = Some(map::KANA[oneesan]);
if from[1] > 0 {
if let Some(imoutos) = map::sub(oneesan) {
if let Some(imouto) = imoutos[usize::from(from[1]) % map::KANA_SUB.len()]
{
d.1 = Some(imouto);
return d;
}
}
let from = [from[1], 0];
d.1 = Self::new(&from[..]).0;
}
d
// Old
/*let mut d = Self::default();
let oneesan = usize::from(from[0]) % map::KANA.len(); let oneesan = usize::from(from[0]) % map::KANA.len();
d.0 = Some(map::KANA[oneesan]); d.0 = Some(map::KANA[oneesan]);
if from[1] > 0 { if from[1] > 0 {
@ -30,7 +47,7 @@ impl Digest {
let from = [from[1], 0]; let from = [from[1], 0];
d.1 = Self::new(&from[..]).0; d.1 = Self::new(&from[..]).0;
} }
d d*/
/*let oneesan = usize::from(from) % map::KANA.len(); /*let oneesan = usize::from(from) % map::KANA.len();
d.0 = Some(map::KANA[oneesan]); d.0 = Some(map::KANA[oneesan]);
if let Some(imoutos) = map::sub(oneesan) { if let Some(imoutos) = map::sub(oneesan) {

Loading…
Cancel
Save