Skip to main content

MultiSieve

Struct MultiSieve 

Source
pub struct MultiSieve<'a> { /* private fields */ }
Expand description

A multi-pass sieve that supports any number of patterns.

Internally, patterns are partitioned into groups of at most 16 entries so each group can reuse the existing SimdSieve implementation. Candidate offsets from every group are then merged with a k-way merge, preserving ascending order and removing duplicates.

§Errors

Returns the same construction errors as SimdSieve::new. In practice, only an empty pattern set can fail because MultiSieve never forwards more than 16 patterns to a single underlying sieve.

§Example

use simdsieve::MultiSieve;

let haystack = b"alpha beta gamma delta";
let patterns: &[&[u8]] = &[b"alpha", b"beta", b"gamma", b"delta"];

let matches: Vec<usize> = MultiSieve::new(haystack, patterns)
    .unwrap()
    .candidates()
    .collect();

assert_eq!(matches, vec![0, 6, 11, 17]);

Implementations§

Source§

impl<'a> MultiSieve<'a>

Source

pub fn new(haystack: &'a [u8], patterns: &[&'a [u8]]) -> Result<Self>

Creates a new exact-match multi-pass sieve.

Patterns are grouped into chunks of 16 so each chunk can be searched by a regular SimdSieve (AVX2 supports up to 16 patterns per filter).

§Errors

Returns an error if the pattern set is empty.

Source

pub fn new_case_insensitive( haystack: &'a [u8], patterns: &[&'a [u8]], ) -> Result<Self>

Creates a case-insensitive multi-pass sieve (ASCII az only).

Patterns are grouped into chunks of 16 so each chunk can be searched by a regular SimdSieve.

§Errors

Returns an error if the pattern set is empty.

Source

pub fn candidates(self) -> impl Iterator<Item = usize> + 'a

Iterates candidate positions from all pattern groups in sorted order.

If multiple groups report the same position, that offset is yielded only once.

Auto Trait Implementations§

§

impl<'a> Freeze for MultiSieve<'a>

§

impl<'a> RefUnwindSafe for MultiSieve<'a>

§

impl<'a> Send for MultiSieve<'a>

§

impl<'a> Sync for MultiSieve<'a>

§

impl<'a> Unpin for MultiSieve<'a>

§

impl<'a> UnsafeUnpin for MultiSieve<'a>

§

impl<'a> UnwindSafe for MultiSieve<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.