Skip to main content

Graph

Struct Graph 

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

A property graph.

Implementations§

Source§

impl Graph

Source

pub fn new() -> Graph

An empty graph that indexes both directions.

Source

pub fn out_only() -> Graph

An empty graph that indexes outgoing edges only.

Half the adjacency memory, and Graph::neighbours in Dir::In answers nothing. Graph::remove_node cannot find the edges that point at a node either, so removing a node from one of these leaves the edges into it in place, and it says so by refusing.

Source

pub fn put_node(&mut self, id: u64, props: &[u8]) -> Result<bool>

Stores props under node id, replacing whatever was there, and answers whether the node is new.

§Errors

Whatever Props::put answers: the document is malformed, or a value an index covers cannot be an index key.

Source

pub fn add_node(&mut self, id: u64) -> Result<bool>

Makes sure node id exists, with no properties if it did not.

§Errors

Only if a declared index refuses an empty object, which cannot happen, and is returned rather than swallowed for the same reason every other write here returns.

Source

pub fn node(&self, id: u64) -> Option<Doc<'_>>

Node id’s properties.

Source

pub fn has_node(&self, id: u64) -> bool

Whether the graph has node id.

Source

pub fn nodes(&self) -> usize

How many nodes the graph has.

Source

pub fn edges(&self) -> usize

How many edges the graph has, counting a parallel edge as its own.

Source

pub fn labels(&self) -> &[u32]

Every label with an edge under it, in order.

Adds an edge from src to dst under label, with props behind it, and answers the slot the properties are under.

Both ends are added as nodes if they were not there, because an edge whose endpoints are not nodes is a dangling reference that every later read has to guard against.

§Errors

Code::Full when every edge slot is taken, which is four billion live edges. Otherwise whatever Props::put answers about props.

Removes one edge from src to dst under label, and answers the slot it was under.

With parallel edges it removes one of them and which one is whatever the run’s order left, the same as crate::Adjacency::unlink.

Source

pub fn edge(&self, slot: u32) -> Option<Doc<'_>>

Edge slot’s properties.

Source

pub fn put_edge(&mut self, slot: u32, props: &[u8]) -> Result<()>

Replaces edge slot’s properties.

§Errors

Code::NotFound if no edge is under that slot, so that a caller that held a slot across a removal is told rather than quietly creating properties for an edge that is gone. Otherwise whatever Props::put answers.

Source

pub fn remove_node(&mut self, id: u64) -> Result<bool>

Takes node id out, along with every edge at either end of it.

Answers whether the node was there.

§Errors

Code::Unsupported on a graph built by Graph::out_only when the node has any outgoing edge, because the edges pointing at it cannot be found and removing it would leave them pointing at nothing. A node with no edges at all is removed either way.

Source

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

The neighbours of node under label in dir, in one contiguous run.

Source

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

The edge slots beside those neighbours, in the same order.

Source

pub fn hop( &self, node: u64, label: u32, dir: Dir, ) -> impl Iterator<Item = (u64, u32)>

The neighbours of node under label in dir, each with the slot of the edge that got there.

Source

pub fn degree(&self, node: u64, label: u32, dir: Dir) -> usize

How many edges node has under label in dir.

Source

pub fn prefetch(&self, node: u64, label: u32, dir: Dir)

Warms the run node is about to be walked through.

Source

pub fn index_nodes(&mut self, path: &str, kind: IndexKind) -> Result<()>

Declares an index over a path into node properties, and backfills it.

§Errors

The same as Props::create_index.

Source

pub fn index_edges(&mut self, path: &str, kind: IndexKind) -> Result<()>

Declares an index over a path into edge properties, and backfills it.

§Errors

The same as Props::create_index.

Source

pub fn find_nodes( &self, path: &str, key: &Key, f: impl FnMut(u64, Doc<'_>), ) -> Result<usize>

Calls f for every node whose properties have key under path.

§Errors

The same as Props::find: the path has to be indexed.

Source

pub fn count_nodes(&self, path: &str, key: &Key) -> Result<usize>

How many nodes have key under path, without reading any of them.

§Errors

The same as Graph::find_nodes.

Source

pub fn count_edges(&self, path: &str, key: &Key) -> Result<usize>

How many edges have key under path, without reading any of them.

§Errors

The same as Graph::find_edges.

Source

pub fn find_edges( &self, path: &str, key: &Key, f: impl FnMut(u32, Doc<'_>), ) -> Result<usize>

Calls f for every edge slot whose properties have key under path.

§Errors

The same as Props::find.

Source

pub fn node_props(&self) -> &Props

The node properties, for the document operations that are the document model’s rather than the graph’s.

Source

pub fn edge_props(&self) -> &Props

The edge properties, likewise.

Source

pub fn adjacency(&self) -> &Adjacency

The adjacency plane underneath.

Source

pub fn memory_bytes(&self) -> usize

What the whole graph weighs.

Trait Implementations§

Source§

impl Debug for Graph

Source§

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

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

impl Default for Graph

Source§

fn default() -> Graph

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

Auto Trait Implementations§

§

impl Freeze for Graph

§

impl RefUnwindSafe for Graph

§

impl Send for Graph

§

impl Sync for Graph

§

impl Unpin for Graph

§

impl UnsafeUnpin for Graph

§

impl UnwindSafe for Graph

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.