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

Source

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

Gets nodes that call the given node.

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

Gets the centrality score for a node.

Source

pub fn set_centrality(&mut self, scores: HashMap<NodeId, f64>)

Sets centrality scores (called after computation).

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§

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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,