Skip to content

Commit

Permalink
use externally consistent combination ids in heuristics mode
Browse files Browse the repository at this point in the history
  • Loading branch information
marcustyphoon committed Sep 21, 2024
1 parent e525c51 commit 8615df4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
10 changes: 3 additions & 7 deletions wasm_module/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub fn calculate(
// workerglobal.set_onmessage(Some(on_message_callback.as_ref().unchecked_ref()));

// calculate the result (maxResult best characters) for the given chunks
let mut result = start(&chunks, &settings, &combinations, Some(&workerglobal));
let mut result = start(&chunks, &settings, &combinations, None, Some(&workerglobal));
result.on_complete(&settings, &combinations);

// parse to string
Expand Down Expand Up @@ -79,16 +79,12 @@ pub fn calculate_with_heuristics(

// receive list of combinationIds
let picked_combination_ids = start_with_heuristics(&settings, &combinations);
// transform into combination structs
let mut picked_combinations = vec![];
for id in picked_combination_ids {
picked_combinations.push(combinations.get(id as usize).unwrap().clone());
}

let mut result = start(
&chunks,
&settings,
&picked_combinations,
&combinations,
Some(&picked_combination_ids),
Some(&workerglobal),
);
result.on_complete(&settings, &combinations);
Expand Down
5 changes: 5 additions & 0 deletions wasm_module/src/optimizer_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub fn start(
chunks: &Vec<Vec<Affix>>,
settings: &Settings,
combinations: &Vec<Combination>,
picked_combination_ids: Option<&Vec<u32>>,
workerglobal: Option<&DedicatedWorkerGlobalScope>,
) -> Result {
let rankby = settings.rankby;
Expand All @@ -48,6 +49,10 @@ pub fn start(

// iterate over all combinations
for i in 0..combinations.len() {
if picked_combination_ids.is_some_and(|ids| ids.contains(&(i as u32)) == false) {
continue;
}

let combination = &combinations[i];
character.clear();
character.combination_id = i as u32;
Expand Down

0 comments on commit 8615df4

Please sign in to comment.