Struct Graph

Source
pub struct Graph<GL, N, E>
where GL: Default,
{ /* private fields */ }

Implementations§

Source§

impl<GL: Default, N: Default + Clone + Debug, E: Default + Clone + Debug> Graph<GL, N, E>

Source

pub fn new(opts: Option<GraphOption>) -> Self

Source

pub fn is_directed(&self) -> bool

Whether graph was created with ‘directed’ flag set to true or not.

Source

pub fn is_multigraph(&self) -> bool

Whether graph was created with ‘multigraph’ flag set to true or not.

Source

pub fn is_compound(&self) -> bool

Whether graph was created with ‘compound’ flag set to true or not.

Source

pub fn set_graph(&mut self, label: GL) -> &mut Self

Sets the label of the graph.

Source

pub fn graph(&self) -> &GL

Gets the graph label.

Source

pub fn graph_mut(&mut self) -> &mut GL

Gets the graph label.

Source

pub fn set_default_node_label( &mut self, new_default: DefaultNodeLabel<N>, ) -> &mut Self

Sets the default node label. If newDefault is a function, it will be invoked ach time when setting a label for a node. Otherwise, this label will be assigned as default label in case if no label was specified while setting a node. Complexity: O(1).

Source

pub fn default_node_label(&self, node_id: String) -> N

Source

pub fn node_count(&self) -> usize

Gets the number of nodes in the graph. Complexity: O(1).

Source

pub fn nodes(&self) -> Vec<String>

Gets all nodes of the graph. Note, the in case of compound graph subnodes are not included in list. Complexity: O(1).

Source

pub fn sources(&self) -> Vec<String>

Gets list of nodes without in-edges. Complexity: O(|V|).

Source

pub fn sinks(&self) -> Vec<String>

Gets list of nodes without out-edges. Complexity: O(|V|).

Source

pub fn set_nodes( &mut self, node_ids: Vec<String>, value: Option<N>, ) -> &mut Self

Invokes setNode method for each node in names list. Complexity: O(|names|).

Source

pub fn set_node(&mut self, v: String, value: Option<N>) -> &mut Self

Creates or updates the value for the node v in the graph. If label is supplied it is set as the value for the node. If label is not supplied and the node was created by this call then the default node label will be assigned. Complexity: O(1).

Source

pub fn node(&self, v: &String) -> Option<&N>

Gets the label of node with specified name. Complexity: O(|V|).

Source

pub fn node_mut(&mut self, v: &String) -> Option<&mut N>

Gets the label of node with specified name. Complexity: O(|V|).

Source

pub fn has_node(&self, v: &String) -> bool

Detects whether graph has a node with specified name or not.

Source

pub fn remove_node(&mut self, v: &String) -> &mut Self

Remove the node with the name from the graph or do nothing if the node is not in the graph. If the node was removed this function also removes any incident edges. Complexity: O(1).

Source

pub fn set_parent( &mut self, v: &String, parent: Option<String>, ) -> Result<&mut Self, Box<dyn Error>>

Sets node p as a parent for node v if it is defined, or removes the parent for v if p is undefined. Method throws an exception in case of invoking it in context of noncompound graph. Average-case complexity: O(1).

Source

pub fn _remove_from_parents_child_list(&mut self, v: &String)

Source

pub fn parent(&self, v: &String) -> Option<&String>

Gets parent node for node v. Complexity: O(1).

Source

pub fn children(&self, v: &String) -> Vec<String>

Gets list of direct children of node v. Complexity: O(1).

Source

pub fn predecessors(&self, v: &String) -> Option<Vec<String>>

Return all nodes that are predecessors of the specified node or undefined if node v is not in the graph. Behavior is undefined for undirected graphs - use neighbors instead. Complexity: O(|V|).

Source

pub fn successors(&self, v: &String) -> Option<Vec<String>>

Return all nodes that are successors of the specified node or undefined if node v is not in the graph. Behavior is undefined for undirected graphs - use neighbors instead. Complexity: O(|V|).

Source

pub fn neighbors(&self, v: &String) -> Option<Vec<String>>

Return all nodes that are predecessors or successors of the specified node or undefined if node v is not in the graph. Complexity: O(|V|).

Source

pub fn is_leaf(&self, v: &String) -> bool

Source

pub fn filter_nodes<F>(&self, filter: F) -> Self
where F: Fn(&String) -> bool,

Creates new graph with nodes filtered via filter. Edges incident to rejected node are also removed. In case of compound graph, if parent is rejected by filter, than all its children are rejected too. Average-case complexity: O(|E|+|V|).

Source

pub fn set_default_edge_label( &mut self, new_default: DefaultEdgeLabel<E>, ) -> &mut Self

Sets the default edge label or factory function. This label will be assigned as default label in case if no label was specified while setting an edge or this function will be invoked each time when setting an edge with no label specified and returned value * will be used as a label for edge. Complexity: O(1).

Source

pub fn default_edge_label(&self, edge_id: String) -> E

Source

pub fn edge_count(&self) -> usize

Gets the number of edges in the graph. Complexity: O(1).

Source

pub fn edges(&self) -> Vec<Edge>

Gets edges of the graph. In case of compound graph subgraphs are not considered. Complexity: O(|E|).

Source

pub fn set_path(&mut self, vs: &Vec<String>, value: Option<E>)

Establish an edges path over the nodes in nodes list. If some edge is already exists, it will update its label, otherwise it will create an edge between pair of nodes with label provided or default label if no label provided. Complexity: O(|nodes|).

Source

pub fn set_edge( &mut self, v: &String, w: &String, edge_label: Option<E>, name: Option<String>, ) -> Result<&mut Self, Box<dyn Error>>

Creates or updates the label for the edge (v, w) with the optionally supplied name. If label is supplied it is set as the value for the edge. If label is not supplied and the edge was created by this call then the default edge label will be assigned. The name parameter is only useful with multigraphs.

Source

pub fn set_edge_with_obj( &mut self, e: &Edge, edge_label: Option<E>, ) -> Result<&mut Self, Box<dyn Error>>

Source

pub fn edge(&self, v: &String, w: &String, name: Option<String>) -> Option<&E>

Gets the label for the specified edge. Complexity: O(1).

Source

pub fn edge_with_obj(&self, edge: &Edge) -> Option<&E>

Gets the label for the specified edge. Complexity: O(1).

Source

pub fn edge_mut( &mut self, v: &String, w: &String, name: Option<String>, ) -> Option<&mut E>

Gets the label for the specified edge. Complexity: O(1).

Source

pub fn edge_mut_with_obj(&mut self, edge: &Edge) -> Option<&mut E>

Gets the label for the specified edge. Complexity: O(1).

Source

pub fn has_edge(&self, v: &String, w: &String, name: Option<String>) -> bool

Detects whether the graph contains specified edge or not. No subgraphs are considered. Complexity: O(1).

Source

pub fn has_edge_with_obj(&self, edge: &Edge) -> bool

Source

pub fn remove_edge( &mut self, v: &String, w: &String, name: Option<String>, ) -> &mut Self

Removes the specified edge from the graph. No subgraphs are considered. Complexity: O(1).

Source

pub fn remove_edge_with_obj(&mut self, e: &Edge) -> &mut Self

Removes the specified edge from the graph. No subgraphs are considered. Complexity: O(1).

Source

pub fn in_edges(&self, v: &String, u: Option<String>) -> Option<Vec<Edge>>

Return all edges that point to the node v. Optionally filters those edges down to just those coming from node u. Behavior is undefined for undirected graphs - use nodeEdges instead. Complexity: O(|E|).

Source

pub fn out_edges(&self, v: &String, w: Option<String>) -> Option<Vec<Edge>>

Return all edges that are pointed at by node v. Optionally filters those edges down to just those point to w. Behavior is undefined for undirected graphs - use nodeEdges instead. Complexity: O(|E|).

Source

pub fn node_edges(&self, v: &String, w: Option<String>) -> Option<Vec<Edge>>

Returns all edges to or from node v regardless of direction. Optionally filters those edges down to just those between nodes v and w regardless of direction. Complexity: O(|E|).

Trait Implementations§

Source§

impl<GL: Default, N, E> Default for Graph<GL, N, E>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<GL, N, E> Freeze for Graph<GL, N, E>
where GL: Freeze, N: Freeze, E: Freeze,

§

impl<GL, N, E> !RefUnwindSafe for Graph<GL, N, E>

§

impl<GL, N, E> !Send for Graph<GL, N, E>

§

impl<GL, N, E> !Sync for Graph<GL, N, E>

§

impl<GL, N, E> Unpin for Graph<GL, N, E>
where GL: Unpin, N: Unpin, E: Unpin,

§

impl<GL, N, E> !UnwindSafe for Graph<GL, N, E>

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, 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.