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
impl Graph
Sourcepub fn name(&self) -> Result<String>
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.
Sourcepub fn add<N: Node>(&self, node: &N) -> Result<Id<N>>
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.
Sourcepub fn id_of<N: Node>(
&self,
id: &<N::Id as Asked>::Ask,
) -> Result<Option<Id<N>>>
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.
Sourcepub fn get<N: Node>(&self, id: Id<N>) -> Result<Option<N>>
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.
Sourcepub fn has<N: Node>(&self, id: Id<N>) -> Result<bool>
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.
Sourcepub fn remove<N: Node>(&self, id: Id<N>) -> Result<bool>
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.
Sourcepub fn count<N: Node>(&self) -> Result<usize>
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.
Sourcepub fn nodes(&self) -> Result<usize>
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.
Sourcepub fn edges(&self) -> Result<usize>
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.
Sourcepub fn link<E: Edge>(
&self,
from: Id<E::From>,
to: Id<E::To>,
edge: &E,
) -> Result<EdgeId<E>>
pub fn link<E: Edge>( &self, from: Id<E::From>, to: Id<E::To>, edge: &E, ) -> Result<EdgeId<E>>
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.
Sourcepub fn unlink<E: Edge>(&self, from: Id<E::From>, to: Id<E::To>) -> Result<bool>
pub fn unlink<E: Edge>(&self, from: Id<E::From>, to: Id<E::To>) -> Result<bool>
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.
Sourcepub fn out<E: Edge>(&self, from: Id<E::From>) -> Result<Vec<Id<E::To>>>
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.
Sourcepub fn incoming<E: Edge>(&self, to: Id<E::To>) -> Result<Vec<Id<E::From>>>
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.
Sourcepub fn out_edges<E: Edge>(&self, from: Id<E::From>) -> Result<Vec<Hop<E>>>
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.
Sourcepub fn degree<E: Edge>(&self, from: Id<E::From>) -> Result<usize>
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.
Sourcepub fn walk_from<N: Node, V: Asked>(
&self,
path: impl Into<Path<N, V>>,
value: &V::Ask,
) -> Result<Walk<'_, N>>
pub fn walk_from<N: Node, V: Asked>( &self, path: impl Into<Path<N, V>>, value: &V::Ask, ) -> Result<Walk<'_, N>>
Sourcepub fn find<N: Node, V: Asked>(
&self,
path: impl Into<Path<N, V>>,
value: &V::Ask,
) -> Result<Vec<N>>
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.
Sourcepub fn count_at<N: Node, V: Asked>(
&self,
path: impl Into<Path<N, V>>,
value: &V::Ask,
) -> Result<usize>
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.
Sourcepub fn memory_bytes(&self) -> Result<usize>
pub fn memory_bytes(&self) -> Result<usize>
What this graph weighs.
§Errors
Code::Invalid if called from inside a callback holding this database.