pub struct SimpleGraph { /* private fields */ }Expand description
A simple undirected graph with vertices labeled by generic type V.
Implementation note: This is a minimal educational implementation.
The Atlas uses a more specialized representation in crate::atlas.
§Examples
use atlas_embeddings::foundations::primitives::SimpleGraph;
// Create triangle graph
let mut g = SimpleGraph::new();
g.add_edge(0, 1);
g.add_edge(1, 2);
g.add_edge(2, 0);
assert_eq!(g.vertex_count(), 3);
assert_eq!(g.edge_count(), 3);
assert!(g.is_adjacent(0, 1));
assert!(g.is_adjacent(1, 0)); // UndirectedImplementations§
Source§impl SimpleGraph
impl SimpleGraph
Sourcepub fn add_vertex(&mut self) -> usize
pub fn add_vertex(&mut self) -> usize
Add a vertex to the graph, returning its index.
Vertices are numbered sequentially: 0, 1, 2, …
Sourcepub fn add_edge(&mut self, u: usize, v: usize)
pub fn add_edge(&mut self, u: usize, v: usize)
Add an undirected edge between vertices u and v.
Automatically adds vertices if they don’t exist yet.
Sourcepub fn is_adjacent(&self, u: usize, v: usize) -> bool
pub fn is_adjacent(&self, u: usize, v: usize) -> bool
Check if vertices u and v are adjacent.
Sourcepub fn degree(&self, v: usize) -> usize
pub fn degree(&self, v: usize) -> usize
Get the degree of vertex v (number of neighbors).
Definition: The degree of a vertex is the number of edges incident to it.
Sourcepub fn vertex_count(&self) -> usize
pub fn vertex_count(&self) -> usize
Get the number of vertices in the graph.
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Get the number of edges in the graph.
Since the graph is undirected, we count each edge once.
Trait Implementations§
Source§impl Clone for SimpleGraph
impl Clone for SimpleGraph
Source§fn clone(&self) -> SimpleGraph
fn clone(&self) -> SimpleGraph
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 SimpleGraph
impl Debug for SimpleGraph
Auto Trait Implementations§
impl Freeze for SimpleGraph
impl RefUnwindSafe for SimpleGraph
impl Send for SimpleGraph
impl Sync for SimpleGraph
impl Unpin for SimpleGraph
impl UnwindSafe for SimpleGraph
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