Change algorithm for finding largest common sequence, change SequenceMatcher to generic
This commit is contained in:
+14
-15
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user