Set

Struct Set 

Source
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 dense array.
    • 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.
  • 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

Source

pub fn new() -> Self

Constructs a new Set.

Source

pub fn len(&self) -> usize

Returns the number of elements in the set, also referred to as its ‘length’.

Source

pub fn is_empty(&self) -> bool

Returns true if the set contains no elements.

Source

pub fn contains(&self, entity: Entity) -> bool

Returns true if the set contains the entity.

Source

pub fn index_of(&self, entity: Entity) -> Option<usize>

Returns the index that was assigned to the entity.

Source

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.

Source

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.

Source

pub fn reserve(&mut self, additional: usize)

Reserves capacity for at least additional more elements to be inserted into the set.

Source

pub fn iter(&self) -> Iter<'_, Entity>

An iterator visiting all entities in the set.

Trait Implementations§

Source§

impl Default for Set

Source§

fn default() -> Set

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

impl<'a> IntoIterator for &'a Set

Source§

type IntoIter = Copied<Iter<'a, Entity>>

Which kind of iterator are we turning this into?
Source§

type Item = Entity

The type of the elements being iterated over.
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

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