EnTT: entt::basic_sparse_set< Entity, Allocator > Class Template Reference

EnTT 3.16.0

Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Types | Protected Member Functions | List of all members
entt::basic_sparse_set< Entity, Allocator > Class Template Reference

Sparse set implementation. More...

`#include <sparse_set.hpp>`

Inheritance diagram for entt::basic_sparse_set< Entity, Allocator >:
[legend]

## Public Types
using | allocator_type = Allocator
| Allocator type.
using | entity_type = typename traits_type::value_type
| Underlying entity identifier.
using | version_type = typename traits_type::version_type
| Underlying version type.
using | size_type = std::size_t
| Unsigned integer type.
using | difference_type = std::ptrdiff_t
| Signed integer type.
using | pointer = typename packed_container_type::const_pointer
| Pointer type to contained entities.
using | iterator = basic_iterator
| Random access iterator type.
using | const_iterator = iterator
| Constant random access iterator type.
using | reverse_iterator = std::reverse_iterator<iterator>
| Reverse iterator type.
using | const_reverse_iterator = std::reverse_iterator<const_iterator>
| Constant reverse iterator type.

## Public Member Functions
| basic_sparse_set ()
| Default constructor.
| basic_sparse_set (const allocator_type &allocator)
| Constructs an empty container with a given allocator.
| basic_sparse_set (deletion_policy pol, const allocator_type &allocator={})
| Constructs an empty container with the given policy and allocator.
| basic_sparse_set (const type_info &elem, deletion_policy pol=deletion_policy::swap_and_pop, const allocator_type &allocator={})
| Constructs an empty container with the given value type, policy and allocator.
| basic_sparse_set (const basic_sparse_set &)=delete
| Default copy constructor, deleted on purpose.
| basic_sparse_set (basic_sparse_set &&other) noexcept
| Move constructor.
| basic_sparse_set (basic_sparse_set &&other, const allocator_type &allocator)
| Allocator-extended move constructor.
virtual | ~basic_sparse_set ()
| Default destructor.
basic_sparse_set & | operator= (const basic_sparse_set &)=delete
| Default copy assignment operator, deleted on purpose.
basic_sparse_set & | operator= (basic_sparse_set &&other) noexcept
| Move assignment operator.
void | swap (basic_sparse_set &other) noexcept
| Exchanges the contents with those of a given sparse set.
constexpr allocator_type | get_allocator () const noexcept
| Returns the associated allocator.
deletion_policy | policy () const noexcept
| Returns the deletion policy of a sparse set.
size_type | free_list () const noexcept
| Returns data on the free list whose meaning depends on the mode.
void | free_list (const size_type value) noexcept
| Sets data on the free list whose meaning depends on the mode.
virtual void | reserve (const size_type cap)
| Increases the capacity of a sparse set.
virtual size_type | capacity () const noexcept
| Returns the number of elements that a sparse set has currently allocated space for.
virtual void | shrink_to_fit ()
| Requests the removal of unused capacity.
size_type | extent () const noexcept
| Returns the extent of a sparse set.
size_type | size () const noexcept
| Returns the number of elements in a sparse set.
bool | empty () const noexcept
| Checks whether a sparse set is empty.
bool | contiguous () const noexcept
| Checks whether a sparse set is fully packed.
pointer | data () const noexcept
| Direct access to the internal packed array.
iterator | begin () const noexcept
| Returns an iterator to the beginning.
const_iterator | cbegin () const noexcept
| Returns an iterator to the beginning.
iterator | end () const noexcept
| Returns an iterator to the end.
const_iterator | cend () const noexcept
| Returns an iterator to the end.
reverse_iterator | rbegin () const noexcept
| Returns a reverse iterator to the beginning.
const_reverse_iterator | crbegin () const noexcept
| Returns a reverse iterator to the beginning.
reverse_iterator | rend () const noexcept
| Returns a reverse iterator to the end.
const_reverse_iterator | crend () const noexcept
| Returns a reverse iterator to the end.
const_iterator | find (const entity_type entt) const noexcept
| Finds an entity.
bool | contains (const entity_type entt) const noexcept
| Checks if a sparse set contains an entity.
version_type | current (const entity_type entt) const noexcept
| Returns the contained version for an identifier.
size_type | index (const entity_type entt) const noexcept
| Returns the position of an entity in a sparse set.
entity_type | operator[] (const size_type pos) const noexcept
| Returns the entity at specified location.
const void * | value (const entity_type entt) const noexcept
| Returns the element assigned to an entity, if any.
void * | value (const entity_type entt) noexcept
| Returns the element assigned to an entity, if any.
iterator | push (const entity_type entt, const void *elem=nullptr)
| Assigns an entity to a sparse set.
template<typename It>
iterator | push (It first, It last)
| Assigns one or more entities to a sparse set.
version_type | bump (const entity_type entt)
| Bump the version number of an entity.
void | erase (const entity_type entt)
| Erases an entity from a sparse set.
template<typename It>
void | erase (It first, It last)
| Erases entities from a set.
bool | remove (const entity_type entt)
| Removes an entity from a sparse set if it exists.
template<typename It>
size_type | remove (It first, It last)
| Removes entities from a sparse set if they exist.
void | compact ()
| Removes all tombstones from a sparse set.
void | swap_elements (const entity_type lhs, const entity_type rhs)
| Swaps two entities in a sparse set.
template<typename Compare, typename Sort = std_sort, typename... Args>
void | sort_n (const size_type length, Compare compare, Sort algo=Sort{}, Args &&...args)
| Sort the first count elements according to the given comparison function.
template<typename Compare, typename Sort = std_sort, typename... Args>
void | sort (Compare compare, Sort algo=Sort{}, Args &&...args)
| Sort all elements according to the given comparison function.
template<typename It>
iterator | sort_as (It first, It last)
| Sort entities according to their order in a range.
void | clear ()
| Clears a sparse set.
const type_info & | info () const noexcept
| Returns a type info object for the value type, if any.
const type_info & | type () const noexcept
| Returns a type info object for the value type, if any.
template<typename Type>
void | bind (Type &&value) noexcept
| Forwards variables to derived classes, if any.

## Protected Types
using | basic_iterator = internal::sparse_set_iterator<packed_container_type>
| Random access iterator type.

## Protected Member Functions
void | swap_only (const basic_iterator it)
| Erases an entity from a sparse set.
void | swap_and_pop (const basic_iterator it)
| Erases an entity from a sparse set.
void | in_place_pop (const basic_iterator it)
| Erases an entity from a sparse set.
virtual void | pop (basic_iterator first, basic_iterator last)
| Erases entities from a sparse set.
virtual void | pop_all ()
| Erases all entities of a sparse set.
virtual basic_iterator | try_emplace (const Entity entt, const bool force_back, const void *=nullptr)
| Assigns an entity to a sparse set.
virtual void | bind_any (any) noexcept
| Forwards variables to derived classes, if any.

## Detailed Description

template<typename Entity, typename Allocator>
class entt::basic_sparse_set< Entity, Allocator >

Sparse set implementation.

Sparse set or packed array or whatever is the name users give it.
Two arrays: an external one and an internal one; a sparse one and a packed one; one used for direct access through contiguous memory, the other one used to get the data through an extra level of indirection.
This type of data structure is widely documented in the literature and on the web. This is nothing more than a customized implementation suitable for the purpose of the framework.

Note
  Internal data structures arrange elements to maximize performance. There are no guarantees that entities are returned in the insertion order when iterate a sparse set. Do not make assumption on the order in any case.

Template Parameters

  Entity | A valid entity type.
  Allocator | Type of allocator used to manage memory and elements.

Definition at line 158 of file sparse_set.hpp.

## Member Typedef Documentation

## ◆ allocator_type

template<typename Entity, typename Allocator>

using entt::basic_sparse_set< Entity, Allocator >::allocator_type = Allocator

Allocator type.

Definition at line 387 of file sparse_set.hpp.

## ◆ basic_iterator

template<typename Entity, typename Allocator>

using entt::basic_sparse_set< Entity, Allocator >::basic_iterator = internal::sparse_set_iterator<packed_container_type>
| protected

Random access iterator type.

Definition at line 247 of file sparse_set.hpp.

## ◆ const_iterator

template<typename Entity, typename Allocator>

using entt::basic_sparse_set< Entity, Allocator >::const_iterator = iterator

Constant random access iterator type.

Definition at line 401 of file sparse_set.hpp.

## ◆ const_reverse_iterator

template<typename Entity, typename Allocator>

using entt::basic_sparse_set< Entity, Allocator >::const_reverse_iterator = std::reverse_iterator<const_iterator>

Constant reverse iterator type.

Definition at line 405 of file sparse_set.hpp.

## ◆ difference_type

template<typename Entity, typename Allocator>

using entt::basic_sparse_set< Entity, Allocator >::difference_type = std::ptrdiff_t

Signed integer type.

Definition at line 395 of file sparse_set.hpp.

## ◆ entity_type

template<typename Entity, typename Allocator>

using entt::basic_sparse_set< Entity, Allocator >::entity_type = typename traits_type::value_type

Underlying entity identifier.

Definition at line 389 of file sparse_set.hpp.

## ◆ iterator

template<typename Entity, typename Allocator>

using entt::basic_sparse_set< Entity, Allocator >::iterator = basic_iterator

Random access iterator type.

Definition at line 399 of file sparse_set.hpp.

## ◆ pointer

template<typename Entity, typename Allocator>

using entt::basic_sparse_set< Entity, Allocator >::pointer = typename packed_container_type::const_pointer

Pointer type to contained entities.

Definition at line 397 of file sparse_set.hpp.

## ◆ reverse_iterator

template<typename Entity, typename Allocator>

using entt::basic_sparse_set< Entity, Allocator >::reverse_iterator = std::reverse_iterator<iterator>

Reverse iterator type.

Definition at line 403 of file sparse_set.hpp.

## ◆ size_type

template<typename Entity, typename Allocator>

using entt::basic_sparse_set< Entity, Allocator >::size_type = std::size_t

Unsigned integer type.

Definition at line 393 of file sparse_set.hpp.

## ◆ version_type

template<typename Entity, typename Allocator>

using entt::basic_sparse_set< Entity, Allocator >::version_type = typename traits_type::version_type

Underlying version type.

Definition at line 391 of file sparse_set.hpp.

## Constructor & Destructor Documentation

## ◆ basic_sparse_set() [1/6]

template<typename Entity, typename Allocator>

entt::basic_sparse_set< Entity, Allocator >::basic_sparse_set | ( |  | ) |
| inline

Default constructor.

Definition at line 408 of file sparse_set.hpp.

## ◆ basic_sparse_set() [2/6]

template<typename Entity, typename Allocator>

entt::basic_sparse_set< Entity, Allocator >::basic_sparse_set | ( | const allocator_type & | allocator | ) |
| inlineexplicit

Constructs an empty container with a given allocator.

Parameters

  allocator | The allocator to use.

Definition at line 415 of file sparse_set.hpp.

## ◆ basic_sparse_set() [3/6]

template<typename Entity, typename Allocator>

entt::basic_sparse_set< Entity, Allocator >::basic_sparse_set | ( | deletion_policy | pol,
|  | const allocator_type & | allocator = {} )
| inlineexplicit

Constructs an empty container with the given policy and allocator.

Parameters

  pol | Type of deletion policy.
  allocator | The allocator to use (possibly default-constructed).

Definition at line 423 of file sparse_set.hpp.

## ◆ basic_sparse_set() [4/6]

template<typename Entity, typename Allocator>

entt::basic_sparse_set< Entity, Allocator >::basic_sparse_set | ( | const type_info & | elem,
|  | deletion_policy | pol = deletion_policy::swap_and_pop,
|  | const allocator_type & | allocator = {} )
| inlineexplicit

Constructs an empty container with the given value type, policy and allocator.

Parameters

  elem | Returned value type, if any.
  pol | Type of deletion policy.
  allocator | The allocator to use (possibly default-constructed).

Definition at line 433 of file sparse_set.hpp.

## ◆ basic_sparse_set() [5/6]

template<typename Entity, typename Allocator>

entt::basic_sparse_set< Entity, Allocator >::basic_sparse_set | ( | basic_sparse_set< Entity, Allocator > && | other | ) |
| inlinenoexcept

Move constructor.

Parameters

  other | The instance to move from.

Definition at line 449 of file sparse_set.hpp.

## ◆ basic_sparse_set() [6/6]

template<typename Entity, typename Allocator>

entt::basic_sparse_set< Entity, Allocator >::basic_sparse_set | ( | basic_sparse_set< Entity, Allocator > && | other,
|  | const allocator_type & | allocator )
| inline

Allocator-extended move constructor.

Parameters

  other | The instance to move from.
  allocator | The allocator to use.

Definition at line 461 of file sparse_set.hpp.

## ◆ ~basic_sparse_set()

template<typename Entity, typename Allocator>

virtual entt::basic_sparse_set< Entity, Allocator >::~basic_sparse_set | ( |  | ) |
| inlinevirtual

Default destructor.

Definition at line 471 of file sparse_set.hpp.

## Member Function Documentation

## ◆ begin()

template<typename Entity, typename Allocator>

iterator entt::basic_sparse_set< Entity, Allocator >::begin | ( |  | ) | const
| inlinenodiscardnoexcept

Returns an iterator to the beginning.

If the sparse set is empty, the returned iterator will be equal to end().

Returns
  An iterator to the first entity of the sparse set.

Definition at line 650 of file sparse_set.hpp.

## ◆ bind()

template<typename Entity, typename Allocator>
template<typename Type>

void entt::basic_sparse_set< Entity, Allocator >::bind | ( | Type && | value | ) |
| inlinenoexcept

Forwards variables to derived classes, if any.

Template Parameters

  Type | Type of the element to forward.

Parameters

  value | The element to forward.

Definition at line 1100 of file sparse_set.hpp.

## ◆ bind_any()

template<typename Entity, typename Allocator>

virtual void entt::basic_sparse_set< Entity, Allocator >::bind_any | ( | any |  | ) |
| inlineprotectedvirtualnoexcept

Forwards variables to derived classes, if any.

Definition at line 383 of file sparse_set.hpp.

## ◆ bump()

template<typename Entity, typename Allocator>

version_type entt::basic_sparse_set< Entity, Allocator >::bump | ( | const entity_type | entt | ) |
| inline

Bump the version number of an entity.

Warning
  Attempting to bump the version of an entity that doesn't belong to the sparse set results in undefined behavior.

Parameters

  entt | A valid identifier.

Returns
  The version of the given identifier.

Definition at line 835 of file sparse_set.hpp.

## ◆ capacity()

template<typename Entity, typename Allocator>

virtual size_type entt::basic_sparse_set< Entity, Allocator >::capacity | ( |  | ) | const
| inlinenodiscardvirtualnoexcept

Returns the number of elements that a sparse set has currently allocated space for.

Returns
  Capacity of the sparse set.

Reimplemented in entt::basic_storage< Type, Entity, Allocator, typename >, entt::basic_storage< Entity, Entity, Allocator >, entt::basic_storage< Type >, and entt::basic_storage< Type, Entity, Allocator, std::enable_if_t< component_traits< Type, Entity >::page_size==0u > >.

Definition at line 555 of file sparse_set.hpp.

## ◆ cbegin()

template<typename Entity, typename Allocator>

const_iterator entt::basic_sparse_set< Entity, Allocator >::cbegin | ( |  | ) | const
| inlinenodiscardnoexcept

Returns an iterator to the beginning.

If the sparse set is empty, the returned iterator will be equal to end().

Returns
  An iterator to the first entity of the sparse set.

Definition at line 656 of file sparse_set.hpp.

## ◆ cend()

template<typename Entity, typename Allocator>

const_iterator entt::basic_sparse_set< Entity, Allocator >::cend | ( |  | ) | const
| inlinenodiscardnoexcept

Returns an iterator to the end.

Returns
  An iterator to the element following the last entity of a sparse set.

Definition at line 670 of file sparse_set.hpp.

## ◆ clear()

template<typename Entity, typename Allocator>

void entt::basic_sparse_set< Entity, Allocator >::clear | ( |  | ) |
| inline

Clears a sparse set.

Definition at line 1073 of file sparse_set.hpp.

## ◆ compact()

template<typename Entity, typename Allocator>

void entt::basic_sparse_set< Entity, Allocator >::compact | ( |  | ) |
| inline

Removes all tombstones from a sparse set.

Definition at line 922 of file sparse_set.hpp.

## ◆ contains()

template<typename Entity, typename Allocator>

bool entt::basic_sparse_set< Entity, Allocator >::contains | ( | const entity_type | entt | ) | const
| inlinenodiscardnoexcept

Checks if a sparse set contains an entity.

Parameters

  entt | A valid identifier.

Returns
  True if the sparse set contains the entity, false otherwise.

Definition at line 721 of file sparse_set.hpp.

## ◆ contiguous()

template<typename Entity, typename Allocator>

bool entt::basic_sparse_set< Entity, Allocator >::contiguous | ( |  | ) | const
| inlinenodiscardnoexcept

Checks whether a sparse set is fully packed.

Returns
  True if the sparse set is fully packed, false otherwise.

Definition at line 630 of file sparse_set.hpp.

## ◆ crbegin()

template<typename Entity, typename Allocator>

const_reverse_iterator entt::basic_sparse_set< Entity, Allocator >::crbegin | ( |  | ) | const
| inlinenodiscardnoexcept

Returns a reverse iterator to the beginning.

If the sparse set is empty, the returned iterator will be equal to rend().

Returns
  An iterator to the first entity of the reversed internal packed array.

Definition at line 688 of file sparse_set.hpp.

## ◆ crend()

template<typename Entity, typename Allocator>

const_reverse_iterator entt::basic_sparse_set< Entity, Allocator >::crend | ( |  | ) | const
| inlinenodiscardnoexcept

Returns a reverse iterator to the end.

Returns
  An iterator to the element following the last entity of the reversed sparse set.

Definition at line 702 of file sparse_set.hpp.

## ◆ current()

template<typename Entity, typename Allocator>

version_type entt::basic_sparse_set< Entity, Allocator >::current | ( | const entity_type | entt | ) | const
| inlinenodiscardnoexcept

Returns the contained version for an identifier.

Parameters

  entt | A valid identifier.

Returns
  The version for the given identifier if present, the tombstone version otherwise.

Definition at line 735 of file sparse_set.hpp.

## ◆ data()

template<typename Entity, typename Allocator>

pointer entt::basic_sparse_set< Entity, Allocator >::data | ( |  | ) | const
| inlinenodiscardnoexcept

Direct access to the internal packed array.

Returns
  A pointer to the internal packed array.

Definition at line 638 of file sparse_set.hpp.

## ◆ empty()

template<typename Entity, typename Allocator>

bool entt::basic_sparse_set< Entity, Allocator >::empty | ( |  | ) | const
| inlinenodiscardnoexcept

Checks whether a sparse set is empty.

Returns
  True if the sparse set is empty, false otherwise.

Definition at line 622 of file sparse_set.hpp.

## ◆ end()

template<typename Entity, typename Allocator>

iterator entt::basic_sparse_set< Entity, Allocator >::end | ( |  | ) | const
| inlinenodiscardnoexcept

Returns an iterator to the end.

Returns
  An iterator to the element following the last entity of a sparse set.

Definition at line 665 of file sparse_set.hpp.

## ◆ erase() [1/2]

template<typename Entity, typename Allocator>

void entt::basic_sparse_set< Entity, Allocator >::erase | ( | const entity_type | entt | ) |
| inline

Erases an entity from a sparse set.

Warning
  Attempting to erase an entity that doesn't belong to the sparse set results in undefined behavior.

Parameters

  entt | A valid identifier.

Definition at line 852 of file sparse_set.hpp.

## ◆ erase() [2/2]

template<typename Entity, typename Allocator>
template<typename It>

void entt::basic_sparse_set< Entity, Allocator >::erase | ( | It | first,
|  | It | last )
| inline

Erases entities from a set.

See also
  erase

Template Parameters

  It | Type of input iterator.

Parameters

  first | An iterator to the first element of the range of entities.
  last | An iterator past the last element of the range of entities.

Definition at line 867 of file sparse_set.hpp.

## ◆ extent()

template<typename Entity, typename Allocator>

size_type entt::basic_sparse_set< Entity, Allocator >::extent | ( |  | ) | const
| inlinenodiscardnoexcept

Returns the extent of a sparse set.

The extent of a sparse set is also the size of the internal sparse array. There is no guarantee that all pages have been allocated, nor that the internal packed array is be the same size.

Returns
  Extent of the sparse set.

Definition at line 600 of file sparse_set.hpp.

## ◆ find()

template<typename Entity, typename Allocator>

const_iterator entt::basic_sparse_set< Entity, Allocator >::find | ( | const entity_type | entt | ) | const
| inlinenodiscardnoexcept

Finds an entity.

Parameters

  entt | A valid identifier.

Returns
  An iterator to the given entity if it's found, past the end iterator otherwise.

Definition at line 712 of file sparse_set.hpp.

## ◆ free_list() [1/2]

template<typename Entity, typename Allocator>

size_type entt::basic_sparse_set< Entity, Allocator >::free_list | ( |  | ) | const
| inlinenodiscardnoexcept

Returns data on the free list whose meaning depends on the mode.

Returns
  Free list information that is mode dependent.

Definition at line 525 of file sparse_set.hpp.

## ◆ free_list() [2/2]

template<typename Entity, typename Allocator>

void entt::basic_sparse_set< Entity, Allocator >::free_list | ( | const size_type | value | ) |
| inlinenoexcept

Sets data on the free list whose meaning depends on the mode.

Parameters

  value | Free list information that is mode dependent.

Definition at line 533 of file sparse_set.hpp.

## ◆ get_allocator()

template<typename Entity, typename Allocator>

allocator_type entt::basic_sparse_set< Entity, Allocator >::get_allocator | ( |  | ) | const
| inlinenodiscardconstexprnoexcept

Returns the associated allocator.

Returns
  The associated allocator.

Definition at line 509 of file sparse_set.hpp.

## ◆ in_place_pop()

template<typename Entity, typename Allocator>

void entt::basic_sparse_set< Entity, Allocator >::in_place_pop | ( | const basic_iterator | it | ) |
| inlineprotected

Erases an entity from a sparse set.

Parameters

  it | An iterator to the element to pop.

Definition at line 282 of file sparse_set.hpp.

## ◆ index()

template<typename Entity, typename Allocator>

size_type entt::basic_sparse_set< Entity, Allocator >::index | ( | const entity_type | entt | ) | const
| inlinenodiscardnoexcept

Returns the position of an entity in a sparse set.

Warning
  Attempting to get the position of an entity that doesn't belong to the sparse set results in undefined behavior.

Parameters

  entt | A valid identifier.

Returns
  The position of the entity in the sparse set.

Definition at line 751 of file sparse_set.hpp.

## ◆ info()

template<typename Entity, typename Allocator>

const type_info & entt::basic_sparse_set< Entity, Allocator >::info | ( |  | ) | const
| inlinenodiscardnoexcept

Returns a type info object for the value type, if any.

Returns
  A type info object for the value type, if any.

Definition at line 1085 of file sparse_set.hpp.

## ◆ operator=() [1/2]

template<typename Entity, typename Allocator>

basic_sparse_set & entt::basic_sparse_set< Entity, Allocator >::operator= | ( | basic_sparse_set< Entity, Allocator > && | other | ) |
| inlinenoexcept

Move assignment operator.

Parameters

  other | The instance to move from.

Returns
  This sparse set.

Definition at line 486 of file sparse_set.hpp.

## ◆ operator=() [2/2]

template<typename Entity, typename Allocator>

basic_sparse_set & entt::basic_sparse_set< Entity, Allocator >::operator= | ( | const basic_sparse_set< Entity, Allocator > & |  | ) |
| delete

Default copy assignment operator, deleted on purpose.

Returns
  This sparse set.

## ◆ operator[]()

template<typename Entity, typename Allocator>

entity_type entt::basic_sparse_set< Entity, Allocator >::operator[] | ( | const size_type | pos | ) | const
| inlinenodiscardnoexcept

Returns the entity at specified location.

Parameters

  pos | The position for which to return the entity.

Returns
  The entity at specified location.

Definition at line 761 of file sparse_set.hpp.

## ◆ policy()

template<typename Entity, typename Allocator>

deletion_policy entt::basic_sparse_set< Entity, Allocator >::policy | ( |  | ) | const
| inlinenodiscardnoexcept

Returns the deletion policy of a sparse set.

Returns
  The deletion policy of the sparse set.

Definition at line 517 of file sparse_set.hpp.

## ◆ pop()

template<typename Entity, typename Allocator>

virtual void entt::basic_sparse_set< Entity, Allocator >::pop | ( | basic_iterator | first,
|  | basic_iterator | last )
| inlineprotectedvirtual

Erases entities from a sparse set.

Parameters

  first | An iterator to the first element of the range of entities.
  last | An iterator past the last element of the range of entities.

Reimplemented in entt::basic_storage< Type, Entity, Allocator, typename >, entt::basic_storage< Entity, Entity, Allocator >, entt::basic_storage< Type >, and entt::basic_storage< Type, Entity, Allocator, std::enable_if_t< component_traits< Type, Entity >::page_size==0u > >.

Definition at line 293 of file sparse_set.hpp.

## ◆ pop_all()

template<typename Entity, typename Allocator>

virtual void entt::basic_sparse_set< Entity, Allocator >::pop_all | ( |  | ) |
| inlineprotectedvirtual

Erases all entities of a sparse set.

Reimplemented in entt::basic_storage< Type, Entity, Allocator, typename >, entt::basic_storage< Entity, Entity, Allocator >, entt::basic_storage< Type >, and entt::basic_storage< Type, Entity, Allocator, std::enable_if_t< component_traits< Type, Entity >::page_size==0u > >.

Definition at line 314 of file sparse_set.hpp.

## ◆ push() [1/2]

template<typename Entity, typename Allocator>

iterator entt::basic_sparse_set< Entity, Allocator >::push | ( | const entity_type | entt,
|  | const void * | elem = nullptr )
| inline

Assigns an entity to a sparse set.

Warning
  Attempting to assign an entity that already belongs to the sparse set results in undefined behavior.

Parameters

  entt | A valid identifier.
  elem | Optional opaque element to forward to mixins, if any.

Returns
  Iterator pointing to the emplaced element in case of success, the end() iterator otherwise.

Definition at line 797 of file sparse_set.hpp.

## ◆ push() [2/2]

template<typename Entity, typename Allocator>
template<typename It>

iterator entt::basic_sparse_set< Entity, Allocator >::push | ( | It | first,
|  | It | last )
| inline

Assigns one or more entities to a sparse set.

Warning
  Attempting to assign an entity that already belongs to the sparse set results in undefined behavior.

Template Parameters

  It | Type of input iterator.

Parameters

  first | An iterator to the first element of the range of entities.
  last | An iterator past the last element of the range of entities.

Returns
  Iterator pointing to the first element inserted in case of success, the end() iterator otherwise.

Definition at line 815 of file sparse_set.hpp.

## ◆ rbegin()

template<typename Entity, typename Allocator>

reverse_iterator entt::basic_sparse_set< Entity, Allocator >::rbegin | ( |  | ) | const
| inlinenodiscardnoexcept

Returns a reverse iterator to the beginning.

If the sparse set is empty, the returned iterator will be equal to rend().

Returns
  An iterator to the first entity of the reversed internal packed array.

Definition at line 683 of file sparse_set.hpp.

## ◆ remove() [1/2]

template<typename Entity, typename Allocator>

bool entt::basic_sparse_set< Entity, Allocator >::remove | ( | const entity_type | entt | ) |
| inline

Removes an entity from a sparse set if it exists.

Parameters

  entt | A valid identifier.

Returns
  True if the entity is actually removed, false otherwise.

Definition at line 882 of file sparse_set.hpp.

## ◆ remove() [2/2]

template<typename Entity, typename Allocator>
template<typename It>

size_type entt::basic_sparse_set< Entity, Allocator >::remove | ( | It | first,
|  | It | last )
| inline

Removes entities from a sparse set if they exist.

Template Parameters

  It | Type of input iterator.

Parameters

  first | An iterator to the first element of the range of entities.
  last | An iterator past the last element of the range of entities.

Returns
  The number of entities actually removed.

Definition at line 894 of file sparse_set.hpp.

## ◆ rend()

template<typename Entity, typename Allocator>

reverse_iterator entt::basic_sparse_set< Entity, Allocator >::rend | ( |  | ) | const
| inlinenodiscardnoexcept

Returns a reverse iterator to the end.

Returns
  An iterator to the element following the last entity of the reversed sparse set.

Definition at line 697 of file sparse_set.hpp.

## ◆ reserve()

template<typename Entity, typename Allocator>

virtual void entt::basic_sparse_set< Entity, Allocator >::reserve | ( | const size_type | cap | ) |
| inlinevirtual

Increases the capacity of a sparse set.

If the new capacity is greater than the current capacity, new storage is allocated, otherwise the method does nothing.

Parameters

  cap | Desired capacity.

Reimplemented in entt::basic_storage< Type, Entity, Allocator, typename >, entt::basic_storage< Entity, Entity, Allocator >, entt::basic_storage< Type >, and entt::basic_storage< Type, Entity, Allocator, std::enable_if_t< component_traits< Type, Entity >::page_size==0u > >.

Definition at line 546 of file sparse_set.hpp.

## ◆ shrink_to_fit()

template<typename Entity, typename Allocator>

virtual void entt::basic_sparse_set< Entity, Allocator >::shrink_to_fit | ( |  | ) |
| inlinevirtual

Requests the removal of unused capacity.

Reimplemented in entt::basic_storage< Type, Entity, Allocator, typename >, entt::basic_storage< Entity, Entity, Allocator >, entt::basic_storage< Type >, and entt::basic_storage< Type, Entity, Allocator, std::enable_if_t< component_traits< Type, Entity >::page_size==0u > >.

Definition at line 560 of file sparse_set.hpp.

## ◆ size()

template<typename Entity, typename Allocator>

size_type entt::basic_sparse_set< Entity, Allocator >::size | ( |  | ) | const
| inlinenodiscardnoexcept

Returns the number of elements in a sparse set.

The number of elements is also the size of the internal packed array. There is no guarantee that the internal sparse array has the same size. Usually the size of the internal sparse array is equal or greater than the one of the internal packed array.

Returns
  Number of elements.

Definition at line 614 of file sparse_set.hpp.

## ◆ sort()

template<typename Entity, typename Allocator>
template<typename Compare, typename Sort = std_sort, typename... Args>

void entt::basic_sparse_set< Entity, Allocator >::sort | ( | Compare | compare,
|  | Sort | algo = Sort{},
|  | Args &&... | args )
| inline

Sort all elements according to the given comparison function.

See also
  sort_n

Template Parameters

  Compare | Type of comparison function object.
  Sort | Type of sort function object.
  Args | Types of arguments to forward to the sort function object.

Parameters

  compare | A valid comparison function object.
  algo | A valid sort function object.
  args | Arguments to forward to the sort function object, if any.

Definition at line 1034 of file sparse_set.hpp.

## ◆ sort_as()

template<typename Entity, typename Allocator>
template<typename It>

iterator entt::basic_sparse_set< Entity, Allocator >::sort_as | ( | It | first,
|  | It | last )
| inline

Sort entities according to their order in a range.

Entities that are part of both the sparse set and the range are ordered internally according to the order they have in the range.
All other entities goes to the end of the sparse set and there are no guarantees on their order.

Template Parameters

  It | Type of input iterator.

Parameters

  first | An iterator to the first element of the range of entities.
  last | An iterator past the last element of the range of entities.

Returns
  An iterator past the last of the elements actually shared.

Definition at line 1053 of file sparse_set.hpp.

## ◆ sort_n()

template<typename Entity, typename Allocator>
template<typename Compare, typename Sort = std_sort, typename... Args>

void entt::basic_sparse_set< Entity, Allocator >::sort_n | ( | const size_type | length,
|  | Compare | compare,
|  | Sort | algo = Sort{},
|  | Args &&... | args )
| inline

Sort the first count elements according to the given comparison function.

The comparison function object must return true if the first element is less than the second one, false otherwise. The signature of the comparison function should be equivalent to the following:

bool(const Entity, const Entity);

Moreover, the comparison function object shall induce a strict weak ordering on the values.

The sort function object must offer a member function template operator() that accepts three arguments:

- An iterator to the first element of the range to sort.
- An iterator past the last element of the range to sort.
- A comparison function to use to compare the elements.

Template Parameters

  Compare | Type of comparison function object.
  Sort | Type of sort function object.
  Args | Types of arguments to forward to the sort function object.

Parameters

  length | Number of elements to sort.
  compare | A valid comparison function object.
  algo | A valid sort function object.
  args | Arguments to forward to the sort function object, if any.

Definition at line 999 of file sparse_set.hpp.

## ◆ swap()

template<typename Entity, typename Allocator>

void entt::basic_sparse_set< Entity, Allocator >::swap | ( | basic_sparse_set< Entity, Allocator > & | other | ) |
| inlinenoexcept

Exchanges the contents with those of a given sparse set.

Parameters

  other | Sparse set to exchange the content with.

Definition at line 496 of file sparse_set.hpp.

## ◆ swap_and_pop()

template<typename Entity, typename Allocator>

void entt::basic_sparse_set< Entity, Allocator >::swap_and_pop | ( | const basic_iterator | it | ) |
| inlineprotected

Erases an entity from a sparse set.

Parameters

  it | An iterator to the element to pop.

Definition at line 264 of file sparse_set.hpp.

## ◆ swap_elements()

template<typename Entity, typename Allocator>

void entt::basic_sparse_set< Entity, Allocator >::swap_elements | ( | const entity_type | lhs,
|  | const entity_type | rhs )
| inline

Swaps two entities in a sparse set.

For what it's worth, this function affects both the internal sparse array and the internal packed array. Users should not care of that anyway.

Warning
  Attempting to swap entities that don't belong to the sparse set results in undefined behavior.

Parameters

  lhs | A valid identifier.
  rhs | A valid identifier.

Definition at line 959 of file sparse_set.hpp.

## ◆ swap_only()

template<typename Entity, typename Allocator>

void entt::basic_sparse_set< Entity, Allocator >::swap_only | ( | const basic_iterator | it | ) |
| inlineprotected

Erases an entity from a sparse set.

Parameters

  it | An iterator to the element to pop.

Definition at line 253 of file sparse_set.hpp.

## ◆ try_emplace()

template<typename Entity, typename Allocator>

virtual basic_iterator entt::basic_sparse_set< Entity, Allocator >::try_emplace | ( | const Entity | entt,
|  | const bool | force_back,
|  | const void * | = nullptr )
| inlineprotectedvirtual

Assigns an entity to a sparse set.

Parameters

  entt | A valid identifier.
  force_back | Force back insertion.

Returns
  Iterator pointing to the emplaced element.

Reimplemented in entt::basic_storage< Type, Entity, Allocator, typename >, entt::basic_storage< Entity, Entity, Allocator >, entt::basic_storage< Type >, and entt::basic_storage< Type, Entity, Allocator, std::enable_if_t< component_traits< Type, Entity >::page_size==0u > >.

Definition at line 344 of file sparse_set.hpp.

## ◆ type()

template<typename Entity, typename Allocator>

const type_info & entt::basic_sparse_set< Entity, Allocator >::type | ( |  | ) | const
| inlinenodiscardnoexcept

Returns a type info object for the value type, if any.

Returns
  A type info object for the value type, if any.

Definition at line 1090 of file sparse_set.hpp.

## ◆ value() [1/2]

template<typename Entity, typename Allocator>

const void * entt::basic_sparse_set< Entity, Allocator >::value | ( | const entity_type | entt | ) | const
| inlinenodiscardnoexcept

Returns the element assigned to an entity, if any.

Warning
  Attempting to use an entity that doesn't belong to the sparse set results in undefined behavior.

Parameters

  entt | A valid identifier.

Returns
  An opaque pointer to the element assigned to the entity, if any.

Definition at line 776 of file sparse_set.hpp.

## ◆ value() [2/2]

template<typename Entity, typename Allocator>

void * entt::basic_sparse_set< Entity, Allocator >::value | ( | const entity_type | entt | ) |
| inlinenodiscardnoexcept

Returns the element assigned to an entity, if any.

Warning
  Attempting to use an entity that doesn't belong to the sparse set results in undefined behavior.

Parameters

  entt | A valid identifier.

Returns
  An opaque pointer to the element assigned to the entity, if any.

Definition at line 781 of file sparse_set.hpp.

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

- src/entt/entity/fwd.hpp
- src/entt/entity/sparse_set.hpp