pub struct Set { /* private fields */ }Expand description
A sparse set of entities, which assigns each
Entity a unique index in a densely packed array.
The time complexity for insert, remove, index_of, and contains is O(1).
The set internally maintains two arrays: sparse and dense.
sparse:- Contains indices to entities in the
densearray. - Entities are used as indices.
- Is sparse, meaning it may have holes.
- Its length is based on the entity with the highest value in the set.
- Contains indices to entities in the
dense:- Contains entities.
- Is densely packed.
- Its length is the number of entities in the set.
This should true for any entity in the set: dense[sparse[entity]] == entity
Implementations§
Source§impl Set
impl Set
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements in the set, also referred to as its ‘length’.
Sourcepub fn index_of(&self, entity: Entity) -> Option<usize>
pub fn index_of(&self, entity: Entity) -> Option<usize>
Returns the index that was assigned to the entity.
Sourcepub fn insert(&mut self, entity: Entity) -> bool
pub fn insert(&mut self, entity: Entity) -> bool
Adds the entity to the set.
Returns true if the entity was inserted into the set, returns false if the entity
was already contained in the set.
Sourcepub fn remove(&mut self, entity: Entity) -> bool
pub fn remove(&mut self, entity: Entity) -> bool
Removes the entity from the set.
Returns true if the entity was removed from the set, returns false if the entity
was not contained in the set.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Set
impl RefUnwindSafe for Set
impl Send for Set
impl Sync for Set
impl Unpin for Set
impl UnwindSafe for Set
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