FECS
Loading...
Searching...
No Matches
FECS::Container::SparseSet< T > Class Template Reference

SparseSet stores components in a densely packed array while allowing fast indexed lookup via sparse indirection. More...

#include <sparse_set.h>

+ Inheritance diagram for FECS::Container::SparseSet< T >:

Public Member Functions

void Insert (Entity e, const T &component)
 Inserts or overrides a component for an entity,.
 
virtual void Remove (Entity e) override
 Removes the component associated with an entity.
 
bool Has (Entity e) const
 Checks if the entity has a component.
 
T & Get (Entity e)
 Returns a mutable reference to the entity's components.
 
const T & Get (Entity e) const
 Returns a const reference to the entity's components.
 
std::size_t Size () const
 Returns the number of components currently stored.
 
Entity EntityAt (std::uint32_t i) const
 Returns the entity as a specific index in the dense array.
 
void Reserve (std::size_t amount)
 Pre-allocates memory for the given number of components.
 
virtual void SetEntityManager (Manager::EntityManager *m) override
 Assigns the EntityManager used for liveness checks.
 
virtual Manager::EntityManagerGetEntityManager () override
 Returns the EntityManager associated with this pool.
 
virtual void Clear () override
 Clears the sparse and dense storage completely.
 

Detailed Description

template<typename T>
class FECS::Container::SparseSet< T >

SparseSet stores components in a densely packed array while allowing fast indexed lookup via sparse indirection.

Uses paged sparse arrays and dense vectors to provide fast O(1) insertion, removal, and access with minimal memory waste.

Template Parameters
TThe component type stored in the set.

Member Function Documentation

◆ Clear()

template<typename T>
virtual void FECS::Container::SparseSet< T >::Clear ( )
inlineoverridevirtual

Clears the sparse and dense storage completely.

Implements FECS::Container::ISparseSet.

◆ EntityAt()

template<typename T>
Entity FECS::Container::SparseSet< T >::EntityAt ( std::uint32_t i) const
inline

Returns the entity as a specific index in the dense array.

Parameters
iThe index
Returns
The entity ID.

◆ Get() [1/2]

template<typename T>
T & FECS::Container::SparseSet< T >::Get ( Entity e)
inline

Returns a mutable reference to the entity's components.

Parameters
eThe entity.
Returns
Reference to the component

◆ Get() [2/2]

template<typename T>
const T & FECS::Container::SparseSet< T >::Get ( Entity e) const
inline

Returns a const reference to the entity's components.

Parameters
eThe entity.
Returns
Reference to the component

◆ GetEntityManager()

template<typename T>
virtual Manager::EntityManager * FECS::Container::SparseSet< T >::GetEntityManager ( )
inlineoverridevirtual

Returns the EntityManager associated with this pool.

Returns
Pointer to the EntityManager.

Implements FECS::Container::ISparseSet.

◆ Has()

template<typename T>
bool FECS::Container::SparseSet< T >::Has ( Entity e) const
inline

Checks if the entity has a component.

Parameters
eThe entity.
Returns
true if the component exists

◆ Insert()

template<typename T>
void FECS::Container::SparseSet< T >::Insert ( Entity e,
const T & component )
inline

Inserts or overrides a component for an entity,.

Parameters
eThe entity.
componentThe component data

◆ Remove()

template<typename T>
virtual void FECS::Container::SparseSet< T >::Remove ( Entity e)
inlineoverridevirtual

Removes the component associated with an entity.

Parameters
eThe entity whose component to remove.

Implements FECS::Container::ISparseSet.

◆ Reserve()

template<typename T>
void FECS::Container::SparseSet< T >::Reserve ( std::size_t amount)
inline

Pre-allocates memory for the given number of components.

Parameters
amountNumber of component entries to reserve.

◆ SetEntityManager()

template<typename T>
virtual void FECS::Container::SparseSet< T >::SetEntityManager ( Manager::EntityManager * m)
inlineoverridevirtual

Assigns the EntityManager used for liveness checks.

Parameters
mPointer to the EntityManager.

Implements FECS::Container::ISparseSet.

◆ Size()

template<typename T>
std::size_t FECS::Container::SparseSet< T >::Size ( ) const
inline

Returns the number of components currently stored.

Returns
The size of the dense array.

The documentation for this class was generated from the following file: