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 import_nodes(&self) -> &[CodeNode]
pub fn import_nodes(&self) -> &[CodeNode]
The import nodes of the files this graph was built from. They are not
vertices; GraphBuilder::add_nodes
takes them back when a graph is rebuilt from this one.
Sourcepub fn rebuild_search_index(&mut self)
pub fn rebuild_search_index(&mut self)
Rebuilds the search index from existing graph nodes. Call after deserialization since search_index is not serialized.
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 resolve_symbol_ranked(&self, name: &str) -> Vec<NodeId> ⓘ
pub fn resolve_symbol_ranked(&self, name: &str) -> Vec<NodeId> ⓘ
Resolves a symbol name to candidate nodes, best match first.
Names collide constantly — getPath may be a utility function and a
method on four unrelated classes. Callers that took
find_by_name(..).first() got whichever file happened to be parsed
first and then answered as though it were the only candidate; on a real
codebase that reported a heavily-used function as unreachable dead code.
Ranking is by graph degree, then centrality, then file path — so the pick is meaningful and does not depend on parse order. An exact node-id match short-circuits to a single result.
Sourcepub fn resolve_symbol(&self, name: &str) -> Option<NodeId>
pub fn resolve_symbol(&self, name: &str) -> Option<NodeId>
The single node a user most likely meant by name.
See resolve_symbol_ranked for how ties
are broken.
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 literally contains the query.
Substring matching only: search("login") will not find
get_authenticated. Use search_ranked when the
caller is asking about a concept rather than spelling a name.
Sourcepub fn search_ranked(&self, query: &str) -> Vec<(&CodeNode, SearchHit)>
pub fn search_ranked(&self, query: &str) -> Vec<(&CodeNode, SearchHit)>
Searches names, identifier tokens, related concepts, and documentation.
Returns hits ordered strongest-first, each labelled with how it matched — so a caller can present an exact hit and a concept guess differently instead of blending them into one opaque ranking.
// Finds `get_authenticated`, `verifyJwt`, `hashPassword`, …
for (node, hit) in graph.search_ranked("login") {
println!("{} ({})", node.name, hit.kind.label());
}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.
Call edges only. A subclass does not call its base; that relationship
is an extends edge and is reported by direct_dependents.
Sourcepub fn direct_dependents(&self, index: NodeId) -> Vec<&CodeNode>
pub fn direct_dependents(&self, index: NodeId) -> Vec<&CodeNode>
Nodes that directly reach index by calling it, extending it, or
implementing it.
PageRank still follows EdgeKind::Calls only. Blast radius and the
graded inheritance check need the type edges as well: a base with
subclasses is reached, even though nothing calls the class.
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
Centrality as a percentile rank in [0.0, 1.0].
0.9 means “more central than 90% of the nodes in this repository”,
and carries that meaning in every repository — so a threshold written
against it behaves the same on a god-object monolith and a flat service.
For the underlying PageRank mass see centrality_raw.
Sourcepub fn centrality_raw(&self, index: NodeId) -> f64
pub fn centrality_raw(&self, index: NodeId) -> f64
Raw PageRank mass for a node. Sums to ~1.0 across the graph.
Sourcepub fn edge_weights(&self) -> impl Iterator<Item = &Edge>
pub fn edge_weights(&self) -> impl Iterator<Item = &Edge>
Iterates every edge weight, for density and confidence reporting.
Sourcepub fn confident_edge_count(&self) -> usize
pub fn confident_edge_count(&self) -> usize
Counts edges at or above Edge::CONFIDENT_THRESHOLD.
The gap between this and edge_count is how much of
the graph rests on inference rather than proof — worth surfacing in any
report that claims to describe what a change reaches.
Sourcepub fn set_centrality(&mut self, scores: HashMap<NodeId, f64>)
pub fn set_centrality(&mut self, scores: HashMap<NodeId, f64>)
Sets percentile centrality scores.
Prefer set_centrality_scores, which
also stores the raw scores a warm start needs.
Sourcepub fn has_centrality_scores(&self) -> bool
pub fn has_centrality_scores(&self) -> bool
Whether every node has a stored percentile, including a legitimate 0.0.
A missing computation leaves the map empty. A finished one writes a score
for each node, and the bottom rank is defined to be 0.0, so “any score
is positive” is the wrong test.
Sourcepub fn set_centrality_scores(&mut self, scores: CentralityScores)
pub fn set_centrality_scores(&mut self, scores: CentralityScores)
Stores both the raw and percentile forms from a computation.
Sourcepub fn centrality_map(&self) -> &HashMap<NodeId, f64>
pub fn centrality_map(&self) -> &HashMap<NodeId, f64>
Raw score map, for warm-starting a recompute.
Falls back to the percentile map when raw scores are absent — a graph
deserialized from a cache written before raw scores were stored. The
warm-start rescale in [crate::ranking] tolerates any scalar multiple
of the fixed point, so this degrades convergence speed, not correctness.
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.
Sourcepub fn find_path(&self, from: NodeId, to: NodeId) -> Option<Vec<&CodeNode>>
pub fn find_path(&self, from: NodeId, to: NodeId) -> Option<Vec<&CodeNode>>
Finds the shortest path between two nodes.
Sourcepub fn list_entry_points(&self) -> Vec<&CodeNode>
pub fn list_entry_points(&self) -> Vec<&CodeNode>
Returns all nodes detected as production entry points.
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