pub struct EGraph {
pub nodes: IndexMap<NodeId, Node>,
pub root_eclasses: Vec<ClassId>,
pub class_data: IndexMap<ClassId, ClassData>,
/* private fields */
}
Fields§
§nodes: IndexMap<NodeId, Node>
§root_eclasses: Vec<ClassId>
§class_data: IndexMap<ClassId, ClassData>
Implementations§
Source§impl EGraph
impl EGraph
Sourcepub fn inline_leaves(&mut self) -> usize
pub fn inline_leaves(&mut self) -> usize
Inline all leaves (e-classes with a single node that has no children) into their parents, so that they are added to the function name like f(10, ·). Returns the number of leaves inlined.
Sourcepub fn saturate_inline_leaves(&mut self)
pub fn saturate_inline_leaves(&mut self)
Inline all leaves (e-classes with a single node that has no children) into their parents, recursively.
Sourcepub fn split_classes(&mut self, should_split: impl Fn(&NodeId, &Node) -> bool)
pub fn split_classes(&mut self, should_split: impl Fn(&NodeId, &Node) -> bool)
Given some function should_split
, after calling this method, all nodes where it is true will have at most
one other node in their e-class and if they have parents, will no other nodes in their e-class.
All nodes in an e-class shared with a split node will still be in a e-class with that node, but no longer in an e-class with each other.
This is used to help make the visualization easier to parse, by breaking cycles and allowing these split nodes
to be later inlined into their parents with inline_leaves
, which only applies when there is a single node in an
e-class.
For example, if we split on all “primitive” nodes or their wrappers, like Int(1), then those nodes can then be inlined into their parents and are all nodes equal to them are no longer in single e-class, making the graph layout easier to understand.
Note that should_split
should only ever be true for either a single node, or no nodes, in an e-class.
If it is true for multiple nodes in an e-class, then this method will panic.
Another way to think about it is that any isomporphic function can be split, since if f(a) = f(b) then a = b, in that case.
Source§impl EGraph
impl EGraph
Sourcepub fn add_node(&mut self, node_id: impl Into<NodeId>, node: Node)
pub fn add_node(&mut self, node_id: impl Into<NodeId>, node: Node)
Adds a new node to the egraph
Panics if a node with the same id already exists
pub fn nid_to_cid(&self, node_id: &NodeId) -> &ClassId
pub fn nid_to_class(&self, node_id: &NodeId) -> &Class
Sourcepub fn classes(&self) -> &IndexMap<ClassId, Class>
pub fn classes(&self) -> &IndexMap<ClassId, Class>
Groups the nodes in the e-graph by their e-class
This is only done once and then the result is cached. Modifications to the e-graph will not be reflected in later calls to this function.
pub fn from_json_file(path: impl AsRef<Path>) -> Result<Self>
pub fn to_json_file(&self, path: impl AsRef<Path>) -> Result<()>
pub fn test_round_trip(&self)
Trait Implementations§
Source§impl<'de> Deserialize<'de> for EGraph
impl<'de> Deserialize<'de> for EGraph
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for EGraph
impl StructuralPartialEq for EGraph
Auto Trait Implementations§
impl !Freeze for EGraph
impl RefUnwindSafe for EGraph
impl Send for EGraph
impl Sync for EGraph
impl Unpin for EGraph
impl UnwindSafe for EGraph
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.