pub struct Graph { /* private fields */ }Expand description
Represents a directed graph using compact adjacency lists for both outgoing and incoming edges.
Adjacency lists are stored as sorted, deduplicated u32 vectors for cache-friendly iteration
and fast membership checks via binary search.
Implementations§
Source§impl Graph
impl Graph
pub fn new(num_nodes: usize) -> Self
pub fn node_count(&self) -> usize
pub fn edge_count(&self) -> usize
pub fn add_edge( &mut self, source: usize, target: usize, ) -> Result<(), GraphError>
pub fn add_edge_with_label( &mut self, source: usize, target: usize, label: u32, ) -> Result<(), GraphError>
pub fn has_edge(&self, source: usize, target: usize) -> bool
Sourcepub unsafe fn has_edge_unchecked(&self, source: usize, target: usize) -> bool
pub unsafe fn has_edge_unchecked(&self, source: usize, target: usize) -> bool
Fast edge check without bounds checking - caller must ensure indices are valid.
§Safety
The caller must ensure that both source and target are valid node indices
(i.e., source < self.node_count() and target < self.node_count()).
Violating this constraint will result in undefined behavior.
pub fn has_edge_undirected(&self, a: usize, b: usize) -> bool
pub fn get_edge_label(&self, source: usize, target: usize) -> Option<u32>
pub fn has_edge_with_label( &self, source: usize, target: usize, label: u32, ) -> bool
pub fn has_edge_undirected_with_label( &self, a: usize, b: usize, label: u32, ) -> bool
pub fn out_degree(&self, node: usize) -> Option<usize>
pub fn in_degree(&self, node: usize) -> Option<usize>
Sourcepub fn undirected_degree(&self, node: usize) -> Option<usize>
pub fn undirected_degree(&self, node: usize) -> Option<usize>
Returns the undirected degree (unique neighbor count ignoring direction).
pub fn outgoing_edges(&self, node: usize) -> Option<&[u32]>
pub fn incoming_edges(&self, node: usize) -> Option<&[u32]>
pub fn set_label(&mut self, node: usize, label: u32) -> Result<(), GraphError>
pub fn label(&self, node: usize) -> u32
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Graph
impl RefUnwindSafe for Graph
impl Send for Graph
impl Sync for Graph
impl Unpin for Graph
impl UnwindSafe for Graph
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