Created
December 14, 2025 04:53
-
-
Save jmcph4/d18c544e840274ea70f71def175077aa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use rayon::prelude::*; | |
| pub fn search(haystack: &[(Url, String)], needle: &str) -> Vec<Finding> { | |
| if needle.is_empty() { | |
| return Vec::new(); | |
| } | |
| haystack | |
| .par_iter() | |
| .flat_map_iter(|(url, text)| { | |
| text.lines() | |
| .enumerate() | |
| .flat_map(move |(line_idx, line)| { | |
| let mut out = Vec::new(); | |
| let mut search_start = 0; | |
| while let Some(pos) = line[search_start..].find(needle) { | |
| let column = search_start + pos; | |
| out.push(Finding { | |
| url: url.clone(), | |
| position: TextPosition { | |
| line: line_idx + 1, | |
| column: column + 1, | |
| }, | |
| }); | |
| search_start = column + needle.len(); | |
| if search_start > line.len() { | |
| break; | |
| } | |
| } | |
| out | |
| }) | |
| }) | |
| .collect() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment