pub struct DirectedGraph { /* private fields */ }Expand description
有向图
使用邻接表表示,支持带权边。
Implementations§
Source§impl DirectedGraph
impl DirectedGraph
Sourcepub fn add_edge_unweighted(&mut self, from: NodeId, to: NodeId)
pub fn add_edge_unweighted(&mut self, from: NodeId, to: NodeId)
添加无权有向边(权重=1.0)
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
节点数
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
边数
Sourcepub fn dijkstra(
&self,
start: NodeId,
end: NodeId,
) -> Option<(Vec<NodeId>, Weight)>
pub fn dijkstra( &self, start: NodeId, end: NodeId, ) -> Option<(Vec<NodeId>, Weight)>
Dijkstra 最短路径算法
返回从 start 到 end 的最短路径和总距离。
如果不可达返回 None。
Sourcepub fn topological_sort(&self) -> Option<Vec<NodeId>>
pub fn topological_sort(&self) -> Option<Vec<NodeId>>
拓扑排序(Kahn 算法)
返回拓扑排序结果。如果图有环返回 None。
Sourcepub fn connected_components(&self) -> Vec<Vec<NodeId>>
pub fn connected_components(&self) -> Vec<Vec<NodeId>>
连通分量(弱连通)
返回每个连通分量的节点列表。
Sourcepub fn reverse(&self) -> DirectedGraph
pub fn reverse(&self) -> DirectedGraph
反转图(所有边方向取反)
Sourcepub fn out_degree(&self, node: NodeId) -> usize
pub fn out_degree(&self, node: NodeId) -> usize
节点的出度
Trait Implementations§
Source§impl Clone for DirectedGraph
impl Clone for DirectedGraph
Source§fn clone(&self) -> DirectedGraph
fn clone(&self) -> DirectedGraph
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for DirectedGraph
impl Debug for DirectedGraph
Source§impl Default for DirectedGraph
impl Default for DirectedGraph
Source§fn default() -> DirectedGraph
fn default() -> DirectedGraph
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for DirectedGraph
impl RefUnwindSafe for DirectedGraph
impl Send for DirectedGraph
impl Sync for DirectedGraph
impl Unpin for DirectedGraph
impl UnsafeUnpin for DirectedGraph
impl UnwindSafe for DirectedGraph
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more