Struct wgpu_core::track::metadata::ResourceMetadata
source · pub(super) struct ResourceMetadata<T: Clone> {
owned: BitVec<usize>,
resources: Vec<Option<T>>,
}
Expand description
A set of resources, holding a Arc<T>
and epoch for each member.
Testing for membership is fast, and iterating over members is reasonably fast in practice. Storage consumption is proportional to the largest id index of any member, not to the number of members, but a bit vector tracks occupancy, so iteration touches only occupied elements.
Fields§
§owned: BitVec<usize>
If the resource with index i
is a member, owned[i]
is true
.
resources: Vec<Option<T>>
A vector holding clones of members’ T
s.
Implementations§
source§impl<T: Clone> ResourceMetadata<T>
impl<T: Clone> ResourceMetadata<T>
pub(super) fn new() -> Self
pub(super) fn set_size(&mut self, size: usize)
pub(super) fn clear(&mut self)
sourcepub(super) fn tracker_assert_in_bounds(&self, index: usize)
pub(super) fn tracker_assert_in_bounds(&self, index: usize)
Ensures a given index is in bounds for all arrays and does sanity checks of the presence of a refcount.
In release mode this function is completely empty and is removed.
sourcepub(super) fn is_empty(&self) -> bool
pub(super) fn is_empty(&self) -> bool
Returns true if the tracker owns no resources.
This is a O(n) operation.
sourcepub(super) fn contains(&self, index: usize) -> bool
pub(super) fn contains(&self, index: usize) -> bool
Returns true if the set contains the resource with the given index.
sourcepub(super) unsafe fn contains_unchecked(&self, index: usize) -> bool
pub(super) unsafe fn contains_unchecked(&self, index: usize) -> bool
Returns true if the set contains the resource with the given index.
§Safety
The given index
must be in bounds for this ResourceMetadata
’s
existing tables. See tracker_assert_in_bounds
.
sourcepub(super) unsafe fn insert(&mut self, index: usize, resource: T) -> &T
pub(super) unsafe fn insert(&mut self, index: usize, resource: T) -> &T
Insert a resource into the set.
Add the resource with the given index, epoch, and reference count to the set.
Returns a reference to the newly inserted resource. (This allows avoiding a clone/reference count increase in many cases.)
§Safety
The given index
must be in bounds for this ResourceMetadata
’s
existing tables. See tracker_assert_in_bounds
.
sourcepub(super) unsafe fn get_resource_unchecked(&self, index: usize) -> &T
pub(super) unsafe fn get_resource_unchecked(&self, index: usize) -> &T
Get the resource with the given index.
§Safety
The given index
must be in bounds for this ResourceMetadata
’s
existing tables. See tracker_assert_in_bounds
.
sourcepub(super) fn owned_resources(&self) -> impl Iterator<Item = T> + '_
pub(super) fn owned_resources(&self) -> impl Iterator<Item = T> + '_
Returns an iterator over the resources owned by self
.
sourcepub(super) fn owned_indices(&self) -> impl Iterator<Item = usize> + '_
pub(super) fn owned_indices(&self) -> impl Iterator<Item = usize> + '_
Returns an iterator over the indices of all resources owned by self
.