Skip to main content

Graph

Struct Graph 

Source
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: Node

Implementations§

Source§

impl Graph

Source

pub fn new() -> Self

Source

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

Source

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.

Source

pub fn node_size(&self) -> usize

Returns the number of nodes

Source

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.

Source

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.

Source

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.

Source

pub fn add_term(&mut self, term: Vec<Token>) -> Result<usize, ParseError>

Adds a term to the graph consuming it in the process.

Source

pub fn print_nodes(&self)

Source

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

Source

pub fn lpidx(term: &Vec<Token>) -> Option<usize>

Returns the first left parenthesis index that is not preceeded by a right parenthesis going from right to left of the passed token sequence or None if no left parenthesis can be found.

Trait Implementations§

Source§

impl Debug for Graph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Graph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Graph

§

impl RefUnwindSafe for Graph

§

impl Send for Graph

§

impl Sync for Graph

§

impl Unpin for Graph

§

impl UnsafeUnpin for Graph

§

impl UnwindSafe for Graph

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.