sparse_set: review pop_all

This commit is contained in:
Michele Caini
2023-09-05 14:37:14 +02:00
parent 9732f0547d
commit 995f7e8e19

View File

@@ -217,20 +217,6 @@ class basic_sparse_set {
}
}
void checked_pop_all() {
for(auto first = begin(); !(first.index() < 0); ++first) {
if(*first != tombstone) {
sparse_ref(*first) = null;
}
}
}
void unchecked_pop_all() {
for(auto first = begin(); !(first.index() < 0); ++first) {
sparse_ref(*first) = null;
}
}
underlying_type policy_to_head() {
switch(mode) {
case deletion_policy::swap_and_pop:
@@ -315,16 +301,24 @@ protected:
virtual void pop_all() {
switch(mode) {
case deletion_policy::in_place:
(std::exchange(head, traits_type::entity_mask) == null) ? unchecked_pop_all() : checked_pop_all();
break;
case deletion_policy::swap_only:
head = {};
if(head != null) {
for(auto first = begin(); !(first.index() < 0); ++first) {
if(*first != tombstone) {
sparse_ref(*first) = null;
}
}
break;
}
[[fallthrough]];
case deletion_policy::swap_only:
case deletion_policy::swap_and_pop:
checked_pop_all();
for(auto first = begin(); !(first.index() < 0); ++first) {
sparse_ref(*first) = null;
}
break;
}
head = policy_to_head();
packed.clear();
}