pub struct ExprExt(/* private fields */);
compiler
only.Expand description
Configuration for extended vectorscan parameters.
These parameters cover various types of fuzzy search as well as input subsetting features. See Extended Parameters for a further reference.
This structure may be passed in when building a database with
ExpressionSet::with_exts()
, or used to interrogate a single expression
with Expression::ext_info()
.
Like many other flags arguments, this struct also supports ops::BitOr
and the |
operator for composition:
use vectorscan::{expression::*, flags::*, matchers::*, sources::*};
// Apply extended configuration to one version of the pattern, but not the other:
let a: Expression = "ab".parse()?;
let ext = ExprExt::from_min_offset(3) | ExprExt::from_max_offset(15);
let set = ExpressionSet::from_exprs([&a, &a])
.with_exts([Some(&ext), None])
.with_ids([ExprId(1), ExprId(2)])
.compile(Mode::BLOCK)?;
let mut scratch = set.allocate_scratch()?;
let msg: ByteSlice = "ab ab ab".into();
let mut matches: Vec<ExpressionIndex> = Vec::new();
scratch.scan_sync(&set, msg, |m| {
matches.push(m.id);
MatchResult::Continue
})?;
// The configured pattern misses out on the first and last match of "ab":
assert_eq!(&matches, &[
ExpressionIndex(2), ExpressionIndex(1), ExpressionIndex(2), ExpressionIndex(2),
]);
Implementations§
Source§impl ExprExt
impl ExprExt
Sourcepub fn from_min_offset(x: usize) -> Self
pub fn from_min_offset(x: usize) -> Self
The minimum end offset in the data stream at which this expression should match successfully.
Sourcepub fn from_max_offset(x: usize) -> Self
pub fn from_max_offset(x: usize) -> Self
The maximum end offset in the data stream at which this expression should match successfully.
Sourcepub fn from_min_length(x: usize) -> Self
pub fn from_min_length(x: usize) -> Self
The minimum match length (from start to end) required to successfully match this expression.
This is one alternative to the use of Flags::ALLOWEMPTY
.
This does not require Flags::SOM_LEFTMOST
:
use vectorscan::{expression::*, flags::*, matchers::*, sources::*};
let a: Expression = "a.*b".parse()?;
let ext = ExprExt::from_min_length(4);
let set = ExpressionSet::from_exprs([&a, &a])
// #1 has no min_length, #2 does:
.with_exts([None, Some(&ext)])
.with_ids([ExprId(1), ExprId(2)])
.compile(Mode::BLOCK)?;
let mut scratch = set.allocate_scratch()?;
let msg: ByteSlice = " ab ab ".into();
let mut matches: Vec<(u32, &str)> = Vec::new();
scratch.scan_sync(&set, msg, |m| {
matches.push((m.id.0, unsafe { m.source.as_str() }));
MatchResult::Continue
})?;
assert_eq!(&matches, &[
// Without min_length, both matches show up:
(1, " ab"),
(1, " ab ab"),
// SOM_LEFTMOST is disabled, so we don't know the match start,
// but the min_length property is correctly applied regardless:
(2, " ab ab"),
]);
Sourcepub fn from_edit_distance(x: usize) -> Self
pub fn from_edit_distance(x: usize) -> Self
Allow patterns to approximately match within this edit distance.
Sourcepub fn from_hamming_distance(x: usize) -> Self
pub fn from_hamming_distance(x: usize) -> Self
Allow patterns to approximately match within this Hamming distance.
Trait Implementations§
Source§impl BitOrAssign for ExprExt
impl BitOrAssign for ExprExt
Source§fn bitor_assign(&mut self, rhs: Self)
fn bitor_assign(&mut self, rhs: Self)
|=
operation. Read more