parent
69edfe4e14
commit
e57b327c57
@ -0,0 +1,10 @@ |
|||||||
|
e4820b45d2277f3844eac66c903e84be |
||||||
|
23170acc097c24edb98fc5488ab033fe |
||||||
|
4a9f51db2c7eba0c724499f749d3176a |
||||||
|
665e5bcb0c20062fe8abaaf4628bb154 |
||||||
|
e8a2cbb6206fc937082bb92e4ed9cd3d |
||||||
|
74a613b8c64fb216dc22d4f2bd4965f4 |
||||||
|
ccb5ed231ba04d750c963668391d1e61 |
||||||
|
d864ae0e66c89cb78345967cb2f3ab6b |
||||||
|
2b56477105d91076030e877c94dd9776 |
||||||
|
732442feac8b5013e16a776486ac5447 |
@ -0,0 +1,48 @@ |
|||||||
|
use packed_simd::u8x32; |
||||||
|
use crate::anagram_logger::log_anagram; |
||||||
|
use crate::dictionary_builder::Dictionary; |
||||||
|
use crate::hash_computer::CHUNK_SIZE; |
||||||
|
use crate::hash_computer::find_hashes; |
||||||
|
use crate::permutations_cache::PermutationsCache; |
||||||
|
|
||||||
|
fn generate_vector_substitutions<'a>(simple_dictionary: &'a Dictionary, permutation: &'a [usize], current_phrase: u8x32, current_phrase_length: usize) -> Box<dyn Iterator<Item = u8x32> + 'a> { |
||||||
|
if permutation.len() == 0 { |
||||||
|
return Box::new(std::iter::once(current_phrase.clone())); |
||||||
|
} |
||||||
|
|
||||||
|
let result = simple_dictionary.words[permutation[0]].iter() |
||||||
|
.flat_map(move |word_info| { |
||||||
|
generate_vector_substitutions(&simple_dictionary, &permutation[1..], current_phrase ^ word_info.get_simd_word_for_offset(current_phrase_length), current_phrase_length + word_info.length + 1).into_iter() |
||||||
|
}); |
||||||
|
return Box::new(result); |
||||||
|
} |
||||||
|
|
||||||
|
fn process_anagram_chunk(chunk: &[u8x32; CHUNK_SIZE], phrase_length: usize, hashes_to_find: &[u32]) -> () { |
||||||
|
match find_hashes(chunk, phrase_length, hashes_to_find) { |
||||||
|
Some(anagrams) => { |
||||||
|
for anagram in anagrams { |
||||||
|
log_anagram(anagram, phrase_length); |
||||||
|
} |
||||||
|
} |
||||||
|
_ => () |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
pub fn analyze_anagrams(anagram_vector: &Vec<usize>, dictionary: &Dictionary, permutations: &PermutationsCache, phrase_length: usize, hashes_to_find: &[u32]) -> () { |
||||||
|
let mut chunk: [u8x32; CHUNK_SIZE] = [u8x32::splat(0); CHUNK_SIZE]; |
||||||
|
let mut chunk_position: usize = 0; |
||||||
|
|
||||||
|
permutations.get_permuted_vectors(&anagram_vector).iter() |
||||||
|
.flat_map(|permuted_vector| { |
||||||
|
generate_vector_substitutions(&dictionary, &permuted_vector, u8x32::splat(0), 0) |
||||||
|
}) |
||||||
|
.for_each(|anagram| { |
||||||
|
chunk[chunk_position] = anagram; |
||||||
|
chunk_position = (chunk_position + 1) % CHUNK_SIZE; |
||||||
|
if chunk_position == 0 { |
||||||
|
process_anagram_chunk(&chunk, phrase_length, hashes_to_find); |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
process_anagram_chunk(&chunk, phrase_length, hashes_to_find); |
||||||
|
} |
@ -1,38 +1,15 @@ |
|||||||
|
use md5; |
||||||
use packed_simd::u8x32; |
use packed_simd::u8x32; |
||||||
use crate::dictionary_builder::Dictionary; |
|
||||||
use crate::dictionary_builder::WordInfo; |
|
||||||
use crate::permutations_cache::PermutationsCache; |
|
||||||
|
|
||||||
fn get_anagram_view_from_simd(simd_vector: u8x32, phrase_length: usize) -> String { |
fn get_anagram_string_from_simd(simd_vector: u8x32, phrase_length: usize) -> String { |
||||||
let mut string_bytes: [u8; 32] = [0; 32]; |
let mut string_bytes: [u8; 32] = [0; 32]; |
||||||
simd_vector.write_to_slice_unaligned(&mut string_bytes); |
simd_vector.write_to_slice_unaligned(&mut string_bytes); |
||||||
|
|
||||||
String::from_utf8_lossy(&string_bytes[0..phrase_length]).into_owned() |
String::from_utf8_lossy(&string_bytes[0..phrase_length]).into_owned() |
||||||
} |
} |
||||||
|
|
||||||
fn generate_vector_substitutions<'a>(simple_dictionary: &'a Vec<Vec<&WordInfo>>, permutation: &'a [usize], current_phrase: u8x32, current_phrase_length: usize) -> Box<dyn Iterator<Item = u8x32> + 'a> { |
pub fn log_anagram(simd_vector: u8x32, phrase_length: usize) -> () { |
||||||
if permutation.len() == 0 { |
let anagram_string = get_anagram_string_from_simd(simd_vector, phrase_length); |
||||||
return Box::new(std::iter::once(current_phrase.clone())); |
let hash = md5::compute(anagram_string.as_bytes()); |
||||||
} |
println!("{:x} {}", hash, anagram_string); |
||||||
|
|
||||||
let result = simple_dictionary[permutation[0]].iter() |
|
||||||
.flat_map(move |&word_info| { |
|
||||||
generate_vector_substitutions(&simple_dictionary, &permutation[1..], current_phrase ^ word_info.get_simd_word_for_offset(current_phrase_length), current_phrase_length + word_info.length + 1).into_iter() |
|
||||||
}); |
|
||||||
return Box::new(result); |
|
||||||
} |
|
||||||
|
|
||||||
pub fn log_anagrams(anagram_vector: &Vec<usize>, dictionary: &Dictionary, permutations: &PermutationsCache, phrase_length: usize) -> () { |
|
||||||
let simple_vector: Vec<usize> = (0..anagram_vector.len()).collect(); |
|
||||||
let simple_dictionary: Vec<Vec<&WordInfo>> = (0..anagram_vector.len()) |
|
||||||
.map(|i| dictionary.words[anagram_vector[i]].iter().map(|word_info| word_info).collect()) |
|
||||||
.collect(); |
|
||||||
|
|
||||||
permutations.get_permuted_vectors(&simple_vector).iter() |
|
||||||
.flat_map(|permuted_vector| { |
|
||||||
generate_vector_substitutions(&simple_dictionary, &permuted_vector, u8x32::splat(0), 0) |
|
||||||
}) |
|
||||||
.for_each(|anagram| { |
|
||||||
println!("{}", get_anagram_view_from_simd(anagram, phrase_length)); |
|
||||||
}) |
|
||||||
} |
} |
Loading…
Reference in new issue