pub struct CsrGraph { /* private fields */ }Expand description
Bidirectional graph with CSR (outgoing) and CSC (incoming) plus a delta log.
Implementations§
Source§impl CsrGraph
impl CsrGraph
Sourcepub fn remove_node(&mut self, id: MemoryId)
pub fn remove_node(&mut self, id: MemoryId)
Remove a node and all its edges.
Sourcepub fn add_edge(&mut self, edge: &MemoryEdge)
pub fn add_edge(&mut self, edge: &MemoryEdge)
Add an edge to the delta log.
Deduplicates: if a currently-valid edge with the same source, target, and type already exists (in CSR or the delta log), the graph is left unchanged. Write inference and pipeline passes may infer the same relationship more than once; parallel duplicates carry no information.
Sourcepub fn strengthen_edge(
&mut self,
source: MemoryId,
target: MemoryId,
delta: f32,
)
pub fn strengthen_edge( &mut self, source: MemoryId, target: MemoryId, delta: f32, )
Strengthen an edge by incrementing its weight (Hebbian learning).
Updates the existing edge rather than appending a parallel duplicate: a delta edge is bumped in place; a compressed (CSR) edge is marked removed and replaced with a delta override, so compaction keeps exactly one copy.
Sourcepub fn remove_edge(&mut self, source: MemoryId, target: MemoryId)
pub fn remove_edge(&mut self, source: MemoryId, target: MemoryId)
Mark an edge for removal.
Sourcepub fn outgoing(&self, id: MemoryId) -> Vec<(MemoryId, StoredEdge)>
pub fn outgoing(&self, id: MemoryId) -> Vec<(MemoryId, StoredEdge)>
Get all outgoing edges from a node (CSR + delta, minus removed).
Sourcepub fn outgoing_valid_at(
&self,
id: MemoryId,
at: Timestamp,
) -> Vec<(MemoryId, StoredEdge)>
pub fn outgoing_valid_at( &self, id: MemoryId, at: Timestamp, ) -> Vec<(MemoryId, StoredEdge)>
Get outgoing edges that are temporally valid at the given timestamp.
Sourcepub fn incoming(&self, id: MemoryId) -> Vec<(MemoryId, StoredEdge)>
pub fn incoming(&self, id: MemoryId) -> Vec<(MemoryId, StoredEdge)>
Get all incoming edges to a node (CSC + delta, minus removed).
Sourcepub fn incoming_valid_at(
&self,
id: MemoryId,
at: Timestamp,
) -> Vec<(MemoryId, StoredEdge)>
pub fn incoming_valid_at( &self, id: MemoryId, at: Timestamp, ) -> Vec<(MemoryId, StoredEdge)>
Get incoming edges that are temporally valid at the given timestamp.
Sourcepub fn contains_node(&self, id: MemoryId) -> bool
pub fn contains_node(&self, id: MemoryId) -> bool
Check if a node exists in the graph.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Number of registered nodes.
Sourcepub fn compact(&mut self)
pub fn compact(&mut self)
Merge all delta edges and removals into the compressed CSR/CSC storage.
Sourcepub fn save(&self, path: &Path) -> MenteResult<()>
pub fn save(&self, path: &Path) -> MenteResult<()>
Save the graph snapshot to a file.
Sourcepub fn load(path: &Path) -> MenteResult<Self>
pub fn load(path: &Path) -> MenteResult<Self>
Load the graph from a file.