Skip to main content

Csr

Struct Csr 

Source
pub struct Csr { /* private fields */ }
Expand description

A read only adjacency, node grouped and bit packed.

Built from an edge list over dense u32 ids, or from the hot form through an id mapping. See the module documentation for the layout and for what it costs.

use yo_graph::Csr;

let mut edges = vec![(0u32, 3u32), (0, 1), (2, 0), (0, 9)];
let cold = Csr::build(10, &mut edges);

assert_eq!(cold.degree(0), 3);
assert_eq!(cold.neighbours(0), vec![1, 3, 9]);
assert_eq!(cold.neighbours(1), Vec::<u32>::new());

Implementations§

Source§

impl Csr

Source

pub fn build(nodes: u32, edges: &mut [(u32, u32)]) -> Csr

Encode an edge list.

The list is sorted in place, which is the only reason it is taken by mutable reference. Every id has to be under nodes. Parallel edges are kept rather than merged, because whether two links between the same pair are one edge or two is the caller’s question and the answer costs a zero gap either way.

Source

pub fn from_hot( hot: &Adjacency, label: u32, dir: Dir, nodes: u32, id: impl Fn(u64) -> u32, ) -> Csr

Encode one label and direction of a hot plane.

id maps the caller’s node ids onto the dense u32 ids the cold form is over. That mapping is the node table’s job and the node table does not exist yet, so for now it is the caller’s, which also means a caller whose ids are already dense can pass a cast and pay nothing.

Source

pub fn nodes(&self) -> u32

How many node ids this was built over, whether or not they have edges.

Source

pub fn edges(&self) -> u64

How many edges are packed in here.

Source

pub fn is_empty(&self) -> bool

Whether there is nothing here.

Source

pub fn degree(&self, node: u32) -> u32

The degree of node, without decoding its run.

Two dependent loads, the offset and then the degree that starts the run, and neither of them touches a gap.

Source

pub fn neighbours_into(&self, node: u32, out: &mut Vec<u32>)

Decode the neighbours of node into out, ascending, replacing whatever was in it.

The buffer is the point: a walk decodes run after run and there is no reason for any of them but the first to allocate.

Source

pub fn neighbours(&self, node: u32) -> Vec<u32>

The neighbours of node, ascending, in a fresh vector.

The convenient one. A traversal should use neighbours_into and keep its buffer.

Source

pub fn prefetch(&self, node: u32)

Ask the cache for the word a node’s offset will be found in.

Same reason as the hot form’s: a frontier is known before any of it is read, and the loads that decode it are dependent, so the only way to make them cheap is to stop them being serial.

Source

pub fn bytes(&self) -> usize

Resident bytes, everything included.

Source

pub fn cost(&self) -> Cost

Where the bits went. See Cost.

Source

pub fn bits_per_edge(&self) -> f64

bytes said the way the target in 11 is written, and zero for a graph with no edges.

Trait Implementations§

Source§

impl Debug for Csr

Source§

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

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

impl Default for Csr

Source§

fn default() -> Csr

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

Auto Trait Implementations§

§

impl Freeze for Csr

§

impl RefUnwindSafe for Csr

§

impl Send for Csr

§

impl Sync for Csr

§

impl Unpin for Csr

§

impl UnsafeUnpin for Csr

§

impl UnwindSafe for Csr

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.