Add ability to calculate ratio

This commit is contained in:
Dima Kudosh
2016-02-15 14:54:32 +03:00
parent 329dc4419a
commit 6bd7dc4b84
2 changed files with 14 additions and 1 deletions
+6 -1
View File
@@ -1,5 +1,5 @@
use std::cmp::Ordering;
use utils::slice_str;
use utils::{slice_str, calculate_ratio};
#[derive(Debug, Clone, Copy)]
pub struct Match{
@@ -162,4 +162,9 @@ impl<'a> SequenceMatcher<'a>{
self.opcodes = Some(opcodes);
return self.opcodes.as_ref().unwrap().clone()
}
pub fn ratio(&mut self) -> f32{
let matches = self.get_matching_blocks().iter().fold(0, |res, &m| res + m.size);
calculate_ratio(matches, self.first_sequence.len() + self.second_sequence.len())
}
}