Struct SparseSet

Source
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§

Source§

impl<S> SparseSet<S>
where S: Default,

Source

pub fn new() -> Self

Creates a new empty SparseSet.

§Examples

let mut cont = SparseSet::<std::hash::RandomState>::new();

Trait Implementations§

Source§

impl<S> AddEntity for SparseSet<S>
where S: BuildHasher + Default + Clone + 'static,

Source§

fn to_value_index(&self, ri: usize) -> Option<usize>

Converts given row index to value index.
Source§

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>)

Inserts a component value of an entity in the entity container. Read more
Source§

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>>

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

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)

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)

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>, )

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)

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)

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)

Finishes removing component values of an entity in the entity container. Read more
Source§

impl<S> BorrowComponent for SparseSet<S>
where S: BuildHasher + Default + Clone + 'static,

Source§

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>

Borrows component column mutably for the given column index. Read more
Source§

unsafe fn get_column(&self, ci: usize) -> Option<NonNull<u8>>

Retrieves component column pointer for the given column index. Read more
Source§

impl<S> ContainEntity for SparseSet<S>
where S: BuildHasher + Default + Clone + 'static,

Source§

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>>

Retrieves an entity for the given component column index and row index from the entity container. Read more
Source§

fn len(&self) -> usize

Returns number of entities in the entity container. Read more
Source§

fn capacity(&self) -> usize

Returns capacity of the entity container. Read more
Source§

fn reserve(&mut self, additional: usize)

May reserve at least additional extra capacity. Read more
Source§

fn shrink_to_fit(&mut self)

May shrink capacity of the entity container as much as possible. Read more
Source§

unsafe fn resize_column( &mut self, ci: usize, new_len: usize, val_ptr: NonNull<u8>, )

Panics Read more
Source§

impl<S: Debug> Debug for SparseSet<S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S> Default for SparseSet<S>
where S: Default,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<S> RegisterComponent for SparseSet<S>
where S: BuildHasher + Default + Clone + 'static,

Source§

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>

Removes the component column from the entity container. Read more
Source§

fn get_column_index(&self, ty: &TypeId) -> Option<usize>

Retrieves column index for the given component type. Read more
Source§

fn get_column_info(&self, ci: usize) -> Option<&TypeInfo>

Retrieves TypeInfo of the component for the given column index. Read more
Source§

fn num_columns(&self) -> usize

Retrieves number of component columns in the entity container. Read more
Source§

fn contains_column(&self, ty: &TypeId) -> bool

Returns true if the entity container contains given component type. 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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.