/// $fwd is a `impl FnMut(haystack, needle) -> Option<Option<usize>>`. When the /// routine returns `None`, then it's skipped, which is useful for substring /// implementations that don't work for all inputs. #[macro_export]
macro_rules! define_substring_forward_quickcheck {
($fwd:expr) => { #[cfg(not(miri))]
quickcheck::quickcheck! { fn qc_fwd_prefix_is_substring(bs: alloc::vec::Vec<u8>) -> bool { crate::tests::substring::prop::prefix_is_substring(&bs, $fwd)
}
/// $rev is a `impl FnMut(haystack, needle) -> Option<Option<usize>>`. When the /// routine returns `None`, then it's skipped, which is useful for substring /// implementations that don't work for all inputs. #[macro_export]
macro_rules! define_substring_reverse_quickcheck {
($rev:expr) => { #[cfg(not(miri))]
quickcheck::quickcheck! { fn qc_rev_prefix_is_substring(bs: alloc::vec::Vec<u8>) -> bool { crate::tests::substring::prop::prefix_is_substring(&bs, $rev)
}
/// Check that every prefix of the given byte string is a substring. pub(crate) fn prefix_is_substring(
bs: &[u8], mut search: impl FnMut(&[u8], &[u8]) -> Option<Option<usize>>,
) -> bool { for i in0..bs.len().saturating_sub(1) { let prefix = &bs[..i]; let result = match search(bs, prefix) {
None => continue,
Some(result) => result,
}; if !result.is_some() { returnfalse;
}
} true
}
/// Check that every suffix of the given byte string is a substring. pub(crate) fn suffix_is_substring(
bs: &[u8], mut search: impl FnMut(&[u8], &[u8]) -> Option<Option<usize>>,
) -> bool { for i in0..bs.len().saturating_sub(1) { let suffix = &bs[i..]; let result = match search(bs, suffix) {
None => continue,
Some(result) => result,
}; if !result.is_some() { returnfalse;
}
} true
}
/// Check that naive substring search matches the result of the given search /// algorithm. pub(crate) fn same_as_naive(
reverse: bool,
haystack: &[u8],
needle: &[u8], mut search: impl FnMut(&[u8], &[u8]) -> Option<Option<usize>>,
) -> bool { let result = match search(haystack, needle) {
None => returntrue,
Some(result) => result,
}; if reverse {
result == naive::rfind(haystack, needle)
} else {
result == naive::find(haystack, needle)
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.15 Sekunden
(vorverarbeitet am 2026-06-23)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.