pub struct RuleSetBuilder<'outer> { /* private fields */ }Expand description
Builder for a RuleSet.
There are in general two ways to add rules to a rule set:
- Use the QueryBuilder and RuleBuilder APIs to construct a rule from scratch.
- Use a previously cached plan and add extra constraints to it.
The pattern this is used by egglog is as follows: An egglog rule is first compiled to a cached plan using builder patterns at declaration time, and each time the rule is run, it is added to a ruleset using the cached plan and possibly some extra constraints (e.g., timestamp).
See Database::new_rule_set for more information.
Implementations§
Source§impl<'outer> RuleSetBuilder<'outer>
impl<'outer> RuleSetBuilder<'outer>
pub fn new(db: &'outer mut Database) -> Self
Sourcepub fn estimate_size(&self, table: TableId, c: Option<Constraint>) -> usize
pub fn estimate_size(&self, table: TableId, c: Option<Constraint>) -> usize
Estimate the size of the subset of the table matching the given constraint.
This is a wrapper around the Database::estimate_size method.
Sourcepub fn new_rule<'a>(&'a mut self) -> QueryBuilder<'outer, 'a>
pub fn new_rule<'a>(&'a mut self) -> QueryBuilder<'outer, 'a>
Add a rule to this rule set.
Sourcepub fn add_rule_from_cached_plan(
&mut self,
cached: &CachedPlan,
extra_constraints: &[(AtomId, Constraint)],
) -> Option<RuleId>
pub fn add_rule_from_cached_plan( &mut self, cached: &CachedPlan, extra_constraints: &[(AtomId, Constraint)], ) -> Option<RuleId>
Add a rule to this rule set based on a previously cached plan, optionally with additional constraints applied on top.
Returns None if the query is provably empty given the current database
state (i.e. some constraint narrows a table to zero matching rows), in
which case no rule or action is allocated. Returns Some(RuleId) otherwise.
The primary use-case is seminaive evaluation: an egglog rule is compiled
once into a CachedPlan and then added to a fresh RuleSet each
iteration with timestamp constraints (e.g. GeConst on the focus atom)
that select only new tuples. If no new tuples exist for an atom, the
None return allows the caller to skip that variant entirely.
Auto Trait Implementations§
impl<'outer> Freeze for RuleSetBuilder<'outer>
impl<'outer> !RefUnwindSafe for RuleSetBuilder<'outer>
impl<'outer> Send for RuleSetBuilder<'outer>
impl<'outer> Sync for RuleSetBuilder<'outer>
impl<'outer> Unpin for RuleSetBuilder<'outer>
impl<'outer> !UnwindSafe for RuleSetBuilder<'outer>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more