pub struct CallGraph {
pub total_callee_names: usize,
pub resolved_callee_names: usize,
/* private fields */
}Expand description
Call graph for a codebase.
Uses an index-based representation: node strings are interned into a Vec<String>
and all adjacency, BFS, and PageRank structures operate on u32 indices.
This avoids per-BFS-call HashMap<String, …> allocations that otherwise grow
unbounded under approximate betweenness (k=256 calls × ~400 MB/call).
Fields§
§total_callee_names: usizeTotal callee names found in ASTs across all functions
resolved_callee_names: usizeCallee names that resolved to a known internal function ID
Implementations§
Source§impl CallGraph
impl CallGraph
Sourcepub fn intern(&mut self, id: String) -> u32
pub fn intern(&mut self, id: String) -> u32
Intern a node string, returning its u32 index (allocated if new).
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Number of nodes in the graph.
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Total number of directed edges in the graph.
Sourcepub fn callees_of<'a>(
&'a self,
id: &str,
) -> Option<impl Iterator<Item = &'a str>>
pub fn callees_of<'a>( &'a self, id: &str, ) -> Option<impl Iterator<Item = &'a str>>
Returns an iterator over callee IDs for the given function, or None if not found.
Sourcepub fn add_adj(&mut self, caller_idx: u32, callee_idx: u32)
pub fn add_adj(&mut self, caller_idx: u32, callee_idx: u32)
Add a directed edge from caller_idx to callee_idx (index-based, no interning).
Both indices must already be interned. Used by lib.rs during fast graph construction
to avoid redundant string lookups after intern has already been called.
Sourcepub fn all_ids(&self) -> impl Iterator<Item = &str>
pub fn all_ids(&self) -> impl Iterator<Item = &str>
Iterate over all interned function IDs in the graph.
Sourcepub fn add_node(&mut self, function_id: String)
pub fn add_node(&mut self, function_id: String)
Add a function to the graph (interning its ID).
Sourcepub fn add_edge(&mut self, caller: String, callee: String)
pub fn add_edge(&mut self, caller: String, callee: String)
Add a call edge (caller -> callee), interning both nodes.
Sourcepub fn fan_in(&self, function_id: &str) -> usize
pub fn fan_in(&self, function_id: &str) -> usize
Calculate fan-in for a function (number of callers).
Sourcepub fn fan_out(&self, function_id: &str) -> usize
pub fn fan_out(&self, function_id: &str) -> usize
Calculate fan-out for a function (number of callees).
Sourcepub fn pagerank(
&self,
damping: f64,
max_iterations: usize,
epsilon: f64,
) -> HashMap<String, f64>
pub fn pagerank( &self, damping: f64, max_iterations: usize, epsilon: f64, ) -> HashMap<String, f64>
Calculate PageRank for all functions.
Uses Vec
§Arguments
damping- Damping factor (typically 0.85)max_iterations- Upper bound on iterations (typically 20-50)epsilon- Convergence threshold; stop early when max delta < epsilon (e.g. 1e-6)
Sourcepub fn betweenness_centrality_approx(&self, k: usize) -> HashMap<String, f64>
pub fn betweenness_centrality_approx(&self, k: usize) -> HashMap<String, f64>
Calculate betweenness centrality using pivoted source sampling (approximate).
Uses systematic k-source sampling: selects k sources evenly spaced through the sorted node list and scales contributions by N/k. This gives an unbiased estimator of exact betweenness with O(k × (N+E)) complexity instead of O(N × (N+E)).
Falls back to exact computation when self.node_count() <= k.
BFS working buffers (stack, pred, sigma, dist, delta) are pre-allocated once and
reused across all k iterations via .clear() / .fill() — RSS is flat regardless
of k.
§Arguments
k- Number of pivot sources to sample (higher = more accurate, more time)
Sourcepub fn betweenness_centrality(&self) -> HashMap<String, f64>
pub fn betweenness_centrality(&self) -> HashMap<String, f64>
Calculate betweenness centrality for all functions (exact).
Uses Brandes’ algorithm: O(N × (N+E)). For large graphs use
betweenness_centrality_approx instead.
BFS working buffers are pre-allocated once and reused across all N iterations.
Sourcepub fn find_strongly_connected_components(
&self,
) -> HashMap<String, (usize, usize)>
pub fn find_strongly_connected_components( &self, ) -> HashMap<String, (usize, usize)>
Find strongly connected components using iterative Tarjan’s algorithm.
Returns a map from function ID to (scc_id, scc_size). Functions in the same SCC form a cyclic dependency group.
Sourcepub fn compute_dependency_depth(&self) -> HashMap<String, Option<usize>>
pub fn compute_dependency_depth(&self) -> HashMap<String, Option<usize>>
Compute dependency depth for all functions.
Returns a map from function ID to depth (0 = entry point, None = unreachable).
Sourcepub fn build_fan_in_map(&self) -> HashMap<String, usize>
pub fn build_fan_in_map(&self) -> HashMap<String, usize>
Build a map from function ID to its fan-in count in O(N + E).
Sourcepub fn is_entry_point(&self, function_id: &str) -> bool
pub fn is_entry_point(&self, function_id: &str) -> bool
Check if a function is likely an entry point.
Sourcepub fn metrics_for(
&self,
function_id: &str,
pagerank_scores: &HashMap<String, f64>,
betweenness_scores: &HashMap<String, f64>,
) -> GraphMetrics
pub fn metrics_for( &self, function_id: &str, pagerank_scores: &HashMap<String, f64>, betweenness_scores: &HashMap<String, f64>, ) -> GraphMetrics
Calculate all graph metrics for a function.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CallGraph
impl RefUnwindSafe for CallGraph
impl Send for CallGraph
impl Sync for CallGraph
impl Unpin for CallGraph
impl UnsafeUnpin for CallGraph
impl UnwindSafe for CallGraph
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more