pub struct FunctionIndex {
pub stats: IndexStats,
/* private fields */
}Expand description
Arena-based function index that stores each function once and uses indices for multiple lookup strategies.
Provides O(1) lookup by name, qualified name, file+name, or class+method. Handles ambiguity when multiple functions share the same name.
§Memory Efficiency
Each FunctionDef is stored exactly once in the functions arena.
All lookup maps use usize indices into this arena, reducing memory
from ~7x duplication (with Arc clones) to 1x + indices.
For a project with 10,000 functions:
- Old: 10,000 FunctionDefs + ~50,000 Arc
clones - New: 10,000 FunctionDefs + ~50,000 usize indices (8 bytes each)
Fields§
§stats: IndexStatsStatistics for debugging
Implementations§
Source§impl FunctionIndex
impl FunctionIndex
Sourcepub fn lookup(&self, name: &str) -> Vec<&FunctionRef>
pub fn lookup(&self, name: &str) -> Vec<&FunctionRef>
Look up all functions with a given simple name.
Returns all functions matching the name, which may be in different
files or classes. Use lookup_qualified or lookup_in_file for
more precise lookups.
§Arguments
name- Simple function name (without module/class prefix)
§Returns
Vec<&FunctionRef>- All matching function references
Sourcepub fn lookup_qualified(&self, qname: &str) -> Option<&FunctionRef>
pub fn lookup_qualified(&self, qname: &str) -> Option<&FunctionRef>
Sourcepub fn lookup_in_file(&self, file: &str, name: &str) -> Option<&FunctionRef>
pub fn lookup_in_file(&self, file: &str, name: &str) -> Option<&FunctionRef>
Sourcepub fn lookup_method(
&self,
class_name: &str,
method_name: &str,
) -> Vec<&FunctionRef>
pub fn lookup_method( &self, class_name: &str, method_name: &str, ) -> Vec<&FunctionRef>
Look up a method in a specific class.
Uses the by_class_method secondary index for O(1) average-case lookup.
Returns all methods matching the class and method name (may exist in
multiple files with the same class name).
§Arguments
class_name- Name of the classmethod_name- Name of the method
§Returns
Vec<&FunctionRef>- All matching method references
§Performance
O(1) average case via HashMap lookup, O(k) where k is the number of methods with the same class/method name in different files.
Sourcepub fn lookup_simple(
&self,
simple_module: &str,
func_name: &str,
) -> Vec<&FunctionRef>
pub fn lookup_simple( &self, simple_module: &str, func_name: &str, ) -> Vec<&FunctionRef>
Look up functions by simple module name and function name.
Enables lookups like “module.func” even when the full qualified name is “pkg.subpkg.module.func”. This matches Python’s indexing strategy where both full and simple module names are indexed.
§Arguments
simple_module- Module basename without extension (e.g., “utils”, “helper”)func_name- Function name
§Returns
Vec<&FunctionRef>- All matching function references
§Performance
O(1) average case via HashMap lookup.
§Example
// For a function defined in pkg/subpkg/utils.py:
index.lookup_simple("utils", "helper_func") // Finds it!Sourcepub fn get_definition(&self, qname: &str) -> Option<&FunctionDef>
pub fn get_definition(&self, qname: &str) -> Option<&FunctionDef>
Sourcepub fn all_functions(&self) -> impl Iterator<Item = &FunctionRef>
pub fn all_functions(&self) -> impl Iterator<Item = &FunctionRef>
Get all functions in the index.
Sourcepub fn statistics(&self) -> &IndexStats
pub fn statistics(&self) -> &IndexStats
Get statistics about the index.
Sourcepub fn iter(&self) -> impl Iterator<Item = &FunctionDef>
pub fn iter(&self) -> impl Iterator<Item = &FunctionDef>
Iterate over all function definitions.
Provides access to full FunctionDef metadata for all indexed functions.
Trait Implementations§
Source§impl Debug for FunctionIndex
impl Debug for FunctionIndex
Source§impl Default for FunctionIndex
impl Default for FunctionIndex
Source§fn default() -> FunctionIndex
fn default() -> FunctionIndex
Auto Trait Implementations§
impl Freeze for FunctionIndex
impl RefUnwindSafe for FunctionIndex
impl Send for FunctionIndex
impl Sync for FunctionIndex
impl Unpin for FunctionIndex
impl UnwindSafe for FunctionIndex
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> 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<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request