pub struct ArborGraph { /* private fields */ }Expand description
The code relationship graph.
This is the heart of Arbor. It stores all code entities as nodes and their relationships as edges, with indexes for fast access.
Implementations§
Source§impl ArborGraph
impl ArborGraph
Sourcepub fn add_node(&mut self, node: CodeNode) -> NodeId
pub fn add_node(&mut self, node: CodeNode) -> NodeId
Adds a code node to the graph.
Returns the node’s index for adding edges later.
Sourcepub fn add_edge(&mut self, from: NodeId, to: NodeId, edge: Edge)
pub fn add_edge(&mut self, from: NodeId, to: NodeId, edge: Edge)
Adds an edge between two nodes.
Sourcepub fn find_by_name(&self, name: &str) -> Vec<&CodeNode>
pub fn find_by_name(&self, name: &str) -> Vec<&CodeNode>
Finds all nodes with a given name.
Sourcepub fn find_by_file(&self, file: &str) -> Vec<&CodeNode>
pub fn find_by_file(&self, file: &str) -> Vec<&CodeNode>
Finds all nodes in a file.
Sourcepub fn search(&self, query: &str) -> Vec<&CodeNode>
pub fn search(&self, query: &str) -> Vec<&CodeNode>
Searches for nodes whose name contains the query.
Uses the search index for fast O(k) lookups where k is the number of matches, instead of O(n) linear scan over all nodes.
Sourcepub fn get_callers(&self, index: NodeId) -> Vec<&CodeNode>
pub fn get_callers(&self, index: NodeId) -> Vec<&CodeNode>
Gets nodes that call the given node.
Sourcepub fn get_callees(&self, index: NodeId) -> Vec<&CodeNode>
pub fn get_callees(&self, index: NodeId) -> Vec<&CodeNode>
Gets nodes that this node calls.
Sourcepub fn get_dependents(
&self,
index: NodeId,
max_depth: usize,
) -> Vec<(NodeId, usize)>
pub fn get_dependents( &self, index: NodeId, max_depth: usize, ) -> Vec<(NodeId, usize)>
Gets all nodes that depend on the given node (directly or transitively).
Sourcepub fn remove_file(&mut self, file: &str)
pub fn remove_file(&mut self, file: &str)
Removes all nodes from a file. Used for incremental updates.
Sourcepub fn centrality(&self, index: NodeId) -> f64
pub fn centrality(&self, index: NodeId) -> f64
Gets the centrality score for a node.
Sourcepub fn set_centrality(&mut self, scores: HashMap<NodeId, f64>)
pub fn set_centrality(&mut self, scores: HashMap<NodeId, f64>)
Sets centrality scores (called after computation).
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Returns the number of nodes.
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Returns the number of edges.
Sourcepub fn export_edges(&self) -> Vec<GraphEdge>
pub fn export_edges(&self) -> Vec<GraphEdge>
Returns all edges with source and target IDs for export.
Sourcepub fn node_indexes(&self) -> impl Iterator<Item = NodeId> + '_
pub fn node_indexes(&self) -> impl Iterator<Item = NodeId> + '_
Iterates over all node indexes.
Source§impl ArborGraph
impl ArborGraph
Source§impl ArborGraph
impl ArborGraph
Sourcepub fn analyze_impact(&self, target: NodeId, max_depth: usize) -> ImpactAnalysis
pub fn analyze_impact(&self, target: NodeId, max_depth: usize) -> ImpactAnalysis
Analyzes the impact of changing a node.
Performs bidirectional BFS from the target:
- Upstream: nodes that depend on target (would break if target changes)
- Downstream: nodes target depends on (may require target updates)
§Arguments
target- The node to analyzemax_depth- Maximum hop distance to traverse (0 = unlimited)
§Returns
Complete impact analysis with affected nodes sorted by severity.
Source§impl ArborGraph
impl ArborGraph
Sourcepub fn slice_context(
&self,
target: NodeId,
max_tokens: usize,
max_depth: usize,
pinned: &[NodeId],
) -> ContextSlice
pub fn slice_context( &self, target: NodeId, max_tokens: usize, max_depth: usize, pinned: &[NodeId], ) -> ContextSlice
Extracts a token-bounded context slice around a target node.
Collects nodes in BFS order:
- Target node itself
- Direct upstream (callers) at depth 1
- Direct downstream (callees) at depth 1
- Continues outward until budget or max_depth reached
Pinned nodes are always included regardless of budget.
§Arguments
target- The node to center the slice aroundmax_tokens- Maximum token budget (0 = unlimited)max_depth- Maximum hop distance (0 = unlimited, default: 2)pinned- Nodes that must be included regardless of budget