vyre 0.4.0

GPU compute intermediate representation with a standard operation library
Documentation
// Substring all-matches operation module.



// Backend-specific lowering marker.



// CPU reference kernel for `string_matching.substring_find_all`.

use crate::ops::string_matching::search_contract::{to_u32_offset, validate_search_inputs, MatchError};

/// Return all overlapping byte offsets where `needle` appears in `haystack`.
///
/// An empty needle matches every byte boundary.
///
/// # Errors
///
/// Returns `Fix: ...` when either input exceeds the documented T47 cap.
pub fn substring_find_all(haystack: &[u8], needle: &[u8]) -> Result<Vec<u32>, MatchError> {
    validate_search_inputs(haystack, needle)?;
    if needle.is_empty() {
        let mut offsets = Vec::with_capacity(haystack.len() + 1);
        for index in 0..=haystack.len() {
            offsets.push(to_u32_offset(index)?);
        }
        return Ok(offsets);
    }
    let mut offsets = Vec::new();
    for (index, window) in haystack.windows(needle.len()).enumerate() {
        if window == needle {
            offsets.push(to_u32_offset(index)?);
        }
    }
    Ok(offsets)
}