Struct fast_graph::Graph

source ·
pub struct Graph<N, E> {
    pub nodes: SlotMap<NodeID, Node<N>>,
    pub edges: SlotMap<EdgeID, Edge<E>>,
}
Expand description

The default Graph struct which implements the GraphInterface trait.

§Examples

use fast_graph::{Graph, Node, Edge};
/* We need to have this trait in scope: */
use fast_graph::{GraphInterface};

#[derive(Clone, Debug)]
struct EdgeData(String);
#[derive(Clone, Debug)]
struct NodeData(String);

let mut graph: Graph<NodeData, EdgeData> = Graph::new();

let node1 = graph.add_node(NodeData("Node 1".into()));
let node2 = graph.add_node(NodeData("Node 2".into()));
let edge1 = graph.add_edge(node1, node2, EdgeData("Edge 1".into()));

assert_eq!(graph.node(node1).unwrap().id, node1);
assert_eq!(graph.edge(edge1).unwrap().id, edge1);

graph.remove_node(node1).unwrap();

assert!(graph.node(node1).is_err());
assert_eq!(graph.node(node2).unwrap().id, node2);

println!("{:#?}", graph);

Fields§

§nodes: SlotMap<NodeID, Node<N>>§edges: SlotMap<EdgeID, Edge<E>>

Implementations§

source§

impl<N, E> Graph<N, E>

source

pub fn new() -> Graph<N, E>

Trait Implementations§

source§

impl<N: Debug + Clone, E: Debug + Clone> Debug for Graph<N, E>

source§

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

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

impl<N, E> GraphInterface for Graph<N, E>

§

type NodeData = N

§

type EdgeData = E

source§

fn nodes(&self) -> impl Iterator<Item = NodeID>

source§

fn node_count(&self) -> usize

source§

fn node(&self, id: NodeID) -> Result<&Node<N>, GraphError>

source§

fn node_mut(&mut self, id: NodeID) -> Result<&mut Node<N>, GraphError>

source§

fn edge(&self, id: EdgeID) -> Result<&Edge<E>, GraphError>

source§

fn edge_mut(&mut self, id: EdgeID) -> Result<&mut Edge<E>, GraphError>

source§

fn remove_node(&mut self, id: NodeID) -> Result<(), GraphError>

source§

fn remove_edge(&mut self, id: EdgeID) -> Result<(), GraphError>

source§

fn add_node(&mut self, data: N) -> NodeID

source§

fn add_nodes(&mut self, data: &[N]) -> Vec<NodeID>
where N: Clone,

source§

fn add_edges(&mut self, data: &[(NodeID, NodeID)]) -> Vec<EdgeID>
where E: Default + Clone, N: Clone,

source§

fn add_edge(&mut self, from: NodeID, to: NodeID, data: E) -> EdgeID

source§

fn remove_nodes(&mut self, ids: &[NodeID]) -> Result<(), GraphError>

Auto Trait Implementations§

§

impl<N, E> Freeze for Graph<N, E>

§

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

§

impl<N, E> Send for Graph<N, E>
where N: Send, E: Send,

§

impl<N, E> Sync for Graph<N, E>
where N: Sync, E: Sync,

§

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

§

impl<N, E> UnwindSafe for Graph<N, E>
where N: UnwindSafe, E: 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<'a, G> IterDepthFirst<'a, G> for G
where G: GraphInterface,

source§

fn connected_components(&'a self) -> Vec<HashSet<NodeID>>

Returns a vector of sets of node IDs, where each set is a connected component.
Starts a DFS at every node (except if it’s already been visited) and marks all reachable nodes as being part of the same component.

source§

fn iter_depth_first(&'a self, start: NodeID) -> DepthFirstSearch<'a, G>

Returns a depth first search iterator starting from a given node
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.