|
EnTT 4.0.0
|
Sparse set implementation. More...
#include <sparse_set.hpp>

Public Types | |
| using | allocator_type = Allocator |
| Allocator type. | |
| using | entity_type = traits_type::value_type |
| Underlying entity identifier. | |
| using | version_type = traits_type::version_type |
| Underlying version type. | |
| using | size_type = stl::size_t |
| Unsigned integer type. | |
| using | difference_type = stl::ptrdiff_t |
| Signed integer type. | |
| using | pointer = 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 = stl::reverse_iterator<iterator> |
| Reverse iterator type. | |
| using | const_reverse_iterator = stl::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. | |
| iterator | push (stl::input_iterator auto first, stl::input_iterator auto 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<stl::input_iterator 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<stl::input_iterator 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<stl::input_iterator 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. | |
| 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 Entity entt) |
| Erases an entity from a sparse set. | |
| void | swap_and_pop (const Entity entt) |
| Erases an entity from a sparse set. | |
| void | in_place_pop (const Entity entt) |
| 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. | |
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.
| Entity | A valid entity type. |
| Allocator | Type of allocator used to manage memory and elements. |
Definition at line 139 of file sparse_set.hpp.
| using entt::basic_sparse_set< Entity, Allocator >::allocator_type = Allocator |
Allocator type.
Definition at line 358 of file sparse_set.hpp.
|
protected |
Random access iterator type.
Definition at line 226 of file sparse_set.hpp.
| using entt::basic_sparse_set< Entity, Allocator >::const_iterator = iterator |
Constant random access iterator type.
Definition at line 372 of file sparse_set.hpp.
| using entt::basic_sparse_set< Entity, Allocator >::const_reverse_iterator = stl::reverse_iterator<const_iterator> |
Constant reverse iterator type.
Definition at line 376 of file sparse_set.hpp.
| using entt::basic_sparse_set< Entity, Allocator >::difference_type = stl::ptrdiff_t |
Signed integer type.
Definition at line 366 of file sparse_set.hpp.
| using entt::basic_sparse_set< Entity, Allocator >::entity_type = traits_type::value_type |
Underlying entity identifier.
Definition at line 360 of file sparse_set.hpp.
| using entt::basic_sparse_set< Entity, Allocator >::iterator = basic_iterator |
Random access iterator type.
Definition at line 370 of file sparse_set.hpp.
| using entt::basic_sparse_set< Entity, Allocator >::pointer = packed_container_type::const_pointer |
Pointer type to contained entities.
Definition at line 368 of file sparse_set.hpp.
| using entt::basic_sparse_set< Entity, Allocator >::reverse_iterator = stl::reverse_iterator<iterator> |
Reverse iterator type.
Definition at line 374 of file sparse_set.hpp.
| using entt::basic_sparse_set< Entity, Allocator >::size_type = stl::size_t |
Unsigned integer type.
Definition at line 364 of file sparse_set.hpp.
| using entt::basic_sparse_set< Entity, Allocator >::version_type = traits_type::version_type |
Underlying version type.
Definition at line 362 of file sparse_set.hpp.
|
inline |
Default constructor.
Definition at line 379 of file sparse_set.hpp.
|
inlineexplicit |
Constructs an empty container with a given allocator.
| allocator | The allocator to use. |
Definition at line 386 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 394 of file sparse_set.hpp.
|
inlineexplicit |
Constructs an empty container with the given value type, policy and allocator.
| elem | Returned value type, if any. |
| pol | Type of deletion policy. |
| allocator | The allocator to use (possibly default-constructed). |
Definition at line 404 of file sparse_set.hpp.
|
inlinenoexcept |
Move constructor.
| other | The instance to move from. |
Definition at line 420 of file sparse_set.hpp.
|
inline |
Allocator-extended move constructor.
| other | The instance to move from. |
| allocator | The allocator to use. |
Definition at line 432 of file sparse_set.hpp.
|
inlinevirtual |
Default destructor.
Definition at line 442 of file sparse_set.hpp.
|
inlinenodiscardnoexcept |
Returns an iterator to the beginning.
If the sparse set is empty, the returned iterator will be equal to end().
Definition at line 619 of file sparse_set.hpp.
|
inlinenoexcept |
Forwards variables to derived classes, if any.
| Type | Type of the element to forward. |
| value | The element to forward. |
Definition at line 1062 of file sparse_set.hpp.
|
inlineprotectedvirtualnoexcept |
Forwards variables to derived classes, if any.
Definition at line 354 of file sparse_set.hpp.
|
inline |
Bump the version number of an entity.
| entt | A valid identifier. |
Definition at line 802 of file sparse_set.hpp.
|
inlinenodiscardvirtualnoexcept |
Returns the number of elements that a sparse set has currently allocated space for.
Reimplemented in entt::basic_storage< Type, Entity, Allocator >, entt::basic_storage< Entity, Entity, Allocator >, entt::basic_storage< Type >, and entt::basic_storage< Type, Entity, Allocator >.
Definition at line 526 of file sparse_set.hpp.
|
inlinenodiscardnoexcept |
Returns an iterator to the beginning.
If the sparse set is empty, the returned iterator will be equal to end().
Definition at line 625 of file sparse_set.hpp.
|
inlinenodiscardnoexcept |
Returns an iterator to the end.
Definition at line 639 of file sparse_set.hpp.
|
inline |
Clears a sparse set.
Definition at line 1040 of file sparse_set.hpp.
|
inline |
Removes all tombstones from a sparse set.
Definition at line 889 of file sparse_set.hpp.
|
inlinenodiscardnoexcept |
Checks if a sparse set contains an entity.
| entt | A valid identifier. |
Definition at line 690 of file sparse_set.hpp.
|
inlinenodiscardnoexcept |
Checks whether a sparse set is fully packed.
Definition at line 599 of file sparse_set.hpp.
|
inlinenodiscardnoexcept |
Returns a reverse iterator to the beginning.
If the sparse set is empty, the returned iterator will be equal to rend().
Definition at line 657 of file sparse_set.hpp.
|
inlinenodiscardnoexcept |
Returns a reverse iterator to the end.
Definition at line 671 of file sparse_set.hpp.
|
inlinenodiscardnoexcept |
Returns the contained version for an identifier.
| entt | A valid identifier. |
Definition at line 704 of file sparse_set.hpp.
|
inlinenodiscardnoexcept |
Direct access to the internal packed array.
Definition at line 607 of file sparse_set.hpp.
|
inlinenodiscardnoexcept |
Checks whether a sparse set is empty.
Definition at line 591 of file sparse_set.hpp.
|
inlinenodiscardnoexcept |
Returns an iterator to the end.
Definition at line 634 of file sparse_set.hpp.
|
inline |
Erases an entity from a sparse set.
| entt | A valid identifier. |
Definition at line 819 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 834 of file sparse_set.hpp.
|
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.
Definition at line 569 of file sparse_set.hpp.
|
inlinenodiscardnoexcept |
Finds an entity.
| entt | A valid identifier. |
Definition at line 681 of file sparse_set.hpp.
|
inlinenodiscardnoexcept |
Returns data on the free list whose meaning depends on the mode.
Definition at line 496 of file sparse_set.hpp.
|
inlinenoexcept |
Sets data on the free list whose meaning depends on the mode.
| value | Free list information that is mode dependent. |
Definition at line 504 of file sparse_set.hpp.
|
inlinenodiscardconstexprnoexcept |
Returns the associated allocator.
Definition at line 480 of file sparse_set.hpp.
|
inlineprotected |
Erases an entity from a sparse set.
| entt | A valid identifier for the element to pop. |
Definition at line 261 of file sparse_set.hpp.
|
inlinenodiscardnoexcept |
Returns the position of an entity in a sparse set.
| entt | A valid identifier. |
Definition at line 720 of file sparse_set.hpp.
|
inlinenodiscardnoexcept |
Returns a type info object for the value type, if any.
Definition at line 1052 of file sparse_set.hpp.
|
inlinenoexcept |
Move assignment operator.
| other | The instance to move from. |
Definition at line 457 of file sparse_set.hpp.
|
delete |
Default copy assignment operator, deleted on purpose.
|
inlinenodiscardnoexcept |
Returns the entity at specified location.
| pos | The position for which to return the entity. |
Definition at line 730 of file sparse_set.hpp.
|
inlinenodiscardnoexcept |
Returns the deletion policy of a sparse set.
Definition at line 488 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< Type, Entity, Allocator >, entt::basic_storage< Entity, Entity, Allocator >, entt::basic_storage< Type >, and entt::basic_storage< Type, Entity, Allocator >.
Definition at line 272 of file sparse_set.hpp.
|
inlineprotectedvirtual |
Erases all entities of a sparse set.
Reimplemented in entt::basic_storage< Type, Entity, Allocator >, entt::basic_storage< Entity, Entity, Allocator >, entt::basic_storage< Type >, and entt::basic_storage< Type, Entity, Allocator >.
Definition at line 293 of file sparse_set.hpp.
|
inline |
Assigns an entity to a sparse set.
| entt | A valid identifier. |
| elem | Optional opaque element to forward to mixins, if any. |
Definition at line 766 of file sparse_set.hpp.
|
inline |
Assigns one or more entities to 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. |
Definition at line 782 of file sparse_set.hpp.
|
inlinenodiscardnoexcept |
Returns a reverse iterator to the beginning.
If the sparse set is empty, the returned iterator will be equal to rend().
Definition at line 652 of file sparse_set.hpp.
|
inline |
Removes an entity from a sparse set if it exists.
| entt | A valid identifier. |
Definition at line 849 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 861 of file sparse_set.hpp.
|
inlinenodiscardnoexcept |
Returns a reverse iterator to the end.
Definition at line 666 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< Type, Entity, Allocator >, entt::basic_storage< Entity, Entity, Allocator >, entt::basic_storage< Type >, and entt::basic_storage< Type, Entity, Allocator >.
Definition at line 517 of file sparse_set.hpp.
|
inlinevirtual |
Requests the removal of unused capacity.
Reimplemented in entt::basic_storage< Type, Entity, Allocator >, entt::basic_storage< Entity, Entity, Allocator >, entt::basic_storage< Type >, and entt::basic_storage< Type, Entity, Allocator >.
Definition at line 531 of file sparse_set.hpp.
|
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.
Definition at line 583 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 1001 of file sparse_set.hpp.
|
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.
| 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 1020 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 966 of file sparse_set.hpp.
|
inlinenoexcept |
Exchanges the contents with those of a given sparse set.
| other | Sparse set to exchange the content with. |
Definition at line 467 of file sparse_set.hpp.
|
inlineprotected |
Erases an entity from a sparse set.
| entt | A valid identifier for the element to pop. |
Definition at line 243 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 926 of file sparse_set.hpp.
|
inlineprotected |
Erases an entity from a sparse set.
| entt | A valid identifier for the element to pop. |
Definition at line 232 of file sparse_set.hpp.
|
inlineprotectedvirtual |
Assigns an entity to a sparse set.
| entt | A valid identifier. |
| force_back | Force back insertion. |
Reimplemented in entt::basic_storage< Type, Entity, Allocator >, entt::basic_storage< Entity, Entity, Allocator >, entt::basic_storage< Type >, and entt::basic_storage< Type, Entity, Allocator >.
Definition at line 315 of file sparse_set.hpp.
|
inlinenodiscardnoexcept |
Returns the element assigned to an entity, if any.
| entt | A valid identifier. |
Definition at line 745 of file sparse_set.hpp.
|
inlinenodiscardnoexcept |
Returns the element assigned to an entity, if any.
| entt | A valid identifier. |
Definition at line 750 of file sparse_set.hpp.