pub struct Graph { /* private fields */ }Expand description
A property graph.
Implementations§
Source§impl Graph
impl Graph
Sourcepub fn out_only() -> Graph
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.
Sourcepub fn put_node(&mut self, id: u64, props: &[u8]) -> Result<bool>
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.
Sourcepub fn add_node(&mut self, id: u64) -> Result<bool>
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.
Sourcepub fn edges(&self) -> usize
pub fn edges(&self) -> usize
How many edges the graph has, counting a parallel edge as its own.
Sourcepub fn link(
&mut self,
src: u64,
dst: u64,
label: u32,
props: &[u8],
) -> Result<u32>
pub fn link( &mut self, src: u64, dst: u64, label: u32, props: &[u8], ) -> Result<u32>
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.
Sourcepub fn unlink(&mut self, src: u64, dst: u64, label: u32) -> Option<u32>
pub fn unlink(&mut self, src: u64, dst: u64, label: u32) -> Option<u32>
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.
Sourcepub fn put_edge(&mut self, slot: u32, props: &[u8]) -> Result<()>
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.
Sourcepub fn remove_node(&mut self, id: u64) -> Result<bool>
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.
Sourcepub fn neighbours(&self, node: u64, label: u32, dir: Dir) -> &[u64]
pub fn neighbours(&self, node: u64, label: u32, dir: Dir) -> &[u64]
The neighbours of node under label in dir, in one contiguous run.
Sourcepub fn edge_slots(&self, node: u64, label: u32, dir: Dir) -> &[u32]
pub fn edge_slots(&self, node: u64, label: u32, dir: Dir) -> &[u32]
The edge slots beside those neighbours, in the same order.
Sourcepub fn hop(
&self,
node: u64,
label: u32,
dir: Dir,
) -> impl Iterator<Item = (u64, u32)>
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.
Sourcepub fn degree(&self, node: u64, label: u32, dir: Dir) -> usize
pub fn degree(&self, node: u64, label: u32, dir: Dir) -> usize
How many edges node has under label in dir.
Sourcepub fn prefetch(&self, node: u64, label: u32, dir: Dir)
pub fn prefetch(&self, node: u64, label: u32, dir: Dir)
Warms the run node is about to be walked through.
Sourcepub fn index_nodes(&mut self, path: &str, kind: IndexKind) -> Result<()>
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.
Sourcepub fn index_edges(&mut self, path: &str, kind: IndexKind) -> Result<()>
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.
Sourcepub fn find_nodes(
&self,
path: &str,
key: &Key,
f: impl FnMut(u64, Doc<'_>),
) -> Result<usize>
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.
Sourcepub fn count_nodes(&self, path: &str, key: &Key) -> Result<usize>
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.
Sourcepub fn count_edges(&self, path: &str, key: &Key) -> Result<usize>
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.
Sourcepub fn find_edges(
&self,
path: &str,
key: &Key,
f: impl FnMut(u32, Doc<'_>),
) -> Result<usize>
pub fn find_edges( &self, path: &str, key: &Key, f: impl FnMut(u32, Doc<'_>), ) -> Result<usize>
Sourcepub fn node_props(&self) -> &Props
pub fn node_props(&self) -> &Props
The node properties, for the document operations that are the document model’s rather than the graph’s.
Sourcepub fn edge_props(&self) -> &Props
pub fn edge_props(&self) -> &Props
The edge properties, likewise.
Sourcepub fn memory_bytes(&self) -> usize
pub fn memory_bytes(&self) -> usize
What the whole graph weighs.