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
impl Filter
Sourcepub fn builder() -> Builder
pub fn builder() -> Builder
Creates a filter builder.
§Examples
use zrx_id::sequence::Filter;
// Create filter builder
let mut builder = Filter::builder();Sourcepub fn into_builder(self) -> Builder
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
impl Filter
Sourcepub fn candidates<T>(&self, ids: T) -> Result<Candidates<'_>, Error>
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:?}");
}