sparse_set/storage: improve emplace(N) with non-sequential entities

This commit is contained in:
Michele Caini
2023-09-12 08:54:38 +02:00
parent e561e8cbdd
commit a6fea6727b
2 changed files with 9 additions and 8 deletions

View File

@@ -363,7 +363,11 @@ protected:
bump(entt);
}
swap_at(static_cast<size_type>(traits_type::to_entity(elem)), (pos = static_cast<size_type>(head++)));
if(force_back) {
pos = static_cast<size_type>(head++);
swap_at(static_cast<size_type>(traits_type::to_entity(elem)), pos);
}
break;
}
@@ -760,7 +764,7 @@ public:
* `end()` iterator otherwise.
*/
iterator push(const entity_type entt, const void *elem = nullptr) {
return try_emplace(entt, false, elem);
return try_emplace(entt, (mode == deletion_policy::swap_only), elem);
}
/**

View File

@@ -1091,16 +1091,13 @@ public:
return emplace();
} else if(const auto curr = local_traits_type::construct(local_traits_type::to_entity(hint), base_type::current(hint)); curr == tombstone) {
const auto pos = static_cast<size_type>(local_traits_type::to_entity(hint));
const auto entt = *base_type::try_emplace(hint, true);
while(!(pos < base_type::size())) {
const auto it = base_type::try_emplace(entity_at(base_type::size()), true);
const auto entt = *it;
base_type::swap_only(it);
base_type::bump(entt);
base_type::try_emplace(entity_at(base_type::size() - 1u), false);
}
return *base_type::try_emplace(hint, true);
return entt;
} else if(const auto idx = base_type::index(curr); idx < base_type::free_list()) {
return emplace();
} else {