pub struct Entities<IndexT, DataT> { /* private fields */ }
Expand description
This is a lazily memory-compact version of SparseEntities
.
Use cases are the same but there are different tradeoffs.
§Tradeoff vs SparseEntities
.
- this struct uses a hash-based virtual table to translate issued ids into an id used internally by its backing collection
Tec
. So accessing items should be similar – it’s dictated by HashMap’s access complexity, since once it finds the internal id, a random access follows. - removing items is O(
Tec::remove()
) = O(n lg n) though I have plans to make it O(n). An added benefits is [remove()
] will also try to compact the memory by removing dead slots fromTec
when there’s a majority of dead slots – it’s another O(n) pass.
Implementations§
Source§impl<IndexT, DataT> Entities<IndexT, DataT>
impl<IndexT, DataT> Entities<IndexT, DataT>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Reserves spaces similar to Vec::with_capacity()
.
Sourcepub fn get_mut(&mut self, index: IndexT) -> Option<&mut DataT>
pub fn get_mut(&mut self, index: IndexT) -> Option<&mut DataT>
Mutable version of get.
Sourcepub fn alloc(&mut self, data: DataT) -> IndexT
pub fn alloc(&mut self, data: DataT) -> IndexT
Allocate an entity with monotonically increase ids, just like crate::SparseEntities
.
Sourcepub fn iter_mut(&mut self) -> impl Iterator<Item = &mut DataT>
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut DataT>
Return all data in mutable references.
Sourcepub fn iter_with_id(&self) -> impl Iterator<Item = (IndexT, &DataT)>
pub fn iter_with_id(&self) -> impl Iterator<Item = (IndexT, &DataT)>
Iterate every entries. This takes O(HashMap::iter()
) to iterate the entire collection.
Trait Implementations§
Auto Trait Implementations§
impl<IndexT, DataT> Freeze for Entities<IndexT, DataT>where
IndexT: Freeze,
impl<IndexT, DataT> RefUnwindSafe for Entities<IndexT, DataT>where
IndexT: RefUnwindSafe,
DataT: RefUnwindSafe,
impl<IndexT, DataT> Send for Entities<IndexT, DataT>
impl<IndexT, DataT> Sync for Entities<IndexT, DataT>
impl<IndexT, DataT> Unpin for Entities<IndexT, DataT>
impl<IndexT, DataT> UnwindSafe for Entities<IndexT, DataT>where
IndexT: UnwindSafe,
DataT: UnwindSafe,
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
Mutably borrows from an owned value. Read more