Change algorithm for finding largest common sequence, change SequenceMatcher to generic

This commit is contained in:
Dima Kudosh
2016-02-27 21:55:43 +03:00
parent 43a88b17b2
commit 792515fb0d
4 changed files with 232 additions and 119 deletions
+14 -15
View File
@@ -1,17 +1,3 @@
pub fn slice_str(string: &str, start: usize, end: usize) -> Option<&str>
{
if start >= end{
return None
}
if start > string.len() || end > string.len(){
return None
}
unsafe{
Some(string.slice_unchecked(start, end))
}
}
pub fn calculate_ratio(matches: usize, length: usize) -> f32{
if length != 0{
return 2.0 * matches as f32 / length as f32
@@ -36,4 +22,17 @@ pub fn count_leading(line: &str, c: char) -> usize {
i += 1;
}
return i
}
}
pub fn format_range_unified(start:usize, end: usize) -> String {
let mut beginning = start + 1;
let length = end - start;
if length == 1 {
return format!("{}", beginning)
}
if length == 0 {
beginning -= 1;
}
format!("{},{}", beginning, length)
}