Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

raw_detect perf tweaks #137

Merged
merged 2 commits into from
Mar 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/combined/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,25 @@ pub fn detect(iquery: &InternalQuery) -> Option<Info> {

// TODO: optimize!
pub fn raw_detect(iquery: &InternalQuery) -> RawOutcome {
let alphabet_raw_outcome = alphabets::raw_detect(iquery);
let trigram_raw_outcome = trigrams::raw_detect(iquery);
let alphabet_raw_outcome: alphabets::RawOutcome = alphabets::raw_detect(iquery);
let trigram_raw_outcome: trigrams::RawOutcome = trigrams::raw_detect(iquery);

let alphabet_scores = &alphabet_raw_outcome.scores;
let trigram_scores = &trigram_raw_outcome.scores;
let alphabet_scores: &Vec<(Lang, f64)> = &alphabet_raw_outcome.scores;
let trigram_scores: &Vec<(Lang, f64)> = &trigram_raw_outcome.scores;

let mut all_langs: Vec<Lang> = alphabet_scores.iter().map(|x| x.0).collect();
trigram_scores.iter().for_each(|(lang, _)| {
for (lang, _) in trigram_scores.iter() {
if !all_langs.contains(lang) {
all_langs.push(*lang);
}
});
}

let count = alphabet_raw_outcome.count;

let alphabet_weight = calc_alphabet_weight(count);
let trigram_weight = 1.0 - alphabet_weight;

let mut scores = vec![];
let mut scores = Vec::with_capacity(all_langs.len());

for lang in all_langs {
let a: f64 = alphabet_scores
Expand Down