pub struct Network { /* private fields */ }Expand description
Undirected weighted graph backing the Leiden / Louvain algorithms.
Node ids are dense usize in 0..nodes(). Each undirected edge is stored
twice (once per endpoint) so adjacency iteration is O(deg). Internal
adjacency uses u32 neighbour ids for compactness; callers see only usize.
Implementations§
Source§impl Network
impl Network
Sourcepub fn with_capacity(n_nodes: usize) -> Network
pub fn with_capacity(n_nodes: usize) -> Network
Create a new empty network with capacity for n_nodes nodes.
Sourcepub fn with_nodes(node_weights: &[f32], degrees: &[usize]) -> Network
pub fn with_nodes(node_weights: &[f32], degrees: &[usize]) -> Network
Every node at once, with weight and room for degree neighbours, so
the edges that follow never grow an adjacency list.
Sourcepub fn add_node(&mut self, weight: f32) -> usize
pub fn add_node(&mut self, weight: f32) -> usize
Append a node with weight. Returns its node id.
Sourcepub fn add_edge(&mut self, source: usize, target: usize, weight: f32)
pub fn add_edge(&mut self, source: usize, target: usize, weight: f32)
Add an undirected edge between source and target with weight.
§Panics
If source or target exceeds u32::MAX, or is out of range.
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Number of undirected edges (each pair counted once).
Sourcepub fn node_weight_mut(&mut self, node: usize) -> &mut f32
pub fn node_weight_mut(&mut self, node: usize) -> &mut f32
Sourcepub fn neighbors(&self, node: usize) -> NeighborAndWeightIter<'_> ⓘ
pub fn neighbors(&self, node: usize) -> NeighborAndWeightIter<'_> ⓘ
Sourcepub fn edge_references(&self) -> EdgeReferences<'_> ⓘ
pub fn edge_references(&self) -> EdgeReferences<'_> ⓘ
Iterator over each undirected edge once.
Sourcepub fn get_total_node_weight(&self) -> f64
pub fn get_total_node_weight(&self) -> f64
Sum of all node weights.
Sourcepub fn get_total_edge_weight(&self) -> f64
pub fn get_total_edge_weight(&self) -> f64
Sum of all edge weights (each undirected edge counted once).
Sourcepub fn get_total_edge_weight_par(&self) -> f64
pub fn get_total_edge_weight_par(&self) -> f64
Parallel total edge weight. Sums the double-counted weights then divides by 2. Chunked + serially reduced for determinism.
Sourcepub fn get_total_edge_weight_per_node(&self, result: &mut Vec<f64>)
pub fn get_total_edge_weight_per_node(&self, result: &mut Vec<f64>)
Tabulate the total edge weight of each node into result.
Sourcepub fn create_reduced_network(&self, clustering: &impl Clustering) -> Network
pub fn create_reduced_network(&self, clustering: &impl Clustering) -> Network
Aggregate network where each cluster becomes a single node.
Node weights are summed within each cluster. Edge weights between distinct clusters are summed. Within-cluster edges are dropped — only the inter-cluster summary is preserved.
§Panics
If a cluster id exceeds u32::MAX.
Sourcepub fn create_subnetworks(&self, c: &impl Clustering) -> Vec<Network>
pub fn create_subnetworks(&self, c: &impl Clustering) -> Vec<Network>
One subnetwork per cluster, containing only intra-cluster edges.
§Panics
If a node index exceeds u32::MAX.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Network
impl RefUnwindSafe for Network
impl Send for Network
impl Sync for Network
impl Unpin for Network
impl UnsafeUnpin for Network
impl UnwindSafe for Network
Blanket Implementations§
impl<T> Allocation for T
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> 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> Pointable for T
impl<T> Pointable for T
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.