Skip to main content

Graph

Struct Graph 

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

A graph.

Cheap to clone and cheap to keep around, the same way crate::Docs is: the handle is a pointer and an index, and every clone is the same graph.

Implementations§

Source§

impl Graph

Source

pub fn name(&self) -> Result<String>

The name this graph was opened under.

§Errors

Code::Invalid if called from inside a callback that is already holding this database.

Source

pub fn add<N: Node>(&self, node: &N) -> Result<Id<N>>

Put a node in, replacing whatever was under its id.

The Id that comes back is this graph’s handle on the node and is the same one every time for the same struct id, so adding a node twice updates it rather than making a second one.

§Errors

Code::ShapeMismatch when another type already uses this label, and Code::Invalid for an id that cannot be a key.

Source

pub fn id_of<N: Node>( &self, id: &<N::Id as Asked>::Ask, ) -> Result<Option<Id<N>>>

This graph’s handle on the node with the id you wrote, if it has one.

The one call that pays the lookup from a struct id to a dense id, which is what the module docs are about.

§Errors

Code::Invalid for an id that cannot be a key.

Source

pub fn get<N: Node>(&self, id: Id<N>) -> Result<Option<N>>

Read a node back.

§Errors

Code::Corrupt if the stored node is not an N, which is a graph that disagrees with its own labels.

Source

pub fn has<N: Node>(&self, id: Id<N>) -> Result<bool>

Whether this graph still has that node.

§Errors

Code::Invalid if called from inside a callback holding this database.

Source

pub fn remove<N: Node>(&self, id: Id<N>) -> Result<bool>

Take a node out, along with every edge at either end of it.

Answers whether the node was there.

§Errors

Code::Corrupt if the stored node is not an N.

Source

pub fn count<N: Node>(&self) -> Result<usize>

How many nodes of this type the graph holds.

§Errors

Code::Invalid if called from inside a callback holding this database.

Source

pub fn nodes(&self) -> Result<usize>

How many nodes of every type the graph holds.

§Errors

Code::Invalid if called from inside a callback holding this database.

Source

pub fn edges(&self) -> Result<usize>

How many edges of every type the graph holds, counting two edges between the same pair as two.

§Errors

Code::Invalid if called from inside a callback holding this database.

Put an edge between two nodes.

Linking the same pair twice leaves two edges, each with its own fields, because that is what a property graph means by a multigraph and because two ratings of the same film on two dates is the case rather than the corner case.

§Errors

Code::NotFound if either end is not in the graph, because an edge hanging off an id that was never added is a dangling reference that every later read would have to guard against.

Take one edge of this kind out from between two nodes.

Answers whether there was one. With two edges between the same pair it takes one of them, and which one is whatever the run’s order left.

§Errors

Code::Invalid if called from inside a callback holding this database.

Source

pub fn edge<E: Edge>(&self, id: EdgeId<E>) -> Result<Option<E>>

Read an edge’s fields.

§Errors

Code::Corrupt if the stored edge is not an E.

Source

pub fn out<E: Edge>(&self, from: Id<E::From>) -> Result<Vec<Id<E::To>>>

Where an edge of this kind goes from this node.

§Errors

Code::Invalid if called from inside a callback holding this database.

Source

pub fn incoming<E: Edge>(&self, to: Id<E::To>) -> Result<Vec<Id<E::From>>>

Where an edge of this kind comes into this node from.

§Errors

Code::Invalid if called from inside a callback holding this database.

Source

pub fn out_edges<E: Edge>(&self, from: Id<E::From>) -> Result<Vec<Hop<E>>>

The same as Graph::out, with the edge that got to each one.

§Errors

Code::Invalid if called from inside a callback holding this database.

Source

pub fn degree<E: Edge>(&self, from: Id<E::From>) -> Result<usize>

How many edges of this kind leave this node.

Read off the run header, so it does not touch the run.

§Errors

Code::Invalid if called from inside a callback holding this database.

Source

pub fn walk<N: Node>(&self, from: Id<N>) -> Walk<'_, N>

Start a walk at a node.

Source

pub fn walk_from<N: Node, V: Asked>( &self, path: impl Into<Path<N, V>>, value: &V::Ask, ) -> Result<Walk<'_, N>>

Start a walk at everything a path index answers.

§Errors

The same as Graph::find.

Source

pub fn find<N: Node, V: Asked>( &self, path: impl Into<Path<N, V>>, value: &V::Ask, ) -> Result<Vec<N>>

Every node of this type with value at path.

§Errors

Code::Invalid if the path is not indexed, and Code::Corrupt if a stored node is not an N.

Source

pub fn count_at<N: Node, V: Asked>( &self, path: impl Into<Path<N, V>>, value: &V::Ask, ) -> Result<usize>

How many nodes of this type have value at path.

§Errors

The same as Graph::find, without the decode.

Source

pub fn memory_bytes(&self) -> Result<usize>

What this graph weighs.

§Errors

Code::Invalid if called from inside a callback holding this database.

Trait Implementations§

Source§

impl Clone for Graph

Source§

fn clone(&self) -> Graph

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 Graph

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Graph

§

impl !Send for Graph

§

impl !Sync for Graph

§

impl !UnwindSafe for Graph

§

impl Freeze for Graph

§

impl Unpin for Graph

§

impl UnsafeUnpin 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> 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.