sparse_set: added free_list(N) for swap_only sets

This commit is contained in:
Michele Caini
2023-09-12 08:46:57 +02:00
parent 05644a742f
commit 8d39f89aff
2 changed files with 10 additions and 11 deletions

View File

@@ -240,15 +240,6 @@ protected:
/*! @brief Random access iterator type. */
using basic_iterator = internal::sparse_set_iterator<packed_container_type>;
/**
* @brief Temporary function to make the transition easier. Don't use me.
* @param len The length to use.
*/
void swap_only_length_temporary_function(const std::size_t len) {
ENTT_ASSERT(mode == deletion_policy::swap_only, "Deletion policy mismatch");
head = static_cast<underlying_type>(len);
}
/**
* @brief Erases an entity from a sparse set.
* @param it An iterator to the element to pop.
@@ -518,6 +509,15 @@ public:
return static_cast<size_type>(head);
}
/**
* @brief Sets the head of the free list, if possible.
* @param len The value to use as the new head of the free list.
*/
void free_list(const size_type len) noexcept {
ENTT_ASSERT((mode == deletion_policy::swap_only) && !(len > packed.size()), "Invalid value");
head = static_cast<underlying_type>(len);
}
/**
* @brief Increases the capacity of a sparse set.
*

View File

@@ -1170,8 +1170,7 @@ public:
* @param len The number of elements considered still in use.
*/
void in_use(const size_type len) noexcept {
ENTT_ASSERT(!(len > base_type::size()), "Invalid length");
base_type::swap_only_length_temporary_function(len);
base_type::free_list(len);
}
/**