Rework sublist to use windows
This commit is contained in:
parent
2e255e2c04
commit
a5cc68b6b3
1 changed files with 1 additions and 7 deletions
|
@ -8,13 +8,7 @@ pub enum Comparison {
|
|||
|
||||
pub fn sublist<T: PartialEq>(first: &[T], second: &[T]) -> Comparison {
|
||||
let is_sublist = |first: &[_], second: &[_]| {
|
||||
second
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, _)| &second[i..])
|
||||
.take_while(|suffix| first.len() <= suffix.len())
|
||||
.map(|suffix| &suffix[..first.len()])
|
||||
.any(|sublist| first == sublist)
|
||||
first.is_empty() || second.windows(first.len()).any(|window| first == window)
|
||||
};
|
||||
if first == second {
|
||||
Comparison::Equal
|
||||
|
|
Loading…
Reference in a new issue