pub struct SparseSet<S> { /* private fields */ }Expand description
Two-dimensional storage containing heterogeneous data types based on
AnyVec.
This struct is composed of “Sparse” and “Dense” layers. Sparse layer is
literally sparse, so it can contain vacant slots in it, while dense layer
doesn’t. Dense layer contains real items and the items can be accessed
through the sparse layer. Each dense is identified by its item’s TypeId.
But you are encouraged to access each dense by its index, not TypeId for
the performance.
We call each dense layer a column, and all columns have the same length. So it looks like a 2D matrix as shown below.
Index Sparse Dense Dense
A B
0 0 _____ . .
1 2 _ _ . .
2 x \_/_ . .
3 1 __/
, where '.' is item and 'x' is vacant slot.Implementations§
Trait Implementations§
Source§impl<S> AddEntity for SparseSet<S>
impl<S> AddEntity for SparseSet<S>
Source§fn begin_add_row(&mut self)
fn begin_add_row(&mut self)
Starts inserting component values of an entity to the entity container. Read more
Source§unsafe fn add_value(&mut self, ci: usize, val_ptr: NonNull<u8>)
unsafe fn add_value(&mut self, ci: usize, val_ptr: NonNull<u8>)
Inserts a component value of an entity in the entity container. Read more
Source§unsafe fn end_add_row(&mut self) -> usize
unsafe fn end_add_row(&mut self) -> usize
Finishes inserting component values of an entity in the entity
container then returns row index to the inserted entity. Read more
Source§fn value_ptr_by_value_index(&self, ci: usize, vi: usize) -> Option<NonNull<u8>>
fn value_ptr_by_value_index(&self, ci: usize, vi: usize) -> Option<NonNull<u8>>
Retrieves a pointer to a component value for the given column and value
indices. Read more
Source§fn remove_row(&mut self, ri: usize) -> bool
fn remove_row(&mut self, ri: usize) -> bool
Removes an entity for the given row index from the entity container. Read more
Source§fn remove_row_by_value_index(&mut self, vi: usize)
fn remove_row_by_value_index(&mut self, vi: usize)
Removes an entity for the given value index from the entity container. Read more
Source§unsafe fn begin_remove_row_by_value_index(&mut self, vi: usize)
unsafe fn begin_remove_row_by_value_index(&mut self, vi: usize)
Starts removing component values of an entity from the entity container. Read more
Source§unsafe fn remove_value_by_value_index(
&mut self,
ci: usize,
vi: usize,
buf: NonNull<u8>,
)
unsafe fn remove_value_by_value_index( &mut self, ci: usize, vi: usize, buf: NonNull<u8>, )
Removes a component value of an entity in the entity container then
write it to the given buffer. Read more
Source§unsafe fn drop_value_by_value_index(&mut self, ci: usize, vi: usize)
unsafe fn drop_value_by_value_index(&mut self, ci: usize, vi: usize)
Drops a component value of an entity in the entity container. Read more
Source§unsafe fn forget_value_by_value_index(&mut self, ci: usize, vi: usize)
unsafe fn forget_value_by_value_index(&mut self, ci: usize, vi: usize)
Removes and forgets a component value of an entity in the entity
container. Read more
Source§unsafe fn end_remove_row_by_value_index(&mut self, vi: usize)
unsafe fn end_remove_row_by_value_index(&mut self, vi: usize)
Finishes removing component values of an entity in the entity container. Read more
Source§impl<S> BorrowComponent for SparseSet<S>
impl<S> BorrowComponent for SparseSet<S>
Source§fn borrow_column(&self, ci: usize) -> BorrowResult<RawGetter>
fn borrow_column(&self, ci: usize) -> BorrowResult<RawGetter>
Borrows component column for the given column index. Read more
Source§fn borrow_column_mut(&mut self, ci: usize) -> BorrowResult<RawGetter>
fn borrow_column_mut(&mut self, ci: usize) -> BorrowResult<RawGetter>
Borrows component column mutably for the given column index. Read more
Source§impl<S> ContainEntity for SparseSet<S>
impl<S> ContainEntity for SparseSet<S>
Source§fn create_twin(&self) -> Box<dyn ContainEntity>
fn create_twin(&self) -> Box<dyn ContainEntity>
Creates a new entity container that has the same component types without
component values. Read more
Source§fn get_item_mut(&mut self, ci: usize, ri: usize) -> Option<NonNull<u8>>
fn get_item_mut(&mut self, ci: usize, ri: usize) -> Option<NonNull<u8>>
Retrieves an entity for the given component column index and row index
from the entity container. Read more
Source§fn reserve(&mut self, additional: usize)
fn reserve(&mut self, additional: usize)
May reserve at least
additional extra capacity. Read moreSource§fn shrink_to_fit(&mut self)
fn shrink_to_fit(&mut self)
May shrink capacity of the entity container as much as possible. Read more
Source§impl<S> RegisterComponent for SparseSet<S>
impl<S> RegisterComponent for SparseSet<S>
Source§fn add_column(&mut self, tinfo: TypeInfo) -> Option<usize>
fn add_column(&mut self, tinfo: TypeInfo) -> Option<usize>
Adds a component column to the entity container then returns column
index. Read more
Source§fn remove_column(&mut self, ci: usize) -> Option<TypeInfo>
fn remove_column(&mut self, ci: usize) -> Option<TypeInfo>
Removes the component column from the entity container. Read more
Source§fn get_column_index(&self, ty: &TypeId) -> Option<usize>
fn get_column_index(&self, ty: &TypeId) -> Option<usize>
Retrieves column index for the given component type. Read more
Source§fn num_columns(&self) -> usize
fn num_columns(&self) -> usize
Retrieves number of component columns in the entity container. Read more
Auto Trait Implementations§
impl<S> Freeze for SparseSet<S>where
S: Freeze,
impl<S> RefUnwindSafe for SparseSet<S>where
S: RefUnwindSafe,
impl<S> Send for SparseSet<S>where
S: Send,
impl<S> Sync for SparseSet<S>where
S: Sync,
impl<S> Unpin for SparseSet<S>where
S: Unpin,
impl<S> UnwindSafe for SparseSet<S>where
S: 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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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