pub struct SparseGraph<T: Clone> { /* private fields */ }Expand description
Structure representation of a sparse graph
§Fields
adjacency- Sparse CSR representation of the graph withf16as weights.num_nodes- Number of nodes represented in the graph.directed- Whether the graph is directed or not.
Implementations§
Source§impl<T> SparseGraph<T>
impl<T> SparseGraph<T>
Sourcepub fn new(
num_nodes: usize,
adjacency: CompressedSparseData2<T>,
directed: bool,
) -> Self
pub fn new( num_nodes: usize, adjacency: CompressedSparseData2<T>, directed: bool, ) -> Self
Sourcepub fn get_neighbours_raw(&self, node: usize) -> (&[u32], &[T])
pub fn get_neighbours_raw(&self, node: usize) -> (&[u32], &[T])
Sourcepub fn get_node_degree(&self, node: usize) -> usize
pub fn get_node_degree(&self, node: usize) -> usize
Sourcepub fn total_weight(&self) -> T
pub fn total_weight(&self) -> T
Sourcepub fn get_node_number(&self) -> usize
pub fn get_node_number(&self) -> usize
Sourcepub fn is_directed(&self) -> bool
pub fn is_directed(&self) -> bool
Sourcepub fn get_edge_number(&self) -> usize
pub fn get_edge_number(&self) -> usize
Number of edges
An undirected graph stores every edge twice, a self-loop included (both
entries in its own row, as edge_pairs_to_sparse_graph builds it).
§Returns
The number of stored entries for a directed graph, half of them for an undirected one.
Sourcepub fn to_edge_pairs(&self) -> (Vec<u32>, Vec<T>)
pub fn to_edge_pairs(&self) -> (Vec<u32>, Vec<T>)
Flatten the graph into an edge-pair list
The inverse of edge_pairs_to_sparse_graph: an undirected edge comes
out once, as (i, j) with i < j, and a self-loop once for each pair
of entries it holds. A directed graph gives every stored entry. Rows
are flattened in parallel, one chunk per worker, so the order is by
source node, then by the CSR order within the row.
§Returns
Tuple of (edges, weights): edges holds the pairs flat,
[u, v, u, v, ...], 0-based; weights one weight per pair.
Source§impl<T> SparseGraph<T>
impl<T> SparseGraph<T>
Sourcepub fn to_bytes(&self) -> Result<Vec<u8>, MethodsErrors>
pub fn to_bytes(&self) -> Result<Vec<u8>, MethodsErrors>
Serialise the graph to bytes
§Returns
A blob that Self::from_bytes reads back. See
bixverse_sparse::serialise for the layout.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self, MethodsErrors>
pub fn from_bytes(bytes: &[u8]) -> Result<Self, MethodsErrors>
Read a graph written by Self::to_bytes
The adjacency is checked for being a structurally sound square CSR
over num_nodes nodes, since the bytes may come from disk.
§Params
bytes- The blob
§Returns
The graph, or a header, decode or validation error.
Trait Implementations§
Source§impl<'de, T> Deserialize<'de> for SparseGraph<T>where
T: Deserialize<'de> + Clone,
impl<'de, T> Deserialize<'de> for SparseGraph<T>where
T: Deserialize<'de> + Clone,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl<T> Freeze for SparseGraph<T>where
CompressedSparseData2<T>: Freeze,
impl<T> RefUnwindSafe for SparseGraph<T>where
CompressedSparseData2<T>: RefUnwindSafe,
impl<T> Send for SparseGraph<T>where
CompressedSparseData2<T>: Send,
impl<T> Sync for SparseGraph<T>where
CompressedSparseData2<T>: Sync,
impl<T> Unpin for SparseGraph<T>where
CompressedSparseData2<T>: Unpin,
impl<T> UnsafeUnpin for SparseGraph<T>where
CompressedSparseData2<T>: UnsafeUnpin,
impl<T> UnwindSafe for SparseGraph<T>where
CompressedSparseData2<T>: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T, U> Imply<T> for U
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.