|
| sparse_set ()=default |
| Default constructor. More...
|
|
| sparse_set (const sparse_set &other) |
| Copy constructor. More...
|
|
| sparse_set (sparse_set &&)=default |
| Default move constructor. More...
|
|
virtual | ~sparse_set () ENTT_NOEXCEPT=default |
| Default destructor. More...
|
|
sparse_set & | operator= (const sparse_set &other) |
| Copy assignment operator. More...
|
|
sparse_set & | operator= (sparse_set &&)=default |
| Default move assignment operator. More...
|
|
void | reserve (const size_type cap) |
| Increases the capacity of a sparse set. More...
|
|
size_type | capacity () const ENTT_NOEXCEPT |
| Returns the number of elements that a sparse set has currently allocated space for. More...
|
|
void | shrink_to_fit () |
| Requests the removal of unused capacity. More...
|
|
size_type | extent () const ENTT_NOEXCEPT |
| Returns the extent of a sparse set. More...
|
|
size_type | size () const ENTT_NOEXCEPT |
| Returns the number of elements in a sparse set. More...
|
|
bool | empty () const ENTT_NOEXCEPT |
| Checks whether a sparse set is empty. More...
|
|
const entity_type * | data () const ENTT_NOEXCEPT |
| Direct access to the internal packed array. More...
|
|
iterator_type | begin () const ENTT_NOEXCEPT |
| Returns an iterator to the beginning. More...
|
|
iterator_type | end () const ENTT_NOEXCEPT |
| Returns an iterator to the end. More...
|
|
iterator_type | find (const entity_type entt) const ENTT_NOEXCEPT |
| Finds an entity. More...
|
|
bool | has (const entity_type entt) const ENTT_NOEXCEPT |
| Checks if a sparse set contains an entity. More...
|
|
size_type | index (const entity_type entt) const ENTT_NOEXCEPT |
| Returns the position of an entity in a sparse set. More...
|
|
void | construct (const entity_type entt) |
| Assigns an entity to a sparse set. More...
|
|
template<typename It > |
void | batch (It first, It last) |
| Assigns one or more entities to a sparse set. More...
|
|
void | destroy (const entity_type entt) |
| Removes an entity from a sparse set. More...
|
|
virtual void | swap (const entity_type lhs, const entity_type rhs) ENTT_NOEXCEPT |
| Swaps two entities in the internal packed array. More...
|
|
template<typename Compare , typename Sort = std_sort, typename... Args> |
void | sort (iterator_type first, iterator_type last, Compare compare, Sort algo=Sort{}, Args &&... args) |
| Sort elements according to the given comparison function. More...
|
|
template<typename Apply , typename Compare , typename Sort = std_sort, typename... Args> |
void | arrange (iterator_type first, iterator_type last, Apply apply, Compare compare, Sort algo=Sort{}, Args &&... args) |
| Sort elements according to the given comparison function. More...
|
|
void | respect (const sparse_set &other) ENTT_NOEXCEPT |
| Sort entities according to their order in another sparse set. More...
|
|
void | reset () |
| Resets a sparse set. More...
|
|
template<typename Entity>
class entt::sparse_set< Entity >
Basic 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 is largely used by the registry to offer users the fastest access ever to the components. Views and groups in general are almost entirely designed around sparse sets.
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
- 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.
-
Internal data structures arrange elements to maximize performance. Because of that, there are no guarantees that elements have the expected order when iterate directly the internal packed array (see
data
and size
member functions for that). Use begin
and end
instead.
- Template Parameters
-
Entity | A valid entity type (see entt_traits for more details). |
template<typename Entity >
template<typename Apply , typename Compare , typename Sort = std_sort, typename... Args>
Sort elements according to the given comparison function.
- See also
- sort
This function is a slightly slower version of sort
that invokes the caller to indicate which entities are swapped.
It's recommended when the caller wants to sort its own data structures to align them with the order induced in the sparse set.
The signature of the callback should be equivalent to the following:
bool(const Entity, const Entity);
- Template Parameters
-
Apply | Type of function object to invoke to notify the caller. |
Compare | Type of comparison function object. |
Sort | Type of sort function object. |
Args | Types of arguments to forward to the sort function object. |
- Parameters
-
first | An iterator to the first element of the range to sort. |
last | An iterator past the last element of the range to sort. |
apply | A valid function object to use as a callback. |
compare | A valid comparison function object. |
algo | A valid sort function object. |
args | Arguments to forward to the sort function object, if any. |
template<typename Entity >
Sort entities according to their order in another sparse set.
Entities that are part of both the sparse sets are ordered internally according to the order they have in other
. All the other entities goes to the end of the list and there are no guarantees on their order.
In other terms, this function can be used to impose the same order on two sets by using one of them as a master and the other one as a slave.
Iterating the sparse set with a couple of iterators returns elements in the expected order after a call to respect
. See begin
and end
for more details.
- Note
- Attempting to iterate elements using a raw pointer returned by a call to
data
gives no guarantees on the order, even though respect
has been invoked.
- Parameters
-
other | The sparse sets that imposes the order of the entities. |
template<typename Entity >
template<typename Compare , typename Sort = std_sort, typename... Args>
Sort elements according to the given comparison function.
Sort the elements so that iterating the range with a couple of iterators returns them in the expected order. See begin
and end
for more details.
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 oject 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.
- Note
- Attempting to iterate elements using a raw pointer returned by a call to
data
gives no guarantees on the order, even though sort
has been invoked.
- 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
-
first | An iterator to the first element of the range to sort. |
last | An iterator past the last element of the range 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. |
template<typename Entity >