pub struct BlockIndexMaps { /* private fields */ }Expand description
BlockIndexMaps provides efficient lookup of blocks by various indices.
Best practices for usage:
- block_name_index: Use when you want to find blocks by name (multiple blocks can share the same name)
- unit_index_map: Use when you want all blocks in a specific unit
- block_kind_index: Use when you want all blocks of a specific kind (e.g., all functions)
- block_id_index: Use for O(1) lookup of block metadata by BlockId
Important: The “name” field is optional since Root blocks and some other blocks may not have names.
Rationale for data structure choices:
- DashMap is used for all indexes to allow concurrent access during parallel graph building
- Vec is used for values to handle multiple blocks with the same index (same name/kind/unit)
Implementations§
Source§impl BlockIndexMaps
impl BlockIndexMaps
Sourcepub fn insert_block(
&self,
block_id: BlockId,
block_name: Option<String>,
block_kind: BlockKind,
unit_index: usize,
)
pub fn insert_block( &self, block_id: BlockId, block_name: Option<String>, block_kind: BlockKind, unit_index: usize, )
Register a new block in all indexes
§Arguments
block_id: The unique block identifierblock_name: Optional name of the block (None for unnamed blocks)block_kind: The kind of block (Func, Class, Stmt, etc.)unit_index: The compilation unit index this block belongs to
Sourcepub fn find_by_name(&self, name: &str) -> Vec<(usize, BlockKind, BlockId)>
pub fn find_by_name(&self, name: &str) -> Vec<(usize, BlockKind, BlockId)>
Find all blocks with a given name (may return multiple blocks)
Returns a vector of (unit_index, block_kind, block_id) tuples
Sourcepub fn find_by_unit(
&self,
unit_index: usize,
) -> Vec<(Option<String>, BlockKind, BlockId)>
pub fn find_by_unit( &self, unit_index: usize, ) -> Vec<(Option<String>, BlockKind, BlockId)>
Find all blocks in a specific unit
Returns a vector of (block_name, block_kind, block_id) tuples
Sourcepub fn find_by_kind(
&self,
block_kind: BlockKind,
) -> Vec<(usize, Option<String>, BlockId)>
pub fn find_by_kind( &self, block_kind: BlockKind, ) -> Vec<(usize, Option<String>, BlockId)>
Find all blocks of a specific kind across all units
Returns a vector of (unit_index, block_name, block_id) tuples
Sourcepub fn find_by_kind_and_unit(
&self,
block_kind: BlockKind,
unit_index: usize,
) -> Vec<BlockId>
pub fn find_by_kind_and_unit( &self, block_kind: BlockKind, unit_index: usize, ) -> Vec<BlockId>
Find all blocks of a specific kind in a specific unit
Returns a vector of block_ids
Sourcepub fn get_block_info(
&self,
block_id: BlockId,
) -> Option<(usize, Option<String>, BlockKind)>
pub fn get_block_info( &self, block_id: BlockId, ) -> Option<(usize, Option<String>, BlockKind)>
Look up block metadata by BlockId for O(1) access
Returns (unit_index, block_name, block_kind) if found
Sourcepub fn block_count(&self) -> usize
pub fn block_count(&self) -> usize
Get total number of blocks indexed
Sourcepub fn unique_names_count(&self) -> usize
pub fn unique_names_count(&self) -> usize
Get the number of unique block names
Sourcepub fn contains_block(&self, block_id: BlockId) -> bool
pub fn contains_block(&self, block_id: BlockId) -> bool
Check if a block with the given ID exists
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BlockIndexMaps
impl !RefUnwindSafe for BlockIndexMaps
impl Send for BlockIndexMaps
impl Sync for BlockIndexMaps
impl Unpin for BlockIndexMaps
impl UnwindSafe for BlockIndexMaps
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 more