pub struct SimpleGraph { /* private fields */ }Expand description
Simple directed graph with adjacency lists.
Stores outgoing and incoming edge lists per vertex for O(degree) traversal, plus a direct Eid-to-edge map for O(1) edge lookup.
Implementations§
Source§impl SimpleGraph
impl SimpleGraph
Sourcepub fn with_capacity(vertices: usize, edges: usize) -> Self
pub fn with_capacity(vertices: usize, edges: usize) -> Self
Creates a new graph with pre-allocated capacity.
Sourcepub fn add_vertex(&mut self, vid: Vid) -> bool
pub fn add_vertex(&mut self, vid: Vid) -> bool
Adds a vertex to the graph. Returns true if the vertex was newly added.
Sourcepub fn remove_vertex(&mut self, vid: Vid)
pub fn remove_vertex(&mut self, vid: Vid)
Removes a vertex and all its edges from the graph.
Sourcepub fn contains_vertex(&self, vid: Vid) -> bool
pub fn contains_vertex(&self, vid: Vid) -> bool
Checks if a vertex exists in the graph.
Sourcepub fn vertex_count(&self) -> usize
pub fn vertex_count(&self) -> usize
Returns the number of vertices in the graph.
Sourcepub fn add_edge(&mut self, src_vid: Vid, dst_vid: Vid, eid: Eid, edge_type: u32)
pub fn add_edge(&mut self, src_vid: Vid, dst_vid: Vid, eid: Eid, edge_type: u32)
Adds an edge to the graph. Vertices are implicitly created if they don’t exist.
Sourcepub fn add_edge_unchecked(
&mut self,
src_vid: Vid,
dst_vid: Vid,
eid: Eid,
edge_type: u32,
)
pub fn add_edge_unchecked( &mut self, src_vid: Vid, dst_vid: Vid, eid: Eid, edge_type: u32, )
Adds an edge without checking if vertices exist. Use when vertices are pre-added.
Sourcepub fn remove_edge(&mut self, eid: Eid) -> Option<EdgeEntry>
pub fn remove_edge(&mut self, eid: Eid) -> Option<EdgeEntry>
Removes an edge by its ID. Returns the removed edge entry if found.
Uses O(1) lookup via edge_map, then O(degree) removal from adjacency lists.
Sourcepub fn neighbors(&self, vid: Vid, direction: Direction) -> &[EdgeEntry]
pub fn neighbors(&self, vid: Vid, direction: Direction) -> &[EdgeEntry]
Returns neighbors in the specified direction. O(degree) complexity.
Sourcepub fn edges(&self) -> impl Iterator<Item = &EdgeEntry>
pub fn edges(&self) -> impl Iterator<Item = &EdgeEntry>
Returns an iterator over all edges in the graph.
Sourcepub fn edge(&self, eid: Eid) -> Option<&EdgeEntry>
pub fn edge(&self, eid: Eid) -> Option<&EdgeEntry>
Returns the edge with the given Eid in O(1) time.
Sourcepub fn vertex(&self, vid: Vid) -> Option<Vid>
pub fn vertex(&self, vid: Vid) -> Option<Vid>
Checks if a vertex exists and returns it (identity).
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Returns the total number of edges in the graph.
Trait Implementations§
Source§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 UnsafeUnpin 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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more