Skip to main content

Filter

Struct Filter 

Source
pub struct Filter { /* private fields */ }
Expand description

Filter.

Filters efficiently match ordered identifier sequences against a set of compiled sequence conditions. Each Filter manages an inner expression filter that identifies matching constrained expressions first, and a positional constraint set that validates whether those candidate matches satisfy a compiled sequence condition. Thus, the inner expression filter can be thought of as the first stage, eliminating non-matching constrained expressions, while the positional constraint set is the second stage, which checks whether the remaining candidate matches are actually satisfiable.

Each Filter manages three cooperating compiled structures:

  • Filter::filter: Contains an inner expression filter that matches the constrained sequence slots against individual identifiers.

  • Filter::bindings: Contains one item per constrained slot in the inner expression filter, which maps candidate indices back to conditions.

  • Filter::layout: Contains a condition layout that records where each condition’s slots live used to validate ordering and gap constraints.

§Examples

use zrx_id::sequence::Filter;
use zrx_id::{selector, Id, Sequence};

// Create filter builder and insert sequence
let mut builder = Filter::builder();
builder.insert(Sequence::suffix(
    selector!(location = "**/*.md")?,
));

// Create filter from builder
let filter = builder.build()?;

// Create identifiers and obtain candidate sequences
let id: Id = "zri:file:::docs:index.md:".parse()?;
for index in filter.candidates([&id])? {
    println!("{index:?}");
}

Implementations§

Source§

impl Filter

Source

pub fn builder() -> Builder

Creates a filter builder.

§Examples
use zrx_id::sequence::Filter;

// Create filter builder
let mut builder = Filter::builder();
Source

pub fn into_builder(self) -> Builder

Creates a filter builder from the filter.

This method allows to modify an existing Filter by converting it back into a filter builder to insert or remove expressions.

§Examples
use zrx_id::sequence::Filter;

// Create filter
let filter = Filter::default();

// Create filter builder
let mut builder = filter.into_builder();
Source§

impl Filter

Source

pub fn candidates<T>(&self, ids: T) -> Result<Candidates<'_>, Error>

Returns the indices of sequences that match the identifiers.

This method compares sequences part of the filter against the given set of ordered identifiers and returns an iterator over the indices of the sequences that match. The order of the returned indices corresponds to the order in which the sequences were added to the filter.

§Errors

Returns Error::Id if any of the identifiers is invalid.

§Examples
use zrx_id::sequence::Filter;
use zrx_id::{selector, Id, Sequence};

// Create filter builder and insert sequence
let mut builder = Filter::builder();
builder.insert(Sequence::suffix(
    selector!(location = "**/*.md")?,
));

// Create filter from builder
let filter = builder.build()?;

// Create identifier and obtain candidate sequences
let id: Id = "zri:file:::docs:index.md:".parse()?;
for index in filter.candidates([&id])? {
    println!("{index:?}");
}
Source§

impl Filter

Source

pub fn len(&self) -> usize

Returns the number of sequences.

Source

pub fn is_empty(&self) -> bool

Returns whether there are any sequences.

Trait Implementations§

Source§

impl Debug for Filter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for Filter

Source§

fn default() -> Filter

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> Arguments for T
where T: Send + Sync + 'static,

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.