change sub-byte selection

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

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

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

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

@ -75,7 +75,23 @@ pub fn find_sub(kana: char) -> Option<Vec<char>>
}
/// 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() {
let mut output = Vec::with_capacity(KANA_SUB.len());

@ -21,9 +21,9 @@ impl Digest {
d.0 = Some(map::KANA[oneesan]);
if from[1] > 0 {
if let Some(imoutos) = map::sub(oneesan) {
let one = (usize::from(from[1]) / map::KANA.len()) % 2;
if imoutos.len() > 0 && one > 0{
d.1 = Some(imoutos[usize::from(from[1]) % imoutos.len()]);
if let Some(imouto) = imoutos[usize::from(from[1]) % map::KANA_SUB.len()]
{
d.1 = Some(imouto);
return d;
}
}
@ -31,16 +31,33 @@ impl Digest {
d.1 = Self::new(&from[..]).0;
}
d
// Old
/*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) {
let one = (usize::from(from[1]) / map::KANA.len()) % 2;
if imoutos.len() > 0 && one > 0{
d.1 = Some(imoutos[usize::from(from[1]) % imoutos.len()]);
return d;
}
}
let from = [from[1], 0];
d.1 = Self::new(&from[..]).0;
}
d*/
/*let oneesan = usize::from(from) % map::KANA.len();
d.0 = Some(map::KANA[oneesan]);
if let Some(imoutos) = map::sub(oneesan) {
d.0 = Some(map::KANA[oneesan]);
if let Some(imoutos) = map::sub(oneesan) {
if imoutos.len() > 0 {
}
} else {
}
} else {
}
}
return d;*/
return d;*/
}
}

Loading…
Cancel
Save