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
Iis the type used for identifying the nodes, because of its purpose only values that implementCopyare allowed like&'static stror {u8,i8, …}. If the identifier is a number it is better to just usepetgraph::Graphsince 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 aHashMap.Nis the type used to store values within the graph’s nodesEis the type used to store values within the graph’s edgesTyis the Graph connection type.petgraph::Directedby defaultIxis 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>
impl<I, N, E, Ty, Ix> Graph<I, N, E, Ty, Ix>
Sourcepub fn with_capacity(nodes: usize, edges: usize) -> Self
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
pub fn node_count(&self) -> usize
pub fn edge_count(&self) -> usize
pub fn visit_map(&self) -> FixedBitSet
Source§impl<I, N, E, Ty: EdgeType, Ix: IndexType> Graph<I, N, E, Ty, Ix>
impl<I, N, E, Ty: EdgeType, Ix: IndexType> Graph<I, N, E, Ty, Ix>
Sourcepub fn index_name<'a>(&'a self, value: NodeIndex<Ix>) -> Option<I>
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”
Sourcepub fn name_index(&self, ident: I) -> Option<NodeIndex<Ix>>
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)
Sourcepub fn next(&mut self, from: I, to: I, edge: E) -> Result<(), ()>where
I: Debug,
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
Sourcepub fn register(&mut self, ident: I, node: N) -> Result<(), ()>where
I: Debug,
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