Skip to main content

CsrGraph

Struct CsrGraph 

Source
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>

Source

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.

Source

pub fn dcf(&self) -> &DCF

Returns a reference to the degree cumulative function.

Source

pub fn successors(&self) -> &S

Returns a reference to the successors.

Source

pub fn into_inner(self) -> (DCF, S)

Consumes the graph, returning the degree cumulative function and the successors.

Source§

impl CsrGraph

Source

pub fn new() -> Self

Creates an empty CSR graph.

Source

pub fn from_lender<I: IntoLender>(iter_nodes: I) -> Self
where I::Lender: for<'next> NodeLabelsLender<'next, Label = usize> + SortedLender,

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.

Source

pub fn from_sorted_lender<I: IntoLender>(iter_nodes: I) -> Self
where 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.

Source

pub fn from_seq_graph<G: SequentialGraph>(g: &G) -> Self
where 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>

Source

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>
where DCF: SerInner<SerType: AlignHash>, S: SerInner<SerType: AlignHash>,

Source§

fn align_hash(hasher: &mut impl Hasher, offset_of: &mut usize)

Accumulates alignment information in hasher assuming to be positioned at offset_of.
Source§

fn align_hash_val(&self, hasher: &mut impl Hasher, offset_of: &mut usize)

Calls AlignHash::align_hash on a value.
Source§

impl<DCF: Clone, S: Clone> Clone for CsrGraph<DCF, S>

Source§

fn clone(&self) -> CsrGraph<DCF, S>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<DCF, S> CopyType for CsrGraph<DCF, S>

Source§

impl<DCF: Debug, S: Debug> Debug for CsrGraph<DCF, S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CsrGraph

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

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>>

The deserialization type associated with this type. It can be retrieved conveniently with the alias DeserType.
Source§

unsafe fn _deser_full_inner( backend: &mut impl ReadWithPos, ) -> Result<Self, Error>

Safety Read more
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>

Safety Read more
Source§

impl<'a, DCF, S> IntoLender for &'a CsrGraph<DCF, S>

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>

The lender type that this type converts into.
Source§

fn into_lender(self) -> Self::Lender

Converts this type into a 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>,

Source§

fn successors( &self, node_id: usize, ) -> <Self as RandomAccessLabeling>::Labels<'_>

Returns the successors of a node. Read more
Source§

fn has_arc(&self, src_node_id: usize, dst_node_id: usize) -> bool

Returns whether there is an arc going from src_node_id to dst_node_id. Read more
Source§

impl<DCF, S> RandomAccessLabeling for CsrGraph<DCF, S>
where DCF: SliceByValue<Value = usize> + IterateByValueFrom<Item = usize>, S: SliceByValue<Value = usize> + IterateByValueFrom<Item = usize>,

Source§

type Labels<'succ> = Take<<S as IterateByValueFromGat<'succ>>::IterFrom> where Self: 'succ

The type of the iterator over the labels of a node returned by labels.
Source§

fn num_arcs(&self) -> u64

Returns the number of arcs in the graph.
Source§

fn outdegree(&self, node: usize) -> usize

Returns the number of labels associated with a node.
Source§

fn labels(&self, node: usize) -> <Self as RandomAccessLabeling>::Labels<'_>

Returns the labels associated with a node.
Source§

impl<DCF, S> SequentialLabeling for CsrGraph<DCF, S>

Source§

type Label = usize

Source§

type Lender<'a> = LenderImpl<<DCF as IterateByValueFromGat<'a>>::IterFrom, <S as IterateByValueFromGat<'a>>::IterFrom> where Self: 'a

The type of Lender over the successors of a node returned by iter.
Source§

fn num_nodes(&self) -> usize

Returns the number of nodes in the graph.
Source§

fn num_arcs_hint(&self) -> Option<u64>

Returns the number of arcs in the graph, if available.
Source§

fn iter_from(&self, from: usize) -> Self::Lender<'_>

Returns an iterator over the labeling starting at from (included). Read more
Source§

fn build_dcf(&self) -> DCF

Builds the degree cumulative function for this labeling. Read more
Source§

fn iter(&self) -> Self::Lender<'_>

Returns an iterator over the labeling. Read more
Source§

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

Applies func to each chunk of nodes of size node_granularity in parallel, and folds the results using fold. Read more
Source§

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

Applies func to each chunk of nodes containing approximately arc_granularity arcs in parallel and folds the results using fold. Read more
Source§

impl<DCF, S> SerInner for CsrGraph<DCF, S>
where DCF: SerInner, S: SerInner,

Source§

const IS_ZERO_COPY: bool

Inner constant used by the derive macros to keep track recursively of whether the type satisfies the conditions for being zero-copy. It is checked at runtime against the trait implemented by the type, and if a ZeroCopy type has this constant set to false serialization will panic.
Source§

type SerType = CsrGraph<<DCF as SerInner>::SerType, <S as SerInner>::SerType>

This is the type that will be written in the header of the file, and thus the type that will be deserialized. In most cases it is Self, but in some cases, as for references to slices, it is customized.
Source§

unsafe fn _ser_inner(&self, backend: &mut impl WriteWithNames) -> Result<()>

Serializes this structure using the given backend. Read more
Source§

impl<DCF, S> TypeHash for CsrGraph<DCF, S>
where DCF: SerInner<SerType: TypeHash>, S: SerInner<SerType: TypeHash>,

Source§

fn type_hash(hasher: &mut impl Hasher)

Accumulates type information in hasher.
Source§

fn type_hash_val(&self, hasher: &mut impl Hasher)

Calls TypeHash::type_hash on a value.
Source§

impl<D, S> SequentialGraph for CsrGraph<D, S>

Auto Trait Implementations§

§

impl<DCF, S> Freeze for CsrGraph<DCF, S>
where DCF: Freeze, S: Freeze,

§

impl<DCF, S> RefUnwindSafe for CsrGraph<DCF, S>

§

impl<DCF, S> Send for CsrGraph<DCF, S>
where DCF: Send, S: Send,

§

impl<DCF, S> Sync for CsrGraph<DCF, S>
where DCF: Sync, S: Sync,

§

impl<DCF, S> Unpin for CsrGraph<DCF, S>
where DCF: Unpin, S: Unpin,

§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CastableFrom<T> for T

Source§

fn cast_from(value: T) -> T

Call Self as W
Source§

impl<T, U> CastableInto<U> for T
where U: CastableFrom<T>,

Source§

fn cast(self) -> U

Call W::cast_from(self)
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DowncastableFrom<T> for T

Source§

fn downcast_from(value: T) -> T

Truncate the current UnsignedInt to a possibly smaller size
Source§

impl<T, U> DowncastableInto<U> for T
where U: DowncastableFrom<T>,

Source§

fn downcast(self) -> U

Call W::downcast_from(self)
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Splat<T> for T

Source§

fn splat(value: T) -> T

Source§

impl<T> To<T> for T

Source§

fn to(self) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UpcastableFrom<T> for T

Source§

fn upcast_from(value: T) -> T

Extend the current UnsignedInt to a possibly bigger size.
Source§

impl<T, U> UpcastableInto<U> for T
where U: UpcastableFrom<T>,

Source§

fn upcast(self) -> U

Call W::upcast_from(self)
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V