pub struct CodeGraph { /* private fields */ }Expand description
The core in-memory graph of code units and their relationships.
Units are stored by their sequential ID. Edges are indexed by source ID for efficient forward traversal.
Implementations§
Source§impl CodeGraph
impl CodeGraph
Sourcepub fn new(dimension: usize) -> Self
pub fn new(dimension: usize) -> Self
Create a new empty code graph with the given feature vector dimension.
Sourcepub fn with_default_dimension() -> Self
pub fn with_default_dimension() -> Self
Create with default dimension (256).
Sourcepub fn add_unit(&mut self, unit: CodeUnit) -> u64
pub fn add_unit(&mut self, unit: CodeUnit) -> u64
Add a code unit to the graph, assigning it a sequential ID.
Returns the assigned ID.
Sourcepub fn add_edge(&mut self, edge: Edge) -> AcbResult<()>
pub fn add_edge(&mut self, edge: Edge) -> AcbResult<()>
Add an edge between two code units.
§Errors
AcbError::SelfEdgeif source and target are the same.AcbError::UnitNotFoundif source or target don’t exist.AcbError::TooManyEdgesif the source unit already has too many edges.
Sourcepub fn unit_count(&self) -> usize
pub fn unit_count(&self) -> usize
Returns the number of code units.
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Returns the number of edges.
Sourcepub fn get_unit_mut(&mut self, id: u64) -> Option<&mut CodeUnit>
pub fn get_unit_mut(&mut self, id: u64) -> Option<&mut CodeUnit>
Get a mutable reference to a code unit by ID.
Sourcepub fn edges_from(&self, source_id: u64) -> Vec<&Edge>
pub fn edges_from(&self, source_id: u64) -> Vec<&Edge>
Get all edges originating from the given unit.
Sourcepub fn edges_from_of_type(
&self,
source_id: u64,
edge_type: EdgeType,
) -> Vec<&Edge>
pub fn edges_from_of_type( &self, source_id: u64, edge_type: EdgeType, ) -> Vec<&Edge>
Get edges from a source filtered by edge type.
Sourcepub fn edges_to_of_type(
&self,
target_id: u64,
edge_type: EdgeType,
) -> Vec<&Edge>
pub fn edges_to_of_type( &self, target_id: u64, edge_type: EdgeType, ) -> Vec<&Edge>
Get edges to a target filtered by edge type.
Sourcepub fn find_units_by_name(&self, prefix: &str) -> Vec<&CodeUnit>
pub fn find_units_by_name(&self, prefix: &str) -> Vec<&CodeUnit>
Find units by name (case-insensitive prefix match).
Sourcepub fn find_units_by_exact_name(&self, name: &str) -> Vec<&CodeUnit>
pub fn find_units_by_exact_name(&self, name: &str) -> Vec<&CodeUnit>
Find units by exact name.
Sourcepub fn find_units_by_type(&self, unit_type: CodeUnitType) -> Vec<&CodeUnit>
pub fn find_units_by_type(&self, unit_type: CodeUnitType) -> Vec<&CodeUnit>
Find units by type.
Sourcepub fn find_units_by_language(&self, language: Language) -> Vec<&CodeUnit>
pub fn find_units_by_language(&self, language: Language) -> Vec<&CodeUnit>
Find units by language.
Sourcepub fn find_units_by_path(&self, path: &Path) -> Vec<&CodeUnit>
pub fn find_units_by_path(&self, path: &Path) -> Vec<&CodeUnit>
Find units in a specific file.
Sourcepub fn has_edge(
&self,
source_id: u64,
target_id: u64,
edge_type: EdgeType,
) -> bool
pub fn has_edge( &self, source_id: u64, target_id: u64, edge_type: EdgeType, ) -> bool
Check if an edge between two units of a given type already exists.
Sourcepub fn stats(&self) -> GraphStats
pub fn stats(&self) -> GraphStats
Get summary statistics about the graph.