Last active
August 29, 2015 14:02
-
-
Save Meyermagic/0399fc1a73c09c671262 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Counts the number of (non-overlapping) elements matching at the start and end of each slice | |
fn common_affix<E: TotalEq>(old: &[E], new: &[E]) -> (uint, uint) { | |
let shorter = min(old.len(), new.len()); | |
let mut common_prefix = 0; | |
for i in range(0, shorter) { | |
if old.get(i) != new.get(i) { | |
break; | |
} | |
common_prefix += 1; | |
} | |
let mut common_suffix = 0; | |
for i in range(0, shorter - common_prefix) { | |
if old.get((old.len() - 1) - i) != new.get((new.len() - 1) - i) { | |
break; | |
} | |
common_suffix += 1; | |
} | |
return (common_prefix, common_suffix); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment