Graph

Struct Graph 

Source
pub struct Graph<I, N, E, Ty = Directed, Ix = DefaultIx> {
    pub nodes: HashMap<Ascii<I>, NodeIndex<Ix>>,
    /* private fields */
}
Expand description

The library’s principal Graph structure.

The struct is an abstract layer built on top of the petgraph::Graph<N, E, Ty, Ix> implementation to support named nodes using I identifiers

  • I is the type used for identifying the nodes, because of its purpose only values that implement Copy are allowed like &'static str or {u8, i8, …}. If the identifier is a number it is better to just use petgraph::Graph since its default behaviour is to work identifying nodes with numbers, these numbers are named indexes and don’t add any overhead like this more high-level API which uses a HashMap.
  • N is the type used to store values within the graph’s nodes
  • E is the type used to store values within the graph’s edges
  • Ty is the Graph connection type. petgraph::Directed by default
  • Ix is the number type value used as indexer for Edges and Nodes.

Fields§

§nodes: HashMap<Ascii<I>, NodeIndex<Ix>>

The map of the I node-name to the NodeIndex<Ix>

Implementations§

Source§

impl<I, N, E, Ty, Ix> Graph<I, N, E, Ty, Ix>
where Ty: EdgeType, Ix: IndexType,

Source

pub fn new() -> Self

The Graph constructor

Source

pub fn with_capacity(nodes: usize, edges: usize) -> Self

Construct a new Graph with a fixed initial size. Since we use a macro to construct the graph we do call this constructor to save a couple calls to the allocator

Source

pub fn node_count(&self) -> usize

Source

pub fn edge_count(&self) -> usize

Source

pub fn visit_map(&self) -> FixedBitSet

Source§

impl<I, N, E, Ty: EdgeType, Ix: IndexType> Graph<I, N, E, Ty, Ix>
where I: Copy + Hash + Eq, Ascii<I>: Copy + Hash + Eq, NodeIndex: From<NodeIndex<Ix>>, EdgeIndex: From<EdgeIndex<Ix>>,

Source

pub fn index_name<'a>(&'a self, value: NodeIndex<Ix>) -> Option<I>

Get the high-level node name from the low-level node index. E.g. NodeIndex(0) -> “Arad”

Source

pub fn name_index(&self, ident: I) -> Option<NodeIndex<Ix>>

Get the low-level node index from the high-level node name. E.g. “Arad” -> NodeIndex(0)

Source

pub fn next(&mut self, from: I, to: I, edge: E) -> Result<(), ()>
where I: Debug,

Connect to nodes by their high-level names. E.g. “Arad” -> “Neamt”

The method calls the necessary low-level methods to connect both node indexes within the inner graph.

Adds values to the inner graph’s Vec<Edge<E, Ix>> to represent neighbors between nodes and the binded E value

Source

pub fn register(&mut self, ident: I, node: N) -> Result<(), ()>
where I: Debug,

Register a node with a given name and stored N value

The method calls the necessary low-level methods to connect both node indexes within the inner graph.

Adds values to the inner graph’s Vec<Node<N, Ix>> to represent neighbors between nodes and the binded N value

Source

pub fn iterative_depth_first<D>( &self, start: I, goal: Option<I>, limit: Option<D>, ) -> Result<Step<D, Ix>, ()>
where D: Measure + Copy + One + Zero,

Source

pub fn depth_first<D>( &self, start: I, goal: Option<I>, limit: Option<D>, ) -> Result<Step<D, Ix>, ()>
where D: Measure + Copy + One + Zero,

Source

pub fn depth_first_impl<D>( &self, start: NodeIndex<Ix>, goal: Option<NodeIndex<Ix>>, limit: Option<D>, ) -> Result<Step<D, Ix>, WalkerState<D, Ix>>
where D: Measure + Copy + One + Zero + Debug,

Source

pub fn breadth_first( &self, start: I, goal: Option<I>, ) -> Result<Steps<(), Ix>, ()>

Source

pub fn dijkstra<K, F>( &self, start: I, goal: Option<I>, edge_cost: F, ) -> Result<Steps<K, Ix>, ()>
where K: Measure + Copy + Eq + Default + Ord + PartialOrd, F: FnMut(&E) -> K,

Source

pub fn dijkstra_impl<'a, K, F>( &self, start: NodeIndex<Ix>, goal: Option<NodeIndex<Ix>>, edge_cost: F, ) -> Result<Steps<K, Ix>, ()>
where K: Measure + Copy + Eq + Default + Ord + PartialOrd, F: FnMut(&E) -> K,

Source

pub fn breadth_first_impl( &self, start: NodeIndex<Ix>, goal: Option<NodeIndex<Ix>>, ) -> Result<Steps<(), Ix>, ()>

Source

pub fn bidirectional<S: Debug, D: Debug>( &self, algo1: impl Walker<S, Ix>, algo2: impl Walker<D, Ix>, ) -> Result<Step<(), Ix>, ()>

Auto Trait Implementations§

§

impl<I, N, E, Ty, Ix> Freeze for Graph<I, N, E, Ty, Ix>

§

impl<I, N, E, Ty, Ix> RefUnwindSafe for Graph<I, N, E, Ty, Ix>

§

impl<I, N, E, Ty, Ix> Send for Graph<I, N, E, Ty, Ix>
where Ty: Send, N: Send, E: Send, I: Send, Ix: Send,

§

impl<I, N, E, Ty, Ix> Sync for Graph<I, N, E, Ty, Ix>
where Ty: Sync, N: Sync, E: Sync, I: Sync, Ix: Sync,

§

impl<I, N, E, Ty, Ix> Unpin for Graph<I, N, E, Ty, Ix>
where Ty: Unpin, N: Unpin, E: Unpin, I: Unpin, Ix: Unpin,

§

impl<I, N, E, Ty, Ix> UnwindSafe for Graph<I, N, E, Ty, Ix>

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.