-
Notifications
You must be signed in to change notification settings - Fork 231
Open
Description
I noticed a possible inconsistency between documentation and code implementation in rust-algorithms/src/string_proc.rs. The details can be found in the following code. The code does not check whether pattern is not empty before it is used but the constraint exists in the documentation.
/// # Panics
///
/// Panics if pattern is empty.
pub fn new(pattern: &'a [C]) -> Self {
let mut fail = Vec::with_capacity(pattern.len());
fail.push(0);
let mut len = 0;
for ch in &pattern[1..] {
while len > 0 && pattern[len] != *ch {
len = fail[len - 1];
}
if pattern[len] == *ch {
len += 1;
}
fail.push(len);
}
Self { pattern, fail }
}
Metadata
Metadata
Assignees
Labels
No labels