pub struct MetricsGraph { /* private fields */ }Expand description
A simple adjacency-list graph for metric computation.
Implementations§
Source§impl MetricsGraph
impl MetricsGraph
Sourcepub fn new_directed() -> Self
pub fn new_directed() -> Self
Create a new directed metrics graph.
Sourcepub fn new_undirected() -> Self
pub fn new_undirected() -> Self
Create a new undirected metrics graph.
Sourcepub fn add_edge(&mut self, from: usize, to: usize)
pub fn add_edge(&mut self, from: usize, to: usize)
Add an edge between two nodes. In undirected mode, adds both directions.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Returns the number of nodes.
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Returns the number of edges.
Sourcepub fn diameter(&self) -> Option<usize>
pub fn diameter(&self) -> Option<usize>
Compute the graph diameter (longest shortest path between any two nodes).
Returns None if the graph is empty or disconnected (between the connected components).
Sourcepub fn local_clustering_coefficient(&self, node: usize) -> f64
pub fn local_clustering_coefficient(&self, node: usize) -> f64
Compute the local clustering coefficient for a given node.
For an undirected graph: C(v) = 2 * edges_between_neighbors / (k * (k-1)) where k = degree of v.
Sourcepub fn average_clustering_coefficient(&self) -> f64
pub fn average_clustering_coefficient(&self) -> f64
Compute the average clustering coefficient of the graph.
Sourcepub fn betweenness_centrality(&self) -> HashMap<usize, f64>
pub fn betweenness_centrality(&self) -> HashMap<usize, f64>
Approximate betweenness centrality using Brandes’ algorithm (exact for small graphs).
Returns a map of node_id -> centrality score (unnormalized).
Trait Implementations§
Source§impl Clone for MetricsGraph
impl Clone for MetricsGraph
Source§fn clone(&self) -> MetricsGraph
fn clone(&self) -> MetricsGraph
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for MetricsGraph
impl RefUnwindSafe for MetricsGraph
impl Send for MetricsGraph
impl Sync for MetricsGraph
impl Unpin for MetricsGraph
impl UnsafeUnpin for MetricsGraph
impl UnwindSafe for MetricsGraph
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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