pub struct CsrGraph<DCF = Box<[usize]>, S = Box<[usize]>> { /* private fields */ }Expand description
A compressed sparse-row graph.
It is a graph representation that stores the degree cumulative function (DCF) and the successors in a compressed format. The DCF is a sequence of offsets that indicates the start of the neighbors for each node in the graph. Building a CSR graph requires always a sorted lender.
The lenders returned by a CSR graph are sorted; however, the successors may
be unsorted. If you need the additional guarantee that the successors are
sorted, use CsrSortedGraph, which however requires a lender returning
sorted successors.
Depending on the performance and memory requirements, both the DCF and successors can be stored in different formats. The default is to use boxed slices for both the DCF and successors, which is the fastest choice.
A CompressedCsrGraph, instead, is a CsrGraph where the DCF is
represented using an Elias-Fano encoding, and the successors are represented
using a BitFieldVec. There is also a version with sorted
successors. Their construction requires a
sequential graph providing the number of arcs.
Implementations§
Source§impl<DCF, S> CsrGraph<DCF, S>
impl<DCF, S> CsrGraph<DCF, S>
Sourcepub unsafe fn from_parts(dcf: DCF, successors: S) -> Self
pub unsafe fn from_parts(dcf: DCF, successors: S) -> Self
Creates a new CSR graph from the given degree cumulative function and successors.
§Safety
The degree cumulative function must be monotone and coherent with the successors.
Sourcepub fn successors(&self) -> &S
pub fn successors(&self) -> &S
Returns a reference to the successors.
Sourcepub fn into_inner(self) -> (DCF, S)
pub fn into_inner(self) -> (DCF, S)
Consumes the graph, returning the degree cumulative function and the successors.
Source§impl CsrGraph
impl CsrGraph
Sourcepub fn from_lender<I: IntoLender>(iter_nodes: I) -> Self
pub fn from_lender<I: IntoLender>(iter_nodes: I) -> Self
Creates a new CSR graph from an IntoLender yielding a
NodeLabelsLender.
This method will determine the number of nodes from the maximum node ID encountered.
Sourcepub fn from_sorted_lender<I: IntoLender>(iter_nodes: I) -> Selfwhere
I::Lender: for<'next> NodeLabelsLender<'next, Label = usize> + SortedLender,
for<'succ> LenderIntoIter<'succ, I::Lender>: SortedIterator,
pub fn from_sorted_lender<I: IntoLender>(iter_nodes: I) -> Selfwhere
I::Lender: for<'next> NodeLabelsLender<'next, Label = usize> + SortedLender,
for<'succ> LenderIntoIter<'succ, I::Lender>: SortedIterator,
Creates a new CSR graph from a sorted IntoLender yielding a
sorted NodeLabelsLender.
This method is an alias for from_lender, as both
sorted and unsorted lenders are handled identically in the unsorted case.
Sourcepub fn from_seq_graph<G: SequentialGraph>(g: &G) -> Selfwhere
for<'a> G::Lender<'a>: SortedLender,
pub fn from_seq_graph<G: SequentialGraph>(g: &G) -> Selfwhere
for<'a> G::Lender<'a>: SortedLender,
Creates a new CSR graph from a SequentialGraph.
This method uses the graph’s size hints for efficient pre-allocation.
Source§impl CsrGraph<EliasFano<SelectAdaptConst<BitVec<Box<[usize]>>, Box<[usize]>, 12, 4>>, BitFieldVec>
impl CsrGraph<EliasFano<SelectAdaptConst<BitVec<Box<[usize]>>, Box<[usize]>, 12, 4>>, BitFieldVec>
Sourcepub fn try_from_graph<G: SequentialGraph>(g: &G) -> Result<Self>where
for<'a> G::Lender<'a>: SortedLender,
pub fn try_from_graph<G: SequentialGraph>(g: &G) -> Result<Self>where
for<'a> G::Lender<'a>: SortedLender,
Creates a new compressed CSR graph from a sequential graph with sorted lender and providing the number of arcs.
This method will return an error if the graph does not provide the number of arcs.
Trait Implementations§
Source§impl<DCF, S> AlignHash for CsrGraph<DCF, S>
impl<DCF, S> AlignHash for CsrGraph<DCF, S>
Source§fn align_hash(hasher: &mut impl Hasher, offset_of: &mut usize)
fn align_hash(hasher: &mut impl Hasher, offset_of: &mut usize)
hasher assuming to be positioned
at offset_of.Source§fn align_hash_val(&self, hasher: &mut impl Hasher, offset_of: &mut usize)
fn align_hash_val(&self, hasher: &mut impl Hasher, offset_of: &mut usize)
AlignHash::align_hash on a value.Source§impl<DCF, S> DeserInner for CsrGraph<DCF, S>where
DCF: DeserInner,
S: DeserInner,
impl<DCF, S> DeserInner for CsrGraph<DCF, S>where
DCF: DeserInner,
S: DeserInner,
Source§type DeserType<'__epserde_desertype> = CsrGraph<<DCF as DeserInner>::DeserType<'__epserde_desertype>, <S as DeserInner>::DeserType<'__epserde_desertype>>
type DeserType<'__epserde_desertype> = CsrGraph<<DCF as DeserInner>::DeserType<'__epserde_desertype>, <S as DeserInner>::DeserType<'__epserde_desertype>>
DeserType.Source§unsafe fn _deser_full_inner(
backend: &mut impl ReadWithPos,
) -> Result<Self, Error>
unsafe fn _deser_full_inner( backend: &mut impl ReadWithPos, ) -> Result<Self, Error>
Source§unsafe fn _deser_eps_inner<'deser_eps_inner_lifetime>(
backend: &mut SliceWithPos<'deser_eps_inner_lifetime>,
) -> Result<Self::DeserType<'deser_eps_inner_lifetime>, Error>
unsafe fn _deser_eps_inner<'deser_eps_inner_lifetime>( backend: &mut SliceWithPos<'deser_eps_inner_lifetime>, ) -> Result<Self::DeserType<'deser_eps_inner_lifetime>, Error>
Source§impl<'a, DCF, S> IntoLender for &'a CsrGraph<DCF, S>where
DCF: SliceByValue + IterateByValueFrom<Item = usize>,
S: SliceByValue + IterateByValueFrom<Item = usize>,
Convenience implementation that makes it possible to iterate
over the graph using the for_ macro
(see the crate documentation).
impl<'a, DCF, S> IntoLender for &'a CsrGraph<DCF, S>where
DCF: SliceByValue + IterateByValueFrom<Item = usize>,
S: SliceByValue + IterateByValueFrom<Item = usize>,
Convenience implementation that makes it possible to iterate
over the graph using the for_ macro
(see the crate documentation).
Source§type Lender = LenderImpl<<DCF as IterateByValueFromGat<'a>>::IterFrom, <S as IterateByValueFromGat<'a>>::IterFrom>
type Lender = LenderImpl<<DCF as IterateByValueFromGat<'a>>::IterFrom, <S as IterateByValueFromGat<'a>>::IterFrom>
Source§fn into_lender(self) -> Self::Lender
fn into_lender(self) -> Self::Lender
Lender.Source§impl<DCF, S> RandomAccessGraph for CsrGraph<DCF, S>where
DCF: SliceByValue<Value = usize> + IterateByValueFrom<Item = usize>,
S: SliceByValue<Value = usize> + IterateByValueFrom<Item = usize>,
impl<DCF, S> RandomAccessGraph for CsrGraph<DCF, S>where
DCF: SliceByValue<Value = usize> + IterateByValueFrom<Item = usize>,
S: SliceByValue<Value = usize> + IterateByValueFrom<Item = usize>,
Source§impl<DCF, S> RandomAccessLabeling for CsrGraph<DCF, S>where
DCF: SliceByValue<Value = usize> + IterateByValueFrom<Item = usize>,
S: SliceByValue<Value = usize> + IterateByValueFrom<Item = usize>,
impl<DCF, S> RandomAccessLabeling for CsrGraph<DCF, S>where
DCF: SliceByValue<Value = usize> + IterateByValueFrom<Item = usize>,
S: SliceByValue<Value = usize> + IterateByValueFrom<Item = usize>,
Source§impl<DCF, S> SequentialLabeling for CsrGraph<DCF, S>where
DCF: SliceByValue + IterateByValueFrom<Item = usize>,
S: SliceByValue + IterateByValueFrom<Item = usize>,
impl<DCF, S> SequentialLabeling for CsrGraph<DCF, S>where
DCF: SliceByValue + IterateByValueFrom<Item = usize>,
S: SliceByValue + IterateByValueFrom<Item = usize>,
type Label = usize
Source§type Lender<'a> = LenderImpl<<DCF as IterateByValueFromGat<'a>>::IterFrom, <S as IterateByValueFromGat<'a>>::IterFrom>
where
Self: 'a
type Lender<'a> = LenderImpl<<DCF as IterateByValueFromGat<'a>>::IterFrom, <S as IterateByValueFromGat<'a>>::IterFrom> where Self: 'a
Source§fn num_arcs_hint(&self) -> Option<u64>
fn num_arcs_hint(&self) -> Option<u64>
Source§fn iter_from(&self, from: usize) -> Self::Lender<'_>
fn iter_from(&self, from: usize) -> Self::Lender<'_>
from (included). Read moreSource§fn par_node_apply<A: Default + Send, F: Fn(Range<usize>) -> A + Sync, R: Fn(A, A) -> A + Sync>(
&self,
func: F,
fold: R,
granularity: Granularity,
pl: &mut impl ConcurrentProgressLog,
) -> A
fn par_node_apply<A: Default + Send, F: Fn(Range<usize>) -> A + Sync, R: Fn(A, A) -> A + Sync>( &self, func: F, fold: R, granularity: Granularity, pl: &mut impl ConcurrentProgressLog, ) -> A
func to each chunk of nodes of size node_granularity in
parallel, and folds the results using fold. Read moreSource§fn par_apply<F: Fn(Range<usize>) -> A + Sync, A: Default + Send, R: Fn(A, A) -> A + Sync, D: for<'a> Succ<Input = usize, Output<'a> = usize>>(
&self,
func: F,
fold: R,
granularity: Granularity,
deg_cumul: &D,
pl: &mut impl ConcurrentProgressLog,
) -> A
fn par_apply<F: Fn(Range<usize>) -> A + Sync, A: Default + Send, R: Fn(A, A) -> A + Sync, D: for<'a> Succ<Input = usize, Output<'a> = usize>>( &self, func: F, fold: R, granularity: Granularity, deg_cumul: &D, pl: &mut impl ConcurrentProgressLog, ) -> A
func to each chunk of nodes containing approximately
arc_granularity arcs in parallel and folds the results using fold. Read moreSource§impl<DCF, S> SerInner for CsrGraph<DCF, S>
impl<DCF, S> SerInner for CsrGraph<DCF, S>
Source§const IS_ZERO_COPY: bool
const IS_ZERO_COPY: bool
ZeroCopy type has this constant set to false
serialization will panic.Source§type SerType = CsrGraph<<DCF as SerInner>::SerType, <S as SerInner>::SerType>
type SerType = CsrGraph<<DCF as SerInner>::SerType, <S as SerInner>::SerType>
Self, but
in some cases, as for references to slices,
it is customized.Source§unsafe fn _ser_inner(&self, backend: &mut impl WriteWithNames) -> Result<()>
unsafe fn _ser_inner(&self, backend: &mut impl WriteWithNames) -> Result<()>
Source§impl<DCF, S> TypeHash for CsrGraph<DCF, S>
impl<DCF, S> TypeHash for CsrGraph<DCF, S>
Source§fn type_hash_val(&self, hasher: &mut impl Hasher)
fn type_hash_val(&self, hasher: &mut impl Hasher)
TypeHash::type_hash on a value.impl<D, S> SequentialGraph for CsrGraph<D, S>where
D: SliceByValue + IterateByValueFrom<Item = usize>,
S: SliceByValue + IterateByValueFrom<Item = usize>,
Auto Trait Implementations§
impl<DCF, S> Freeze for CsrGraph<DCF, S>
impl<DCF, S> RefUnwindSafe for CsrGraph<DCF, S>where
DCF: RefUnwindSafe,
S: RefUnwindSafe,
impl<DCF, S> Send for CsrGraph<DCF, S>
impl<DCF, S> Sync for CsrGraph<DCF, S>
impl<DCF, S> Unpin for CsrGraph<DCF, S>
impl<DCF, S> UnsafeUnpin for CsrGraph<DCF, S>where
DCF: UnsafeUnpin,
S: UnsafeUnpin,
impl<DCF, S> UnwindSafe for CsrGraph<DCF, S>where
DCF: UnwindSafe,
S: 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
Source§impl<T, U> CastableInto<U> for Twhere
U: CastableFrom<T>,
impl<T, U> CastableInto<U> for Twhere
U: CastableFrom<T>,
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DowncastableFrom<T> for T
impl<T> DowncastableFrom<T> for T
Source§fn downcast_from(value: T) -> T
fn downcast_from(value: T) -> T
Source§impl<T, U> DowncastableInto<U> for Twhere
U: DowncastableFrom<T>,
impl<T, U> DowncastableInto<U> for Twhere
U: DowncastableFrom<T>,
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