sparse_set: swap_only pop function
This commit is contained in:
@@ -241,6 +241,25 @@ protected:
|
||||
head = static_cast<underlying_type>(len);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Erases an entity from a sparse set.
|
||||
* @param it An iterator to the element to pop.
|
||||
*/
|
||||
void swap_only(const basic_iterator it) {
|
||||
ENTT_ASSERT(mode == deletion_policy::swap_only, "Deletion policy mismatched");
|
||||
|
||||
if(const auto pos = static_cast<underlying_type>(index(*it)); pos < head) {
|
||||
bump(traits_type::next(*it));
|
||||
|
||||
if(const auto slot = head - 1u; pos != slot) {
|
||||
swap_elements(packed[pos], packed[slot]);
|
||||
}
|
||||
|
||||
// partition check support in derived classes
|
||||
--head;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Erases an entity from a sparse set.
|
||||
* @param it An iterator to the element to pop.
|
||||
@@ -287,7 +306,9 @@ protected:
|
||||
}
|
||||
break;
|
||||
case deletion_policy::swap_only:
|
||||
// no-op
|
||||
for(; first != last; ++first) {
|
||||
swap_only(first);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -971,25 +971,6 @@ private:
|
||||
}
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Erases entities from a storage.
|
||||
* @param first An iterator to the first element of the range of entities.
|
||||
* @param last An iterator past the last element of the range of entities.
|
||||
*/
|
||||
void pop(underlying_iterator first, underlying_iterator last) override {
|
||||
for(; first != last; ++first) {
|
||||
if(const auto pos = base_type::index(*first); pos < base_type::free_list()) {
|
||||
base_type::bump(local_traits_type::next(*first));
|
||||
|
||||
if(const size_type slot = base_type::free_list() - 1u; pos != slot) {
|
||||
base_type::swap_elements(base_type::data()[pos], base_type::data()[slot]);
|
||||
}
|
||||
|
||||
base_type::swap_only_length_temporary_function(base_type::free_list() - 1u);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Assigns an entity to a storage.
|
||||
* @param hint A valid identifier.
|
||||
@@ -1147,7 +1128,7 @@ public:
|
||||
* @param first An iterator to the first element of the range to generate.
|
||||
* @param last An iterator past the last element of the range to generate.
|
||||
*/
|
||||
template<typename It>
|
||||
template<typename It>
|
||||
void insert(It first, It last) {
|
||||
for(const auto sz = base_type::size(); first != last && base_type::free_list() != sz; ++first, base_type::swap_only_length_temporary_function(base_type::free_list() + 1u)) {
|
||||
*first = base_type::operator[](base_type::free_list());
|
||||
|
||||
Reference in New Issue
Block a user