Struct Graph

Source
pub struct Graph<Node, EdgeData> {
    pub nodes: HashMap<NodeIndex, Node>,
    pub edges: HashMap<EdgeIndex, Edge<EdgeData>>,
}
Expand description

A graph generic over node and edge data.

Nodes and edges are public because this graph makes no guarantees as to its structure beyond being a graph.

The graph does provide convenience functions for some simple operations over its data.

Fields§

§nodes: HashMap<NodeIndex, Node>§edges: HashMap<EdgeIndex, Edge<EdgeData>>

Implementations§

Source§

impl<Node, EdgeData> Graph<Node, EdgeData>

Source

pub fn new() -> Self

Create a new graph with empty nodes and edges.

To initialize with capacity or other pre-defined settings, create it using public fields.

Source

pub fn nodes<'a>(&'a self) -> impl Iterator + 'a

An iterator over this graph’s nodes, in no particular order.

Source

pub fn edges<'a>(&'a self) -> impl Iterator + 'a

An iterator over this graph’s edges, in no particular order.

Source

pub fn edge(&mut self, edge: Edge<EdgeData>) -> EdgeIndex

A convenience function to insert an edge at a new index.

Source

pub fn r_edge(&mut self, idx: EdgeIndex) -> Option<Edge<EdgeData>>

Attempt to remove an edge from this graph, returning it if it existed.

Source

pub fn node(&mut self, node: Node) -> NodeIndex

A convenience function to insert a node at a new index.

Source

pub fn r_node(&mut self, idx: NodeIndex) -> Option<Node>

Attempt to remove a node from this graph, returning it if it existed.

Note that this will not check if any edges still have the node referenced.

Trait Implementations§

Source§

impl<Node: Debug, EdgeData: Debug> Debug for Graph<Node, EdgeData>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<Node, EdgeData> Freeze for Graph<Node, EdgeData>

§

impl<Node, EdgeData> RefUnwindSafe for Graph<Node, EdgeData>
where Node: RefUnwindSafe, EdgeData: RefUnwindSafe,

§

impl<Node, EdgeData> Send for Graph<Node, EdgeData>
where Node: Send, EdgeData: Send,

§

impl<Node, EdgeData> Sync for Graph<Node, EdgeData>
where Node: Sync, EdgeData: Sync,

§

impl<Node, EdgeData> Unpin for Graph<Node, EdgeData>
where Node: Unpin, EdgeData: Unpin,

§

impl<Node, EdgeData> UnwindSafe for Graph<Node, EdgeData>
where Node: UnwindSafe, EdgeData: UnwindSafe,

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.