pub struct GraphTable<'txn> { /* private fields */ }Expand description
A table storing graph edges with bidirectional indexes and temporal tracking.
This table maintains two internal tables (forward and reverse) to enable efficient queries for both outgoing and incoming edges. Both tables are updated atomically within the same write transaction.
Value tuple: (is_active, weight, created_at, deleted_at)
Implementations§
Source§impl<'txn> GraphTable<'txn>
impl<'txn> GraphTable<'txn>
Sourcepub fn open(txn: &'txn WriteTransaction, name: &str) -> Result<Self, TableError>
pub fn open(txn: &'txn WriteTransaction, name: &str) -> Result<Self, TableError>
Opens a graph table for writing.
Creates two internal tables: {name}_forward and {name}_reverse.
Sourcepub fn add_edge(
&mut self,
source: &Uuid,
edge_type: &str,
target: &Uuid,
is_active: bool,
weight: f32,
created_at: Option<u64>,
) -> Result<(), TableError>
pub fn add_edge( &mut self, source: &Uuid, edge_type: &str, target: &Uuid, is_active: bool, weight: f32, created_at: Option<u64>, ) -> Result<(), TableError>
Adds an edge to the graph with optional timestamp.
Updates both forward and reverse indexes atomically.
§Arguments
source- Source vertex UUIDedge_type- Edge type (e.g., “follows”, “knows”)target- Target vertex UUIDis_active- Whether the edge is activeweight- Edge weight/scorecreated_at- Optional creation timestamp (uses current time if None)
Sourcepub fn remove_edge(
&mut self,
source: &Uuid,
edge_type: &str,
target: &Uuid,
) -> Result<(), StorageError>
pub fn remove_edge( &mut self, source: &Uuid, edge_type: &str, target: &Uuid, ) -> Result<(), StorageError>
Soft deletes an edge from the graph by setting deleted_at timestamp.
The edge remains in storage for temporal queries but is marked as deleted. Updates both forward and reverse indexes atomically.
Sourcepub fn hard_delete_edge(
&mut self,
source: &Uuid,
edge_type: &str,
target: &Uuid,
) -> Result<(), StorageError>
pub fn hard_delete_edge( &mut self, source: &Uuid, edge_type: &str, target: &Uuid, ) -> Result<(), StorageError>
Hard deletes an edge from the graph, removing it entirely from storage.
This permanently removes the edge and its history. Use remove_edge() for soft delete that preserves temporal history.
Sourcepub fn update_edge(
&mut self,
source: &Uuid,
edge_type: &str,
target: &Uuid,
is_active: bool,
weight: f32,
) -> Result<(), TableError>
pub fn update_edge( &mut self, source: &Uuid, edge_type: &str, target: &Uuid, is_active: bool, weight: f32, ) -> Result<(), TableError>
Updates the properties of an existing edge while preserving timestamps.
Updates both forward and reverse indexes atomically.
Sourcepub fn add_edges_batch(
&mut self,
edges: &[(Uuid, &str, Uuid, bool, f32, u64)],
sorted: bool,
) -> Result<usize, StorageError>
pub fn add_edges_batch( &mut self, edges: &[(Uuid, &str, Uuid, bool, f32, u64)], sorted: bool, ) -> Result<usize, StorageError>
Adds multiple edges to the graph in a single batch operation.
This method leverages Manifold’s bulk insertion API for improved throughput, especially beneficial when loading large graphs. Both forward and reverse indexes are updated atomically within the same transaction.
§Arguments
edges- Vector of edge tuples: (source,edge_type, target,is_active,weight,created_at)sorted- Whether the input is pre-sorted by (source,edge_type, target). Set totrueif your data is already sorted for best performance.
§Returns
Returns the number of edges inserted.
§Performance
- Sorted data (
sorted = true): Uses optimized insertion with minimal tree rebalancing - Unsorted data (
sorted = false): Chunks and sorts data internally for good performance - Batch operations benefit from WAL group commit for higher throughput
§Example
let u1 = Uuid::new_v4();
let u2 = Uuid::new_v4();
let u3 = Uuid::new_v4();
let now = 1234567890;
let edges = vec![
(u1, "follows", u2, true, 1.0, now),
(u1, "follows", u3, true, 0.8, now),
(u2, "follows", u3, true, 0.9, now),
];
let count = graph.add_edges_batch(&edges, false)?;
assert_eq!(count, 3);Sourcepub fn len(&self) -> Result<u64, StorageError>
pub fn len(&self) -> Result<u64, StorageError>
Returns the number of edges in the forward table.
Sourcepub fn is_empty(&self) -> Result<bool, StorageError>
pub fn is_empty(&self) -> Result<bool, StorageError>
Returns true if the table contains no edges.