pub struct Graph {
pub subexpressions: HashMap<usize, Pair<Edge>>,
pub sr: HashMap<usize, Vec<ReactionPair<Edge>>>,
pub kr: HashMap<usize, Vec<Edge>>,
pub ir: HashMap<usize, Vec<Edge>>,
pub nodes: HashMap<usize, Node>,
pub ti: Node,
pub tk: Node,
pub ts: Node,
}Expand description
Graph that shows how expressions break down into shared subexpressions and its possible reductions.
Fields§
§subexpressions: HashMap<usize, Pair<Edge>>§sr: HashMap<usize, Vec<ReactionPair<Edge>>>§kr: HashMap<usize, Vec<Edge>>§ir: HashMap<usize, Vec<Edge>>§nodes: HashMap<usize, Node>§ti: Node§tk: Node§ts: NodeImplementations§
Source§impl Graph
impl Graph
pub fn new() -> Self
Sourcepub fn get_term_id(&self, term: &Vec<Token>) -> Option<usize>
pub fn get_term_id(&self, term: &Vec<Token>) -> Option<usize>
Returns the id of the node containing the term or None if no term can be found
Sourcepub fn contains(&self, term: &Vec<Token>) -> Option<usize>
pub fn contains(&self, term: &Vec<Token>) -> Option<usize>
Returns the id of the node containing the term or None if no term can be found. Includes the elementary terms S,K and I.
Sourcepub fn add_node(&mut self, term: Vec<Token>, is_root: bool) -> usize
pub fn add_node(&mut self, term: Vec<Token>, is_root: bool) -> usize
Adds an new node with the given term and returns its assigned IDs.
Sourcepub fn add_reduction_edge(
&mut self,
reduction: &Reduction,
origin_id: &usize,
destination_id: &usize,
level: usize,
)
pub fn add_reduction_edge( &mut self, reduction: &Reduction, origin_id: &usize, destination_id: &usize, level: usize, )
Adds an edge to the reductions according to the rule type of the reduction.
Sourcepub fn add_subexpr_edge(
&mut self,
origin_id: &usize,
destination_id: &usize,
sibling: Sibling,
weight: f32,
)
pub fn add_subexpr_edge( &mut self, origin_id: &usize, destination_id: &usize, sibling: Sibling, weight: f32, )
Adds an edge to a subexpression from the nodes with origin_id to destination_id and assigns the weight parameter to it.
Sourcepub fn add_term(&mut self, term: Vec<Token>) -> Result<usize, ParseError>
pub fn add_term(&mut self, term: Vec<Token>) -> Result<usize, ParseError>
Adds a term to the graph consuming it in the process.
pub fn print_nodes(&self)
Sourcepub fn integrate(
&mut self,
term: &mut Vec<Token>,
level: usize,
) -> Option<usize>
pub fn integrate( &mut self, term: &mut Vec<Token>, level: usize, ) -> Option<usize>
Intgrates a new node into the graph Returns the ID of the new node or a provisional id of 0 if the integration limit is reached.
§Example
use ruski::* use ruski::parser::Token;
let graph = Graph::new(); let term = vec![S,S,S,Lparen,S,S,Rparen,S,S]; assert_eq!(graph.integrate(term), Some(5), 0);
§Errors
Return None if the expression is invalid