pub struct CsrGraph { /* private fields */ }Expand description
A directed, weighted graph in Compressed Sparse Row format.
Built once from the edge set and reused by every graph algorithm. Both forward (out-edges) and reverse (in-edges) CSR arrays are stored: PageRank and Dijkstra consume out-edges; community detection and similarity use the undirected view (both directions).
Implementations§
Source§impl CsrGraph
impl CsrGraph
Sourcepub fn from_edges(node_ids: &[String], edges: &[GraphEdge]) -> Self
pub fn from_edges(node_ids: &[String], edges: &[GraphEdge]) -> Self
Build a CSR graph from an explicit node-id list and edge list.
Edges whose source or target is absent from node_ids are dropped
(foreign-reference integrity). Duplicate node IDs collapse to the first
occurrence. The construction is O(V + E log E).
Sourcepub fn build_csr(conn: &Connection) -> Result<Self>
pub fn build_csr(conn: &Connection) -> Result<Self>
Build a CSR snapshot from a SQLite connection.
Loads all node IDs (including edge-less dangling nodes) and a node-count-proportional edge cap.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Number of nodes.
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Number of resolved edges (orphans excluded).
Sourcepub fn node_index(&self, id: &str) -> Option<u32>
pub fn node_index(&self, id: &str) -> Option<u32>
Resolve a node ID to its index, or None if absent.
Sourcepub fn node_id(&self, idx: u32) -> &str
pub fn node_id(&self, idx: u32) -> &str
Resolve an index back to its node ID. Panics on out-of-range index.
Sourcepub fn out_neighbors(&self, src: u32) -> impl Iterator<Item = (u32, f64)> + '_
pub fn out_neighbors(&self, src: u32) -> impl Iterator<Item = (u32, f64)> + '_
Iterate (target_idx, weight) over the out-edges of src.
Sourcepub fn in_neighbors(&self, dst: u32) -> impl Iterator<Item = (u32, f64)> + '_
pub fn in_neighbors(&self, dst: u32) -> impl Iterator<Item = (u32, f64)> + '_
Iterate (source_idx, weight) over the in-edges of dst.
Sourcepub fn out_degree(&self, idx: u32) -> u32
pub fn out_degree(&self, idx: u32) -> u32
Out-degree (number of out-edges) of idx.
Sourcepub fn out_weight_sum(&self, idx: u32) -> f64
pub fn out_weight_sum(&self, idx: u32) -> f64
Sum of out-edge weights for idx. <= 0.0 marks a dangling node.
Sourcepub fn is_dangling(&self, idx: u32) -> bool
pub fn is_dangling(&self, idx: u32) -> bool
Whether idx is a dangling node — no out-edges, or all-zero weights.
PageRank redistributes a dangling node’s rank mass globally each iteration to prevent rank leakage and convergence failure.
Sourcepub fn node_indices(&self) -> Range<u32>
pub fn node_indices(&self) -> Range<u32>
Iterate all node indices in [0, node_count).
Auto Trait Implementations§
impl Freeze for CsrGraph
impl RefUnwindSafe for CsrGraph
impl Send for CsrGraph
impl Sync for CsrGraph
impl Unpin for CsrGraph
impl UnsafeUnpin for CsrGraph
impl UnwindSafe for CsrGraph
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.