Skip to main content

find_byte_in_bitmap

Function find_byte_in_bitmap 

Source
pub fn find_byte_in_bitmap(
    haystack: &[u8],
    bitmap: &ByteBitmap,
) -> Option<usize>
Expand description

Find the byte offset of the first occurrence of any byte whose value is set in bitmap. The bitmap encodes a 256-bit set — bit b is set ⇔ byte value b is a needle.

This is the dispatch shape every other primitive in this module reduces to. Exposed publicly for callers (parser hot paths, formatter pre-pass) that want to amortise the bitmap construction across many calls with the same needle set.

§Examples

use noyalib::simd::{bitmap_for, find_byte_in_bitmap};

// Build the bitmap once — `:` (0x3A) and `\n` (0x0A).
let bm = bitmap_for(&[b':', b'\n']);
assert_eq!(find_byte_in_bitmap(b"foo:bar", &bm), Some(3));
assert_eq!(find_byte_in_bitmap(b"all good", &bm), None);