Skip to main content

ExprPool

Struct ExprPool 

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

Arena-like pool for Expr values backed by a hash-consing table.

ExprPool layers GC-root tracking on top of ExprHashcons. Any expression added via add_root (or subsequently marked with mark_root) is considered live.

Implementations§

Source§

impl ExprPool

Source

pub fn new() -> Self

Create a new, empty pool.

Source

pub fn add(&mut self, expr: Expr) -> ExprId

Intern an expression without marking it as a root.

Source

pub fn add_root(&mut self, expr: Expr) -> ExprId

Intern an expression and mark it as a GC root.

Source

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

Look up an expression by ID.

Source

pub fn mark_root(&mut self, id: ExprId)

Mark an existing interned expression as a GC root.

If id is already a root it will appear twice in roots; live_count uses a deduplicated count so this is harmless.

Source

pub fn live_count(&self) -> usize

Return the number of distinct live (root) expressions.

Duplicates in roots are ignored.

Source

pub fn total_count(&self) -> usize

Return the total number of distinct expressions in the pool.

Source

pub fn dedup_ratio(&self) -> f64

Compute the deduplication ratio: hits / total intern calls.

A value close to 1.0 means most add/add_root calls were satisfied from cache.

Source

pub fn get_id(&self, expr: &Expr) -> Option<ExprId>

Look up the for a structurally equal expression, if interned.

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 = 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.