Struct naga::arena::unique_arena::UniqueArena
source · pub struct UniqueArena<T> {
set: FastIndexSet<T>,
span_info: Vec<Span>,
}
Expand description
An arena whose elements are guaranteed to be unique.
A UniqueArena
holds a set of unique values of type T
, each with an
associated Span
. Inserting a value returns a Handle<T>
, which can be
used to index the UniqueArena
and obtain shared access to the T
element.
Access via a Handle
is an array lookup - no hash lookup is necessary.
The element type must implement Eq
and Hash
. Insertions of equivalent
elements, according to Eq
, all return the same Handle
.
Once inserted, elements may not be mutated.
UniqueArena
is similar to Arena
: If Arena
is vector-like,
UniqueArena
is HashSet
-like.
Fields§
§set: FastIndexSet<T>
§span_info: Vec<Span>
Spans for the elements, indexed by handle.
The length of this vector is always equal to set.len()
. FastIndexSet
promises that its elements “are indexed in a compact range, without
holes in the range 0..set.len()”, so we can always use the indices
returned by insertion as indices into this vector.
Implementations§
source§impl<T> UniqueArena<T>
impl<T> UniqueArena<T>
source§impl<T: Eq + Hash> UniqueArena<T>
impl<T: Eq + Hash> UniqueArena<T>
sourcepub fn iter(&self) -> impl DoubleEndedIterator<Item = (Handle<T>, &T)>
pub fn iter(&self) -> impl DoubleEndedIterator<Item = (Handle<T>, &T)>
Returns an iterator over the items stored in this arena, returning both the item’s handle and a reference to it.
sourcepub fn insert(&mut self, value: T, span: Span) -> Handle<T>
pub fn insert(&mut self, value: T, span: Span) -> Handle<T>
Insert a new value into the arena.
Return a Handle<T>
, which can be used to index this arena to get a
shared reference to the element.
If this arena already contains an element that is Eq
to value
,
return a Handle
to the existing element, and drop value
.
If value
is inserted into the arena, associate span
with
it. An element’s span can be retrieved with the get_span
method.
sourcepub fn replace(&mut self, old: Handle<T>, new: T)
pub fn replace(&mut self, old: Handle<T>, new: T)
Replace an old value with a new value.
§Panics
- if the old value is not in the arena
- if the new value already exists in the arena
sourcepub fn get(&self, value: &T) -> Option<Handle<T>>
pub fn get(&self, value: &T) -> Option<Handle<T>>
Return this arena’s handle for value
, if present.
If this arena already contains an element equal to value
,
return its handle. Otherwise, return None
.
Trait Implementations§
source§impl<T: Clone> Clone for UniqueArena<T>
impl<T: Clone> Clone for UniqueArena<T>
source§fn clone(&self) -> UniqueArena<T>
fn clone(&self) -> UniqueArena<T>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more