RuleSetBuilder

Struct RuleSetBuilder 

Source
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:

  1. Use the QueryBuilder and RuleBuilder APIs to construct a rule from scratch.
  2. 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>

Source

pub fn new(db: &'outer mut Database) -> Self

Source

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.

Source

pub fn new_rule<'a>(&'a mut self) -> QueryBuilder<'outer, 'a>

Add a rule to this rule set.

Source

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.

Source

pub fn build(self) -> RuleSet

Build the ruleset.

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

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.