mirror of
https://github.com/kmc7468/cs220.git
synced 2025-12-15 06:28:46 +00:00
Update assignment 6
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
//! Assignment 6: Mastering advanced types.
|
//! Assignment 6: Mastering advanced types (1/2).
|
||||||
//!
|
//!
|
||||||
//! The primary goal of this assignment is to understand generics, traits, and lifetimes.
|
//! The primary goal of this assignment is to understand generics, traits, and lifetimes.
|
||||||
//!
|
//!
|
||||||
@@ -140,26 +140,3 @@ impl<C: Semiring> Polynomial<C> {
|
|||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct FindIter<'s, T: Eq> {
|
|
||||||
query: &'s [T],
|
|
||||||
base: &'s [T],
|
|
||||||
curr: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: Eq> Iterator for FindIter<'_, T> {
|
|
||||||
type Item = usize;
|
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns an iterator over substring query indexes in the base.
|
|
||||||
pub fn find<'s, T: Eq>(query: &'s [T], base: &'s [T]) -> impl 's + Iterator<Item = usize> {
|
|
||||||
FindIter {
|
|
||||||
query,
|
|
||||||
base,
|
|
||||||
curr: 0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -88,27 +88,4 @@ mod test {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_find() {
|
|
||||||
assert_eq!(
|
|
||||||
find("abc".as_bytes(), "abcdabcd".as_bytes()).collect::<Vec<usize>>(),
|
|
||||||
vec![0, 4]
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
find("aaba".as_bytes(), "aabaacaadaabaaba".as_bytes()).collect::<Vec<usize>>(),
|
|
||||||
vec![0, 9, 12]
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
find("ababac".as_bytes(), "abababcabababcabababc".as_bytes()).collect::<Vec<usize>>(),
|
|
||||||
vec![]
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
find("ababc".as_bytes(), "abc".as_bytes()).collect::<Vec<usize>>(),
|
|
||||||
vec![]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user