Skip to main content

CsrGraph

Struct CsrGraph 

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

Bidirectional graph with CSR (outgoing) and CSC (incoming) plus a delta log.

Implementations§

Source§

impl CsrGraph

Source

pub fn new() -> Self

Creates a new empty CSR graph.

Source

pub fn add_node(&mut self, id: MemoryId) -> u32

Register a node. Returns its internal index.

Source

pub fn remove_node(&mut self, id: MemoryId)

Remove a node and all its edges.

Source

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.

Source

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.

Source

pub fn remove_edge(&mut self, source: MemoryId, target: MemoryId)

Mark an edge for removal.

Source

pub fn outgoing(&self, id: MemoryId) -> Vec<(MemoryId, StoredEdge)>

Get all outgoing edges from a node (CSR + delta, minus removed).

Source

pub fn outgoing_valid_at( &self, id: MemoryId, at: Timestamp, ) -> Vec<(MemoryId, StoredEdge)>

Get outgoing edges that are temporally valid at the given timestamp.

Source

pub fn incoming(&self, id: MemoryId) -> Vec<(MemoryId, StoredEdge)>

Get all incoming edges to a node (CSC + delta, minus removed).

Source

pub fn incoming_valid_at( &self, id: MemoryId, at: Timestamp, ) -> Vec<(MemoryId, StoredEdge)>

Get incoming edges that are temporally valid at the given timestamp.

Source

pub fn contains_node(&self, id: MemoryId) -> bool

Check if a node exists in the graph.

Source

pub fn node_count(&self) -> usize

Number of registered nodes.

Source

pub fn node_ids(&self) -> &[MemoryId]

All registered node IDs.

Source

pub fn compact(&mut self)

Merge all delta edges and removals into the compressed CSR/CSC storage.

Source

pub fn save(&self, path: &Path) -> MenteResult<()>

Save the graph snapshot to a file.

Source

pub fn load(path: &Path) -> MenteResult<Self>

Load the graph from a file.

Trait Implementations§

Source§

impl Clone for CsrGraph

Source§

fn clone(&self) -> CsrGraph

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 CsrGraph

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for CsrGraph

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for CsrGraph

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for CsrGraph

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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 = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more