pub struct CourseGraph {
pub graph: DiGraph<CourseNode, ()>,
pub node_map: HashMap<String, NodeIndex>,
}Fields§
§graph: DiGraph<CourseNode, ()>§node_map: HashMap<String, NodeIndex>Implementations§
Source§impl CourseGraph
impl CourseGraph
pub fn new() -> Self
Sourcepub fn add_edge(&mut self, prerequisite_id: &str, course_id: &str) -> Result<()>
pub fn add_edge(&mut self, prerequisite_id: &str, course_id: &str) -> Result<()>
Add an edge between two nodes (prerequisite -> course)
Sourcepub fn get_node(&self, id: &str) -> Option<&CourseNode>
pub fn get_node(&self, id: &str) -> Option<&CourseNode>
Get a node by its ID
Sourcepub fn nodes(&self) -> impl Iterator<Item = (NodeIndex, &CourseNode)>
pub fn nodes(&self) -> impl Iterator<Item = (NodeIndex, &CourseNode)>
Get all nodes in the graph
Sourcepub fn edges(&self) -> impl Iterator<Item = (NodeIndex, NodeIndex)> + '_
pub fn edges(&self) -> impl Iterator<Item = (NodeIndex, NodeIndex)> + '_
Get all edges in the graph
Sourcepub fn has_cycles(&self) -> bool
pub fn has_cycles(&self) -> bool
Check if the graph has cycles
Sourcepub fn topological_sort(&self) -> Result<Vec<NodeIndex>>
pub fn topological_sort(&self) -> Result<Vec<NodeIndex>>
Get nodes in topological order (if the graph is acyclic)
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Get the number of nodes
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Get the number of edges
Sourcepub fn find_root_nodes(&self) -> Vec<NodeIndex>
pub fn find_root_nodes(&self) -> Vec<NodeIndex>
Find nodes with no prerequisites (root nodes)
Sourcepub fn find_leaf_nodes(&self) -> Vec<NodeIndex>
pub fn find_leaf_nodes(&self) -> Vec<NodeIndex>
Find nodes with no dependents (leaf nodes)
Trait Implementations§
Source§impl Clone for CourseGraph
impl Clone for CourseGraph
Source§fn clone(&self) -> CourseGraph
fn clone(&self) -> CourseGraph
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 CourseGraph
impl Debug for CourseGraph
Auto Trait Implementations§
impl Freeze for CourseGraph
impl RefUnwindSafe for CourseGraph
impl Send for CourseGraph
impl Sync for CourseGraph
impl Unpin for CourseGraph
impl UnsafeUnpin for CourseGraph
impl UnwindSafe for CourseGraph
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