Skip to main content

ExprPool

Struct ExprPool 

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

Process-wide shared hash-consing pool (spec §8.1/§12.4): maps content hash → ExprId. The central store is append-only (the symbolic layer is acyclic and resident), concurrency-safe.

Implementations§

Source§

impl ExprPool

Source

pub fn new() -> ExprPool

Source

pub fn global() -> &'static ExprPool

Process-wide shared instance (OnceLock): the interpreter and the symbolic engine share one pool.

Source

pub fn intern(&self, data: ExprData) -> ExprId

Intern flow (spec §8.1): content hash → local cache → global pool → append-allocate and write back to both caches. The same ExprData always yields the same ExprId.

Source

pub fn get(&self, id: ExprId) -> Option<ExprData>

Source

pub fn symbol(&self, id: SymbolId) -> ExprId

Source

pub fn integer(&self, n: i64) -> ExprId

Source

pub fn real(&self, x: f64) -> ExprId

Source

pub fn number(&self, n: &Number) -> ExprId

Source

pub fn const_number(&self, id: ExprId) -> Option<Number>

Source

pub fn is_const_zero(&self, id: ExprId) -> bool

Source

pub fn is_const_one(&self, id: ExprId) -> bool

Source

pub fn add(&self, items: &[ExprId]) -> ExprId

Raw Add node (no simplification), stored in canonical order (spec §8.4).

Source

pub fn mul(&self, items: &[ExprId]) -> ExprId

Raw Mul node (no simplification), stored in canonical order (spec §8.4).

Source

pub fn pow(&self, base: ExprId, exp: ExprId) -> ExprId

Source

pub fn apply(&self, f: ExprId, args: &[ExprId]) -> ExprId

Source

pub fn add_n(&self, items: &[ExprId]) -> ExprId

Level 0/1 addition simplification (spec §8.3): Add flattening, constant merging, x+0→x; the result is sorted in canonical order (numbers/constants → symbols → composite nodes, spec §8.4).

Source

pub fn mul_n(&self, items: &[ExprId]) -> ExprId

Level 0/1 multiplication simplification (spec §8.3): Mul flattening, constant merging, 0*x→0, 1*x→x.

Source

pub fn add2(&self, a: ExprId, b: ExprId) -> ExprId

Source

pub fn mul2(&self, a: ExprId, b: ExprId) -> ExprId

Source

pub fn pow2(&self, base: ExprId, exp: ExprId) -> ExprId

Level 0/1 power simplification (spec §8.3): x^0→1, x^1→x, 1^x→1, plus constant folding at the same level.

Source

pub fn sub2(&self, a: ExprId, b: ExprId) -> ExprId

Source

pub fn div2(&self, a: ExprId, b: ExprId) -> ExprId

Trait Implementations§

Source§

impl Default for ExprPool

Source§

fn default() -> Self

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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.