diff options
author | Jacques Lucke <jacques@blender.org> | 2020-08-26 11:52:35 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-08-26 11:52:43 +0300 |
commit | 0e50b6529cf8b43d4ff7a738bf201e6058ca5ba6 (patch) | |
tree | 95ee8293b247f6dead6fe9b7abc7c0b8ee18b9b7 /source/blender/blenlib/BLI_vector.hh | |
parent | 6a10e69d270bc6866dd0000ffc0b81f6205ba2e9 (diff) |
BLI: support removing multiple elements from a vector
Diffstat (limited to 'source/blender/blenlib/BLI_vector.hh')
-rw-r--r-- | source/blender/blenlib/BLI_vector.hh | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_vector.hh b/source/blender/blenlib/BLI_vector.hh index 392b6cd9f47..3c90e1ab755 100644 --- a/source/blender/blenlib/BLI_vector.hh +++ b/source/blender/blenlib/BLI_vector.hh @@ -742,6 +742,27 @@ class Vector { } /** + * Remove a contiguous chunk of elements and move all values coming after it towards the front. + * This takes O(n) time. + * + * This is similar to std::vector::erase. + */ + void remove(const int64_t start_index, const int64_t amount) + { + const int64_t old_size = this->size(); + BLI_assert(start_index >= 0); + BLI_assert(amount >= 0); + BLI_assert(start_index + amount <= old_size); + const int64_t move_amount = old_size - start_index - amount; + for (int64_t i = 0; i < move_amount; i++) { + begin_[start_index + i] = std::move(begin_[start_index + amount + i]); + } + destruct_n(end_ - amount, amount); + end_ -= amount; + UPDATE_VECTOR_SIZE(this); + } + + /** * Do a linear search to find the value in the vector. * When found, return the first index, otherwise return -1. */ |