[−][src]Struct gchemol_graph::NxGraph
networkx-like API wrapper around petgraph
Methods
impl<N, E> NxGraph<N, E> where
N: Default,
E: Default,
[src]
N: Default,
E: Default,
Build/Read/Edit Graph
Example
use gchemol_graph::NxGraph; let mut g = NxGraph::path_graph(2); let u = g.add_node(2); let v = g.add_node(3); g.add_edge(u, v, 5); assert!(g.has_node(u)); assert!(g.has_edge(u, v)); // loop over neighbors of node u for x in g.neighbors(u) { dbg!(x); }
pub fn new() -> Self
[src]
Build a default Graph
pub fn neighbors(&self, n: NodeIndex) -> impl Iterator<Item = NodeIndex> + '_
[src]
Returns an iterator over all neighbors of node n
.
Reference
- https://networkx.github.io/documentation/stable/reference/classes/generated/networkx.Graph.neighbors.html
pub fn node_indices(&self) -> impl Iterator<Item = NodeIndex> + '_
[src]
Return an iterator over the node indices of the graph
pub fn has_node(&self, n: NodeIndex) -> bool
[src]
Returns true if the graph contains the node n.
pub fn has_edge(&self, u: NodeIndex, v: NodeIndex) -> bool
[src]
Returns true if the edge (u, v) is in the graph.
pub fn number_of_nodes(&self) -> usize
[src]
Returns the number of nodes in the graph.
pub fn number_of_edges(&self) -> usize
[src]
Returns the number of edges in the graph.
pub fn add_node(&mut self, data: N) -> NodeIndex
[src]
Add a node with associated data into graph.
pub fn add_nodes_from<M: IntoIterator<Item = N>>(
&mut self,
nodes: M
) -> Vec<NodeIndex>
[src]
&mut self,
nodes: M
) -> Vec<NodeIndex>
Add multiple nodes.
pub fn add_edge(&mut self, u: NodeIndex, v: NodeIndex, data: E)
[src]
Add an edge with data
between u
and v
(no parallel edge).
pub fn add_edges_from<M: IntoIterator<Item = (NodeIndex, NodeIndex, E)>>(
&mut self,
edges: M
)
[src]
&mut self,
edges: M
)
Add multiple edges from edges
.
pub fn remove_edge(&mut self, node1: NodeIndex, node2: NodeIndex) -> Option<E>
[src]
Remove an edge between node1
and node2
. Return None if trying to
remove a non-existent edge.
pub fn remove_node(&mut self, n: NodeIndex) -> Option<N>
[src]
Removes the node n
and all adjacent edges. Return None if trying to
remove a non-existent node.
pub fn clear(&mut self)
[src]
Remove all nodes and edges
pub fn clear_edges(&mut self)
[src]
Remove all edges
impl NxGraph<usize, usize>
[src]
pub fn path_graph(n: usize) -> Self
[src]
Returns the Path graph P_n
of linearly connected nodes. Node data and
edge data are usize type, mainly for test purpose.
impl<N, E> NxGraph<N, E> where
N: Default,
E: Default,
[src]
N: Default,
E: Default,
Node view and Edge view for NxGraph
.
Example
use gchemol_graph::NxGraph; let mut g = NxGraph::path_graph(3); let u = g.add_node(5); let v = g.add_node(2); let w = g.add_node(1); g.add_edge(u, v, 7); g.add_edge(u, w, 6); // loop over nodes for (node_index, node_data) in g.nodes() { // do something } // get node data of node `u` let nodes = g.nodes(); let node_u = nodes[u]; assert_eq!(node_u, 5); // Collect nodes into HashMap let nodes: std::collections::HashMap<_, _> = g.nodes().collect(); assert_eq!(nodes.len(), 6); // loop over edges for (u, v, edge_data) in g.edges() { // dbg!(u, v, edge_data) } // get edge data let edges = g.edges(); let edge_uv = edges[(u, v)]; assert_eq!(edge_uv, 7);
ⓘImportant traits for Nodes<'a, N, E>pub fn nodes(&self) -> Nodes<N, E>
[src]
A Node view of the Graph.
Reference
- https://networkx.github.io/documentation/stable/reference/classes/generated/networkx.Graph.nodes.html
ⓘImportant traits for Edges<'a, N, E>pub fn edges(&self) -> Edges<N, E>
[src]
An Edge view of the Graph.
Reference
- https://networkx.github.io/documentation/stable/reference/classes/generated/networkx.Graph.edges.html
Trait Implementations
impl<N: Clone, E: Clone> Clone for NxGraph<N, E> where
N: Default,
E: Default,
[src]
N: Default,
E: Default,
impl<N: Debug, E: Debug> Debug for NxGraph<N, E> where
N: Default,
E: Default,
[src]
N: Default,
E: Default,
impl<N: Default, E: Default> Default for NxGraph<N, E> where
N: Default,
E: Default,
[src]
N: Default,
E: Default,
impl<'de, N, E> Deserialize<'de> for NxGraph<N, E> where
N: Default,
E: Default,
N: Deserialize<'de>,
E: Deserialize<'de>,
[src]
N: Default,
E: Default,
N: Deserialize<'de>,
E: Deserialize<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl<N, E> Index<(NodeIndex<u32>, NodeIndex<u32>)> for NxGraph<N, E> where
N: Default,
E: Default,
[src]
N: Default,
E: Default,
type Output = E
The returned type after indexing.
fn index(&self, e: (NodeIndex, NodeIndex)) -> &Self::Output
[src]
impl<N, E> Index<NodeIndex<u32>> for NxGraph<N, E> where
N: Default,
E: Default,
[src]
N: Default,
E: Default,
type Output = N
The returned type after indexing.
fn index(&self, n: NodeIndex) -> &Self::Output
[src]
impl<N, E> IndexMut<(NodeIndex<u32>, NodeIndex<u32>)> for NxGraph<N, E> where
N: Default,
E: Default,
[src]
N: Default,
E: Default,
impl<N, E> IndexMut<NodeIndex<u32>> for NxGraph<N, E> where
N: Default,
E: Default,
[src]
N: Default,
E: Default,
impl<N, E> Serialize for NxGraph<N, E> where
N: Default,
E: Default,
N: Serialize,
E: Serialize,
[src]
N: Default,
E: Default,
N: Serialize,
E: Serialize,
Auto Trait Implementations
impl<N, E> RefUnwindSafe for NxGraph<N, E> where
E: RefUnwindSafe,
N: RefUnwindSafe,
E: RefUnwindSafe,
N: RefUnwindSafe,
impl<N, E> Send for NxGraph<N, E> where
E: Send,
N: Send,
E: Send,
N: Send,
impl<N, E> Sync for NxGraph<N, E> where
E: Sync,
N: Sync,
E: Sync,
N: Sync,
impl<N, E> Unpin for NxGraph<N, E> where
E: Unpin,
N: Unpin,
E: Unpin,
N: Unpin,
impl<N, E> UnwindSafe for NxGraph<N, E> where
E: UnwindSafe,
N: UnwindSafe,
E: UnwindSafe,
N: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,