pub struct DirectedGraph<T: PartialEq + Hash + Copy + Ord + Debug + Display>(/* private fields */);
Expand description
A directed graph, whose nodes contain an identifier of type T
.
Implementations§
Source§impl<T: PartialEq + Hash + Copy + Ord + Debug + Display> DirectedGraph<T>
impl<T: PartialEq + Hash + Copy + Ord + Debug + Display> DirectedGraph<T>
Sourcepub fn add_edge(&mut self, source: T, target: T)
pub fn add_edge(&mut self, source: T, target: T)
Add an edge to the graph, adding nodes if necessary.
Sourcepub fn get_targets(&self, id: T) -> Option<&HashSet<T>>
pub fn get_targets(&self, id: T) -> Option<&HashSet<T>>
Get targets of all edges from this node.
Sourcepub fn topological_sort(&self) -> Result<Vec<T>, Error<T>>
pub fn topological_sort(&self) -> Result<Vec<T>, Error<T>>
Returns the nodes of the graph in reverse topological order, or an error if the graph contains a cycle.
TODO: //src/devices/tools/banjo/srt/ast.rs can be migrated to use this feature.
Sourcepub fn find_shortest_path(&self, from: T, to: T) -> Option<Vec<T>>
pub fn find_shortest_path(&self, from: T, to: T) -> Option<Vec<T>>
Finds the shortest path between the from
and to
nodes in this graph, if such a path
exists. Both from
and to
are included in the returned path.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for DirectedGraph<T>
impl<T> RefUnwindSafe for DirectedGraph<T>where
T: RefUnwindSafe,
impl<T> Send for DirectedGraph<T>where
T: Send,
impl<T> Sync for DirectedGraph<T>where
T: Sync,
impl<T> Unpin for DirectedGraph<T>where
T: Unpin,
impl<T> UnwindSafe for DirectedGraph<T>where
T: UnwindSafe,
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