pub struct ExprPool { /* private fields */ }Expand description
Owns all expression nodes. Every ExprId is valid only within its pool.
ExprPool is Send + Sync.
Read operations (with, get, len) are fully lock-free — they index
into a boxcar::Vec via a single atomic load with no lock acquisition.
Write operations (intern) use a per-shard lock (parallel mode) or a
Mutex (non-parallel mode) only during new-node insertion.
Implementations§
Source§impl ExprPool
impl ExprPool
pub fn new() -> Self
Sourcepub fn intern(&self, data: ExprData) -> ExprId
pub fn intern(&self, data: ExprData) -> ExprId
Intern data, returning a shared ExprId. Identical structures
always return the same id; structural equality ⟺ id equality.
Sourcepub fn with<R, F: FnOnce(&ExprData) -> R>(&self, id: ExprId, f: F) -> R
pub fn with<R, F: FnOnce(&ExprData) -> R>(&self, id: ExprId, f: F) -> R
Borrow a node by id and apply f without cloning. Lock-free.
pub fn is_empty(&self) -> bool
Sourcepub fn symbol(&self, name: impl Into<String>, domain: Domain) -> ExprId
pub fn symbol(&self, name: impl Into<String>, domain: Domain) -> ExprId
Free symbol; multiplication treats it as commuting with every other factor (default).
Sourcepub fn symbol_commutative(
&self,
name: impl Into<String>,
domain: Domain,
commutative: bool,
) -> ExprId
pub fn symbol_commutative( &self, name: impl Into<String>, domain: Domain, commutative: bool, ) -> ExprId
Free symbol with explicit commutative flag (V3-2). commutative: false is for
matrix or operator generators where A*B and B*A must remain distinct.
pub fn integer(&self, n: impl Into<Integer>) -> ExprId
pub fn rational( &self, numer: impl Into<Integer>, denom: impl Into<Integer>, ) -> ExprId
pub fn float(&self, value: f64, prec: u32) -> ExprId
pub fn add(&self, args: Vec<ExprId>) -> ExprId
pub fn mul(&self, args: Vec<ExprId>) -> ExprId
pub fn pow(&self, base: ExprId, exp: ExprId) -> ExprId
pub fn func(&self, name: impl Into<String>, args: Vec<ExprId>) -> ExprId
Sourcepub fn piecewise(
&self,
branches: Vec<(ExprId, ExprId)>,
default: ExprId,
) -> ExprId
pub fn piecewise( &self, branches: Vec<(ExprId, ExprId)>, default: ExprId, ) -> ExprId
Build a Piecewise expression.
Branches are (cond, value) pairs where cond must be a
Predicate node. The default value is used when no condition
matches.
Sourcepub fn predicate(&self, kind: PredicateKind, args: Vec<ExprId>) -> ExprId
pub fn predicate(&self, kind: PredicateKind, args: Vec<ExprId>) -> ExprId
Build a Predicate node (symbolic boolean condition).
pub fn pred_lt(&self, a: ExprId, b: ExprId) -> ExprId
pub fn pred_le(&self, a: ExprId, b: ExprId) -> ExprId
pub fn pred_gt(&self, a: ExprId, b: ExprId) -> ExprId
pub fn pred_ge(&self, a: ExprId, b: ExprId) -> ExprId
pub fn pred_eq(&self, a: ExprId, b: ExprId) -> ExprId
pub fn pred_ne(&self, a: ExprId, b: ExprId) -> ExprId
pub fn pred_and(&self, args: Vec<ExprId>) -> ExprId
pub fn pred_or(&self, args: Vec<ExprId>) -> ExprId
pub fn pred_not(&self, a: ExprId) -> ExprId
pub fn pred_true(&self) -> ExprId
pub fn pred_false(&self) -> ExprId
Sourcepub fn big_o(&self, arg: ExprId) -> ExprId
pub fn big_o(&self, arg: ExprId) -> ExprId
O(arg) — symbolic big-O bound used in truncated series (V2-15).
Sourcepub fn pos_infinity(&self) -> ExprId
pub fn pos_infinity(&self) -> ExprId
Canonical +∞ symbol for limits at infinity (V2-16).
pub fn display(&self, id: ExprId) -> ExprDisplay<'_>
Source§impl ExprPool
impl ExprPool
Sourcepub fn checkpoint(&self, path: impl AsRef<Path>) -> Result<(), IoError>
pub fn checkpoint(&self, path: impl AsRef<Path>) -> Result<(), IoError>
V1-14 — write the current pool to path atomically. Equivalent to
save_to.
Sourcepub fn open_persistent(path: impl AsRef<Path>) -> Result<Self, IoError>
pub fn open_persistent(path: impl AsRef<Path>) -> Result<Self, IoError>
V1-14 — load a persisted pool, or return a fresh one if the file does
not exist. Equivalent to open_persistent.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for ExprPool
impl !RefUnwindSafe for ExprPool
impl Unpin for ExprPool
impl UnsafeUnpin for ExprPool
impl UnwindSafe for ExprPool
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> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
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