pub struct CSE<N, C: CSEController<Node = N>> {
random_state: RandomState,
phantom_data: PhantomData<N>,
controller: C,
}Expand description
The main entry point of Common Subexpression Elimination.
CSE requires a CSEController, that defines how common subtrees of a particular
TreeNode tree can be eliminated. The elimination process can be started with the
CSE::extract_common_nodes() method.
Fields§
§random_state: RandomState§phantom_data: PhantomData<N>§controller: CImplementations§
Source§impl<N, C> CSE<N, C>
impl<N, C> CSE<N, C>
pub fn new(controller: C) -> Self
Sourcefn node_to_id_array<'n>(
&mut self,
node: &'n N,
node_stats: &mut HashMap<Identifier<'n, N>, NodeEvaluation>,
id_array: &mut Vec<(usize, Option<Identifier<'n, N>>)>,
) -> Result<bool>
fn node_to_id_array<'n>( &mut self, node: &'n N, node_stats: &mut HashMap<Identifier<'n, N>, NodeEvaluation>, id_array: &mut Vec<(usize, Option<Identifier<'n, N>>)>, ) -> Result<bool>
Add an identifier to id_array for every TreeNode in this tree.
Sourcefn to_arrays<'n>(
&mut self,
nodes: &'n [N],
node_stats: &mut HashMap<Identifier<'n, N>, NodeEvaluation>,
) -> Result<(bool, Vec<Vec<(usize, Option<Identifier<'n, N>>)>>)>
fn to_arrays<'n>( &mut self, nodes: &'n [N], node_stats: &mut HashMap<Identifier<'n, N>, NodeEvaluation>, ) -> Result<(bool, Vec<Vec<(usize, Option<Identifier<'n, N>>)>>)>
Returns the identifier list for each element in nodes and a flag to indicate if
rewrite phase of CSE make sense.
Returns and array with 1 element for each input node in nodes
Each element is itself the result of CSE::node_to_id_array for that node
(e.g. the identifiers for each node in the tree)
Sourcefn replace_common_node<'n>(
&mut self,
node: N,
id_array: &Vec<(usize, Option<Identifier<'n, N>>)>,
node_stats: &HashMap<Identifier<'n, N>, NodeEvaluation>,
common_nodes: &mut IndexMap<Identifier<'n, N>, (N, String)>,
) -> Result<N>
fn replace_common_node<'n>( &mut self, node: N, id_array: &Vec<(usize, Option<Identifier<'n, N>>)>, node_stats: &HashMap<Identifier<'n, N>, NodeEvaluation>, common_nodes: &mut IndexMap<Identifier<'n, N>, (N, String)>, ) -> Result<N>
Sourcefn rewrite_nodes_list<'n>(
&mut self,
nodes_list: Vec<Vec<N>>,
arrays_list: &[Vec<Vec<(usize, Option<Identifier<'n, N>>)>>],
node_stats: &HashMap<Identifier<'n, N>, NodeEvaluation>,
common_nodes: &mut IndexMap<Identifier<'n, N>, (N, String)>,
) -> Result<Vec<Vec<N>>>
fn rewrite_nodes_list<'n>( &mut self, nodes_list: Vec<Vec<N>>, arrays_list: &[Vec<Vec<(usize, Option<Identifier<'n, N>>)>>], node_stats: &HashMap<Identifier<'n, N>, NodeEvaluation>, common_nodes: &mut IndexMap<Identifier<'n, N>, (N, String)>, ) -> Result<Vec<Vec<N>>>
Sourcepub fn extract_common_nodes(
&mut self,
nodes_list: Vec<Vec<N>>,
) -> Result<FoundCommonNodes<N>>
pub fn extract_common_nodes( &mut self, nodes_list: Vec<Vec<N>>, ) -> Result<FoundCommonNodes<N>>
Extracts common TreeNodes and rewrites nodes_list.
Returns FoundCommonNodes recording the result of the extraction.
Auto Trait Implementations§
impl<N, C> Freeze for CSE<N, C>where
C: Freeze,
impl<N, C> RefUnwindSafe for CSE<N, C>where
C: RefUnwindSafe,
N: RefUnwindSafe,
impl<N, C> Send for CSE<N, C>
impl<N, C> Sync for CSE<N, C>
impl<N, C> Unpin for CSE<N, C>
impl<N, C> UnwindSafe for CSE<N, C>where
C: UnwindSafe,
N: UnwindSafe,
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
Mutably borrows from an owned value. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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 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>
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