BlockIndexMaps

Struct BlockIndexMaps 

Source
pub struct BlockIndexMaps {
    pub block_name_index: BTreeMap<String, Vec<(usize, BlockKind, BlockId)>>,
    pub unit_index_map: BTreeMap<usize, Vec<(Option<String>, BlockKind, BlockId)>>,
    pub block_kind_index: HashMap<BlockKind, Vec<(usize, Option<String>, BlockId)>>,
    pub block_id_index: HashMap<BlockId, (usize, Option<String>, BlockKind)>,
}
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_index: 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:

  • BTreeMap is used for name and unit indexes for better iteration and range queries
  • HashMap is used for kind index since BlockKind doesn’t implement Ord
  • HashMap is used for block_id_index (direct lookup by BlockId) for O(1) access
  • Vec is used for values to handle multiple blocks with the same index (same name/kind/unit)

Fields§

§block_name_index: BTreeMap<String, Vec<(usize, BlockKind, BlockId)>>

block_name -> Vec<(unit_index, block_kind, block_id)> Multiple blocks can share the same name across units or within the same unit

§unit_index_map: BTreeMap<usize, Vec<(Option<String>, BlockKind, BlockId)>>

unit_index -> Vec<(block_name, block_kind, block_id)> Allows retrieval of all blocks in a specific compilation unit

§block_kind_index: HashMap<BlockKind, Vec<(usize, Option<String>, BlockId)>>

block_kind -> Vec<(unit_index, block_name, block_id)> Allows retrieval of all blocks of a specific kind across all units

§block_id_index: HashMap<BlockId, (usize, Option<String>, BlockKind)>

block_id -> (unit_index, block_name, block_kind) Direct O(1) lookup of block metadata by ID

Implementations§

Source§

impl BlockIndexMaps

Source

pub fn new() -> Self

Create a new empty BlockIndexMaps

Source

pub fn insert_block( &mut 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 identifier
  • block_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
Source

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

Source

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

Source

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

Source

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

Source

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

Source

pub fn block_count(&self) -> usize

Get total number of blocks indexed

Source

pub fn unique_names_count(&self) -> usize

Get the number of unique block names

Source

pub fn contains_block(&self, block_id: BlockId) -> bool

Check if a block with the given ID exists

Source

pub fn clear(&mut self)

Clear all indexes

Trait Implementations§

Source§

impl Clone for BlockIndexMaps

Source§

fn clone(&self) -> BlockIndexMaps

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BlockIndexMaps

Source§

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

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

impl Default for BlockIndexMaps

Source§

fn default() -> BlockIndexMaps

Returns the “default value” for a type. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.