pub struct UndirectedGraph {
pub n: usize,
pub adj: Vec<HashSet<usize>>,
}Expand description
An undirected simple graph (represented as adjacency sets for simplicity).
Fields§
§n: usizeNumber of vertices.
adj: Vec<HashSet<usize>>Adjacency sets: adj[u] = set of neighbors
Implementations§
Source§impl UndirectedGraph
impl UndirectedGraph
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Is the graph connected?
Sourcepub fn num_components(&self) -> usize
pub fn num_components(&self) -> usize
Number of connected components.
Sourcepub fn bipartite_coloring(&self) -> Option<Vec<usize>>
pub fn bipartite_coloring(&self) -> Option<Vec<usize>>
Is the graph bipartite? Returns Some(coloring) or None.
Sourcepub fn is_bipartite(&self) -> bool
pub fn is_bipartite(&self) -> bool
Is the graph bipartite?
Sourcepub fn all_degrees_even(&self) -> bool
pub fn all_degrees_even(&self) -> bool
Check if all vertex degrees are even (necessary for Eulerian circuit).
Sourcepub fn has_eulerian_circuit(&self) -> bool
pub fn has_eulerian_circuit(&self) -> bool
Check if graph has an Eulerian circuit (connected + all even degrees).
Sourcepub fn greedy_coloring(&self) -> (usize, Vec<usize>)
pub fn greedy_coloring(&self) -> (usize, Vec<usize>)
Greedy graph coloring (returns number of colors used and coloring).
Sourcepub fn is_proper_coloring(&self, coloring: &[usize]) -> bool
pub fn is_proper_coloring(&self, coloring: &[usize]) -> bool
Check if a given coloring is proper.
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Number of edges.
Sourcepub fn spanning_tree(&self) -> Vec<(usize, usize)>
pub fn spanning_tree(&self) -> Vec<(usize, usize)>
Minimum spanning tree (Prim’s algorithm, unweighted → any spanning tree). Returns edges of the spanning tree.
Sourcepub fn complete_bipartite(m: usize, n: usize) -> Self
pub fn complete_bipartite(m: usize, n: usize) -> Self
Create complete bipartite graph K_{m,n}.
Trait Implementations§
Source§impl Clone for UndirectedGraph
impl Clone for UndirectedGraph
Source§fn clone(&self) -> UndirectedGraph
fn clone(&self) -> UndirectedGraph
Returns a duplicate of the value. Read more
1.0.0 · 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 UndirectedGraph
impl Debug for UndirectedGraph
Source§impl Default for UndirectedGraph
impl Default for UndirectedGraph
Source§fn default() -> UndirectedGraph
fn default() -> UndirectedGraph
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for UndirectedGraph
impl RefUnwindSafe for UndirectedGraph
impl Send for UndirectedGraph
impl Sync for UndirectedGraph
impl Unpin for UndirectedGraph
impl UnsafeUnpin for UndirectedGraph
impl UnwindSafe for UndirectedGraph
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