Struct naga::compact::handle_set_map::HandleMap
source · pub struct HandleMap<T> {
new_index: Vec<Option<NonMaxU32>>,
as_keys: PhantomData<T>,
}
Expand description
A map from old handle indices to new, compressed handle indices.
Fields§
§new_index: Vec<Option<NonMaxU32>>
The indices assigned to handles in the compacted module.
If new_index[i]
is Some(n)
, then n
is the Index
of the
compacted Handle
corresponding to the pre-compacted Handle
whose index is i
.
as_keys: PhantomData<T>
This type is indexed by values of type T
.
Implementations§
source§impl<T: 'static> HandleMap<T>
impl<T: 'static> HandleMap<T>
pub fn from_set(set: HandleSet<T>) -> Self
sourcepub fn try_adjust(&self, old: Handle<T>) -> Option<Handle<T>>
pub fn try_adjust(&self, old: Handle<T>) -> Option<Handle<T>>
Return the counterpart to old
in the compacted module.
If we thought old
wouldn’t be used in the compacted module, return
None
.
sourcepub fn adjust(&self, handle: &mut Handle<T>)
pub fn adjust(&self, handle: &mut Handle<T>)
Return the counterpart to old
in the compacted module.
If we thought old
wouldn’t be used in the compacted module, panic.
sourcepub fn adjust_option(&self, handle: &mut Option<Handle<T>>)
pub fn adjust_option(&self, handle: &mut Option<Handle<T>>)
Like adjust
, but for optional handles.
sourcepub fn adjust_range(&self, range: &mut Range<T>, compacted_arena: &Arena<T>)
pub fn adjust_range(&self, range: &mut Range<T>, compacted_arena: &Arena<T>)
Shrink range
to include only used handles.
Fortunately, compaction doesn’t arbitrarily scramble the expressions in the arena, but instead preserves the order of the elements while squeezing out unused ones. That means that a contiguous range in the pre-compacted arena always maps to a contiguous range in the post-compacted arena. So we just need to adjust the endpoints.
Compaction may have eliminated the endpoints themselves.
Use compacted_arena
to bounds-check the result.