|
EnTT
3.10.0
|
Basic sparse set implementation. More...
#include <sparse_set.hpp>

Public Types | |
| using | allocator_type = Allocator |
| Allocator type. | |
| using | entity_type = Entity |
| Underlying entity identifier. | |
| using | version_type = typename entity_traits::version_type |
| Underlying version type. | |
| using | size_type = typename packed_container_type::size_type |
| Unsigned 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 = reverse_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. More... | |
| basic_sparse_set (deletion_policy pol, const allocator_type &allocator={}) | |
| Constructs an empty container with the given policy and allocator. More... | |
| basic_sparse_set (const type_info &value, deletion_policy pol=deletion_policy::swap_and_pop, const allocator_type &allocator={}) | |
| Constructs an empty container with the given value type, policy and allocator. More... | |
| basic_sparse_set (basic_sparse_set &&other) | |
| Move constructor. More... | |
| basic_sparse_set (basic_sparse_set &&other, const allocator_type &allocator) | |
| Allocator-extended move constructor. More... | |
| virtual | ~basic_sparse_set () |
| Default destructor. | |
| basic_sparse_set & | operator= (basic_sparse_set &&other) |
| Move assignment operator. More... | |
| void | swap (basic_sparse_set &other) |
| Exchanges the contents with those of a given sparse set. More... | |
| constexpr allocator_type | get_allocator () const |
| Returns the associated allocator. More... | |
| deletion_policy | policy () const |
| Returns the deletion policy of a sparse set. More... | |
| virtual void | reserve (const size_type cap) |
| Increases the capacity of a sparse set. More... | |
| virtual size_type | capacity () const |
| Returns the number of elements that a sparse set has currently allocated space for. More... | |
| virtual void | shrink_to_fit () |
| Requests the removal of unused capacity. | |
| size_type | extent () const |
| Returns the extent of a sparse set. More... | |
| size_type | size () const |
| Returns the number of elements in a sparse set. More... | |
| bool | empty () const |
| Checks whether a sparse set is empty. More... | |
| pointer | data () const |
| Direct access to the internal packed array. More... | |
| const_iterator | begin () const |
| Returns an iterator to the beginning. More... | |
| const_iterator | cbegin () const |
| Returns an iterator to the beginning. More... | |
| iterator | end () const |
| Returns an iterator to the end. More... | |
| const_iterator | cend () const |
| Returns an iterator to the end. More... | |
| const_reverse_iterator | rbegin () const |
| Returns a reverse iterator to the beginning. More... | |
| const_reverse_iterator | crbegin () const |
| Returns a reverse iterator to the beginning. More... | |
| reverse_iterator | rend () const |
| Returns a reverse iterator to the end. More... | |
| const_reverse_iterator | crend () const |
| Returns a reverse iterator to the end. More... | |
| iterator | find (const entity_type entt) const |
| Finds an entity. More... | |
| bool | contains (const entity_type entt) const |
| Checks if a sparse set contains an entity. More... | |
| version_type | current (const entity_type entt) const |
| Returns the contained version for an identifier. More... | |
| size_type | index (const entity_type entt) const |
| Returns the position of an entity in a sparse set. More... | |
| entity_type | at (const size_type pos) const |
| Returns the entity at specified location, with bounds checking. More... | |
| entity_type | operator[] (const size_type pos) const |
| Returns the entity at specified location, without bounds checking. More... | |
| const void * | get (const entity_type entt) const |
| Returns the element assigned to an entity, if any. More... | |
| void * | get (const entity_type entt) |
| Returns the element assigned to an entity, if any. More... | |
| iterator | emplace (const entity_type entt, const void *value=nullptr) |
| Assigns an entity to a sparse set. More... | |
| void | bump (const entity_type entt) |
| Bump the version number of an entity. More... | |
| template<typename It > | |
| iterator | insert (It first, It last) |
| Assigns one or more entities to a sparse set. More... | |
| void | erase (const entity_type entt) |
| Erases an entity from a sparse set. More... | |
| template<typename It > | |
| void | erase (It first, It last) |
| Erases entities from a set. More... | |
| bool | remove (const entity_type entt) |
| Removes an entity from a sparse set if it exists. More... | |
| template<typename It > | |
| size_type | remove (It first, It last) |
| Removes entities from a sparse set if they exist. More... | |
| void | compact () |
| Removes all tombstones from the packed array of a sparse set. | |
| void | swap_elements (const entity_type lhs, const entity_type rhs) |
| Swaps two entities in a sparse set. More... | |
| 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. More... | |
| 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. More... | |
| void | respect (const basic_sparse_set &other) |
| Sort entities according to their order in another sparse set. More... | |
| void | clear () |
| Clears a sparse set. | |
| const type_info & | type () const |
| Returned value type, if any. More... | |
| virtual void | bind (any) |
| Forwards variables to mixins, if any. | |
Protected Types | |
| using | basic_iterator = internal::sparse_set_iterator< packed_container_type > |
| Random access iterator type. | |
Protected Member Functions | |
| virtual void | swap_and_pop (basic_iterator first, basic_iterator last) |
| Erases entities from a sparse set. More... | |
| virtual void | in_place_pop (basic_iterator first, basic_iterator last) |
| Erases entities from a sparse set. More... | |
| virtual basic_iterator | try_emplace (const Entity entt, const bool force_back, const void *=nullptr) |
| Assigns an entity to a sparse set. More... | |
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.
| Entity | A valid entity type (see entt_traits for more details). |
| Allocator | Type of allocator used to manage memory and elements. |
Definition at line 174 of file sparse_set.hpp.
|
inlineexplicit |
Constructs an empty container with a given allocator.
| allocator | The allocator to use. |
Definition at line 314 of file sparse_set.hpp.
|
inlineexplicit |
Constructs an empty container with the given policy and allocator.
| pol | Type of deletion policy. |
| allocator | The allocator to use (possibly default-constructed). |
Definition at line 322 of file sparse_set.hpp.
|
inlineexplicit |
Constructs an empty container with the given value type, policy and allocator.
| value | Returned value type, if any. |
| pol | Type of deletion policy. |
| allocator | The allocator to use (possibly default-constructed). |
Definition at line 332 of file sparse_set.hpp.
|
inline |
Move constructor.
| other | The instance to move from. |
Definition at line 343 of file sparse_set.hpp.
|
inline |
Allocator-extended move constructor.
| other | The instance to move from. |
| allocator | The allocator to use. |
Definition at line 355 of file sparse_set.hpp.
|
inline |
Returns the entity at specified location, with bounds checking.
| pos | The position for which to return the entity. |
Definition at line 615 of file sparse_set.hpp.
|
inline |
Returns an iterator to the beginning.
The returned iterator points to the first entity of the internal packed array. If the sparse set is empty, the returned iterator will be equal to end().
Definition at line 494 of file sparse_set.hpp.
|
inline |
Bump the version number of an entity.
| entt | A valid identifier. |
Definition at line 673 of file sparse_set.hpp.
|
inlinevirtual |
Returns the number of elements that a sparse set has currently allocated space for.
Reimplemented in entt::basic_storage< Entity, Type, Allocator, typename >, and entt::basic_storage< entity_type, payload_type >.
Definition at line 432 of file sparse_set.hpp.
|
inline |
Returns an iterator to the beginning.
The returned iterator points to the first entity of the internal packed array. If the sparse set is empty, the returned iterator will be equal to end().
Definition at line 500 of file sparse_set.hpp.
|
inline |
Returns an iterator to the end.
The returned iterator points to the element following the last entity in a sparse set. Attempting to dereference the returned iterator results in undefined behavior.
Definition at line 519 of file sparse_set.hpp.
|
inline |
Checks if a sparse set contains an entity.
| entt | A valid identifier. |
Definition at line 576 of file sparse_set.hpp.
|
inline |
Returns a reverse iterator to the beginning.
The returned iterator points to the first entity of the reversed internal packed array. If the sparse set is empty, the returned iterator will be equal to rend().
Definition at line 538 of file sparse_set.hpp.
|
inline |
Returns a reverse iterator to the end.
The returned iterator points to the element following the last entity in the reversed sparse set. Attempting to dereference the returned iterator results in undefined behavior.
Definition at line 557 of file sparse_set.hpp.
|
inline |
Returns the contained version for an identifier.
| entt | A valid identifier. |
Definition at line 589 of file sparse_set.hpp.
|
inline |
Direct access to the internal packed array.
Definition at line 481 of file sparse_set.hpp.
|
inline |
Assigns an entity to a sparse set.
| entt | A valid identifier. |
| value | Optional opaque value to forward to mixins, if any. |
end() iterator otherwise. Definition at line 660 of file sparse_set.hpp.
|
inline |
Checks whether a sparse set is empty.
Definition at line 473 of file sparse_set.hpp.
|
inline |
Returns an iterator to the end.
The returned iterator points to the element following the last entity in a sparse set. Attempting to dereference the returned iterator results in undefined behavior.
Definition at line 514 of file sparse_set.hpp.
|
inline |
Erases an entity from a sparse set.
| entt | A valid identifier. |
Definition at line 710 of file sparse_set.hpp.
|
inline |
Erases entities from a set.
| It | Type of input iterator. |
| 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 725 of file sparse_set.hpp.
|
inline |
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 the internal packed 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.
Definition at line 451 of file sparse_set.hpp.
|
inline |
Finds an entity.
| entt | A valid identifier. |
Definition at line 567 of file sparse_set.hpp.
|
inline |
Returns the element assigned to an entity, if any.
| entt | A valid identifier. |
Definition at line 644 of file sparse_set.hpp.
|
inline |
Returns the element assigned to an entity, if any.
| entt | A valid identifier. |
Definition at line 639 of file sparse_set.hpp.
|
inlineconstexpr |
Returns the associated allocator.
Definition at line 403 of file sparse_set.hpp.
|
inlineprotectedvirtual |
Erases entities from a sparse set.
| 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< Entity, Type, Allocator, typename >, and entt::basic_storage< entity_type, payload_type >.
Definition at line 258 of file sparse_set.hpp.
|
inline |
Returns the position of an entity in a sparse set.
| entt | A valid identifier. |
Definition at line 605 of file sparse_set.hpp.
|
inline |
Assigns one or more entities to a sparse set.
| It | Type of input iterator. |
| first | An iterator to the first element of the range of entities. |
| last | An iterator past the last element of the range of entities. |
end() iterator otherwise. Definition at line 693 of file sparse_set.hpp.
|
inline |
Move assignment operator.
| other | The instance to move from. |
Definition at line 374 of file sparse_set.hpp.
|
inline |
Returns the entity at specified location, without bounds checking.
| pos | The position for which to return the entity. |
Definition at line 624 of file sparse_set.hpp.
|
inline |
Returns the deletion policy of a sparse set.
Definition at line 411 of file sparse_set.hpp.
|
inline |
Returns a reverse iterator to the beginning.
The returned iterator points to the first entity of the reversed internal packed array. If the sparse set is empty, the returned iterator will be equal to rend().
Definition at line 533 of file sparse_set.hpp.
|
inline |
Removes an entity from a sparse set if it exists.
| entt | A valid identifier. |
Definition at line 740 of file sparse_set.hpp.
|
inline |
Removes entities from a sparse set if they exist.
| It | Type of input iterator. |
| 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 752 of file sparse_set.hpp.
|
inline |
Returns a reverse iterator to the end.
The returned iterator points to the element following the last entity in the reversed sparse set. Attempting to dereference the returned iterator results in undefined behavior.
Definition at line 552 of file sparse_set.hpp.
|
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.
| cap | Desired capacity. |
Reimplemented in entt::basic_storage< entity_type, payload_type >.
Definition at line 423 of file sparse_set.hpp.
|
inline |
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.
| other | The sparse sets that imposes the order of the entities. |
Definition at line 903 of file sparse_set.hpp.
|
inline |
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.
Definition at line 465 of file sparse_set.hpp.
|
inline |
Sort all elements according to the given comparison function.
| Compare | Type of comparison function object. |
| Sort | Type of sort function object. |
| Args | Types of arguments to forward to the sort function object. |
| 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 883 of file sparse_set.hpp.
|
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:
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:
| Compare | Type of comparison function object. |
| Sort | Type of sort function object. |
| Args | Types of arguments to forward to the sort function object. |
| 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 848 of file sparse_set.hpp.
|
inline |
Exchanges the contents with those of a given sparse set.
| other | Sparse set to exchange the content with. |
Definition at line 390 of file sparse_set.hpp.
|
inlineprotectedvirtual |
Erases entities from a sparse set.
| 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< Entity, Type, Allocator, typename >, and entt::basic_storage< entity_type, payload_type >.
Definition at line 241 of file sparse_set.hpp.
|
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.
| lhs | A valid identifier. |
| rhs | A valid identifier. |
Definition at line 799 of file sparse_set.hpp.
|
inlineprotectedvirtual |
Assigns an entity to a sparse set.
| entt | A valid identifier. |
| force_back | Force back insertion. |
Definition at line 271 of file sparse_set.hpp.
|
inline |
Returned value type, if any.
Definition at line 942 of file sparse_set.hpp.