Skip to main content

Snapshot

Struct Snapshot 

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

A graph as dense arrays: ids renumbered from zero, one CSR per direction.

Implementations§

Source§

impl Snapshot

Source

pub fn of(g: &Graph) -> Snapshot

Every node and every edge of g, under every label.

Source

pub fn labelled(g: &Graph, labels: &[u32]) -> Snapshot

Every node of g, and the edges under the labels named.

Every node, including the ones that have no edge under any of these labels, because an algorithm’s answer is a vector indexed by node and a node that was left out of the numbering would shift every answer after it. An isolated node is an empty run and costs two offsets.

Source

pub fn weighted( g: &Graph, labels: &[u32], field: &[u8], missing: u32, ) -> (Snapshot, Vec<u32>)

The same projection, and a weight for every outgoing edge in it.

The weight is read off the edge’s own document, out of the field named, which is where a weight lives in this engine: an edge is a document and a weight is one of its fields. The weights come back in the order the outgoing runs are in, so the weight of the edge out(node)[i] is weights[out_at(node) + i], and a shortest path only has to index the two arrays together.

An edge whose document has no such field, or has one that is not a number, or has a negative one, gets missing. A negative weight is refused rather than clamped because every shortest path algorithm worth having needs weights that do not go backwards, and quietly turning a minus five into a zero is a worse answer than using the default the caller chose.

A float is rounded to the nearest whole number, and anything above four billion is held at four billion, because a weight is u32 so that an edge costs four bytes rather than eight.

Source

pub fn nodes(&self) -> u32

How many nodes there are, which is the length of every answer.

Source

pub fn edges(&self) -> u64

How many edges were projected, counting a parallel edge as its own.

Source

pub fn is_empty(&self) -> bool

Whether there is nothing here.

Source

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

The graph’s own id for a dense one.

§Panics

If node is not a node of this snapshot, which is a bug in the caller: every dense id an algorithm can be holding came out of 0..nodes().

Source

pub fn dense(&self, id: u64) -> Option<u32>

The dense id for one of the graph’s, or None if it has no such node.

Source

pub fn out(&self, node: u32) -> &[u32]

Node node’s outgoing neighbours.

Source

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

Where node node’s outgoing run starts in the flat array.

Only useful next to something that was built alongside that array, which in practice means the weights out of Snapshot::weighted: the weight of out(node)[i] is weights[out_at(node) + i].

Source

pub fn into_(&self, node: u32) -> &[u32]

Node node’s incoming neighbours.

The trailing underscore is because in is a keyword, and the name is still in because that is the word for what it is.

Source

pub fn neighbours(&self, node: u32, dir: Dir) -> &[u32]

Neighbours in whichever direction, for an algorithm that takes one.

Source

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

How many edges leave node.

Source

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

How many edges arrive at node.

Source

pub fn prefetch(&self, node: u32)

Ask the cache for a node’s outgoing run, before the loop that reads it.

The same call crate::Adjacency::prefetch is for and much cheaper to serve, because a dense run is one load of the offset and then a contiguous read rather than a hash and a probe.

Source

pub fn memory_bytes(&self) -> usize

Resident bytes.

Trait Implementations§

Source§

impl Clone for Snapshot

Source§

fn clone(&self) -> Snapshot

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Snapshot

Source§

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

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

impl Default for Snapshot

Source§

fn default() -> Snapshot

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

Auto Trait Implementations§

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

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.