Skip to main content

GraphBackend

Trait GraphBackend 

Source
pub trait GraphBackend: Send + Sync {
    // Required methods
    fn add_node(&mut self, node: GraphNode) -> Result<(), CodememError>;
    fn get_node(&self, id: &str) -> Result<Option<GraphNode>, CodememError>;
    fn remove_node(&mut self, id: &str) -> Result<bool, CodememError>;
    fn add_edge(&mut self, edge: Edge) -> Result<(), CodememError>;
    fn get_edges(&self, node_id: &str) -> Result<Vec<Edge>, CodememError>;
    fn remove_edge(&mut self, id: &str) -> Result<bool, CodememError>;
    fn bfs(
        &self,
        start_id: &str,
        max_depth: usize,
    ) -> Result<Vec<GraphNode>, CodememError>;
    fn dfs(
        &self,
        start_id: &str,
        max_depth: usize,
    ) -> Result<Vec<GraphNode>, CodememError>;
    fn shortest_path(
        &self,
        from: &str,
        to: &str,
    ) -> Result<Vec<String>, CodememError>;
    fn stats(&self) -> GraphStats;

    // Provided methods
    fn bfs_filtered(
        &self,
        start_id: &str,
        max_depth: usize,
        exclude_kinds: &[NodeKind],
        include_relationships: Option<&[RelationshipType]>,
    ) -> Result<Vec<GraphNode>, CodememError> { ... }
    fn dfs_filtered(
        &self,
        start_id: &str,
        max_depth: usize,
        exclude_kinds: &[NodeKind],
        include_relationships: Option<&[RelationshipType]>,
    ) -> Result<Vec<GraphNode>, CodememError> { ... }
}
Expand description

Graph backend trait for graph operations.

Required Methods§

Source

fn add_node(&mut self, node: GraphNode) -> Result<(), CodememError>

Add a node to the graph.

Source

fn get_node(&self, id: &str) -> Result<Option<GraphNode>, CodememError>

Get a node by ID.

Source

fn remove_node(&mut self, id: &str) -> Result<bool, CodememError>

Remove a node by ID.

Source

fn add_edge(&mut self, edge: Edge) -> Result<(), CodememError>

Add an edge between two nodes.

Source

fn get_edges(&self, node_id: &str) -> Result<Vec<Edge>, CodememError>

Get edges from a node.

Source

fn remove_edge(&mut self, id: &str) -> Result<bool, CodememError>

Remove an edge by ID.

Source

fn bfs( &self, start_id: &str, max_depth: usize, ) -> Result<Vec<GraphNode>, CodememError>

BFS traversal from a start node up to max_depth.

Source

fn dfs( &self, start_id: &str, max_depth: usize, ) -> Result<Vec<GraphNode>, CodememError>

DFS traversal from a start node up to max_depth.

Source

fn shortest_path( &self, from: &str, to: &str, ) -> Result<Vec<String>, CodememError>

Shortest path between two nodes.

Source

fn stats(&self) -> GraphStats

Get graph statistics.

Provided Methods§

Source

fn bfs_filtered( &self, start_id: &str, max_depth: usize, exclude_kinds: &[NodeKind], include_relationships: Option<&[RelationshipType]>, ) -> Result<Vec<GraphNode>, CodememError>

BFS traversal with filtering: exclude certain node kinds and optionally restrict to specific relationship types.

Source

fn dfs_filtered( &self, start_id: &str, max_depth: usize, exclude_kinds: &[NodeKind], include_relationships: Option<&[RelationshipType]>, ) -> Result<Vec<GraphNode>, CodememError>

DFS traversal with filtering: exclude certain node kinds and optionally restrict to specific relationship types.

Implementors§