Skip to main content

ArborGraph

Struct ArborGraph 

Source
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

Source

pub fn new() -> Self

Creates a new empty graph.

Source

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.

Source

pub fn rebuild_search_index(&mut self)

Rebuilds the search index from existing graph nodes. Call after deserialization since search_index is not serialized.

Source

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.

Source

pub fn add_edge(&mut self, from: NodeId, to: NodeId, edge: Edge)

Adds an edge between two nodes.

Source

pub fn get_by_id(&self, id: &str) -> Option<&CodeNode>

Gets a node by its string ID.

Source

pub fn get(&self, index: NodeId) -> Option<&CodeNode>

Gets a node by its graph index.

Source

pub fn find_by_name(&self, name: &str) -> Vec<&CodeNode>

Finds all nodes with a given name.

Source

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.

Source

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.

Source

pub fn find_by_file(&self, file: &str) -> Vec<&CodeNode>

Finds all nodes in a file.

Source

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.

Source

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());
}
Source

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.

Source

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.

Source

pub fn get_callees(&self, index: NodeId) -> Vec<&CodeNode>

Gets nodes that this node calls.

Source

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).

Source

pub fn remove_file(&mut self, file: &str)

Removes all nodes from a file. Used for incremental updates.

Source

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.

Source

pub fn centrality_raw(&self, index: NodeId) -> f64

Raw PageRank mass for a node. Sums to ~1.0 across the graph.

Source

pub fn edge_weights(&self) -> impl Iterator<Item = &Edge>

Iterates every edge weight, for density and confidence reporting.

Source

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.

Source

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.

Source

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.

Source

pub fn set_centrality_scores(&mut self, scores: CentralityScores)

Stores both the raw and percentile forms from a computation.

Source

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.

Source

pub fn node_count(&self) -> usize

Returns the number of nodes.

Source

pub fn edge_count(&self) -> usize

Returns the number of edges.

Source

pub fn nodes(&self) -> impl Iterator<Item = &CodeNode>

Iterates over all nodes.

Source

pub fn edges(&self) -> impl Iterator<Item = &Edge>

Iterates over all edges.

Source

pub fn export_edges(&self) -> Vec<GraphEdge>

Returns all edges with source and target IDs for export.

Source

pub fn node_indexes(&self) -> impl Iterator<Item = NodeId> + '_

Iterates over all node indexes.

Source

pub fn find_path(&self, from: NodeId, to: NodeId) -> Option<Vec<&CodeNode>>

Finds the shortest path between two nodes.

Source

pub fn get_index(&self, id: &str) -> Option<NodeId>

Gets the node index for a string ID.

Source

pub fn list_entry_points(&self) -> Vec<&CodeNode>

Returns all nodes detected as production entry points.

Source

pub fn nodes_in_file_with_edges( &self, file: &str, ) -> (Vec<&CodeNode>, Vec<(String, String, String)>)

Returns all nodes in a file and the call edges between them. Edges returned as (caller_name, callee_name, edge_kind_debug_str) triples.

Source§

impl ArborGraph

Source

pub fn stats(&self) -> GraphStats

Returns graph statistics.

Source§

impl ArborGraph

Source

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 analyze
  • max_depth - Maximum hop distance to traverse (0 = unlimited)
§Returns

Complete impact analysis with affected nodes sorted by severity.

Source§

impl ArborGraph

Source

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:

  1. Target node itself
  2. Direct upstream (callers) at depth 1
  3. Direct downstream (callees) at depth 1
  4. Continues outward until budget or max_depth reached

Pinned nodes are always included regardless of budget.

§Arguments
  • target - The node to center the slice around
  • max_tokens - Maximum token budget (0 = unlimited)
  • max_depth - Maximum hop distance (0 = unlimited, default: 2)
  • pinned - Nodes that must be included regardless of budget

Trait Implementations§

Source§

impl Debug for ArborGraph

Source§

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

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

impl Default for ArborGraph

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for ArborGraph

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 ArborGraph

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> 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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