summaryrefslogtreecommitdiff
path: root/src/core/smallvec_type.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/smallvec_type.hpp')
-rw-r--r--src/core/smallvec_type.hpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/core/smallvec_type.hpp b/src/core/smallvec_type.hpp
index ccf8dbaec..62de176a5 100644
--- a/src/core/smallvec_type.hpp
+++ b/src/core/smallvec_type.hpp
@@ -145,6 +145,20 @@ public:
}
/**
+ * Set the size of the vector, effectively truncating items from the end or appending uninitialised ones.
+ * @param num_items Target size.
+ */
+ inline void Resize(uint num_items)
+ {
+ this->items = num_items;
+
+ if (this->items > this->capacity) {
+ this->capacity = Align(this->items, S);
+ this->data = ReallocT(this->data, this->capacity);
+ }
+ }
+
+ /**
* Search for the first occurrence of an item.
* The '!=' operator of T is used for comparison.
* @param item Item to search for
@@ -213,6 +227,21 @@ public:
}
/**
+ * Remove items from the vector while preserving the order of other items.
+ * @param pos First item to remove.
+ * @param count Number of consecutive items to remove.
+ */
+ void ErasePreservingOrder(uint pos, uint count = 1)
+ {
+ if (count == 0) return;
+ assert(pos < this->items);
+ assert(pos + count <= this->items);
+ this->items -= count;
+ uint to_move = this->items - pos;
+ if (to_move > 0) MemMoveT(this->data + pos, this->data + pos + count, to_move);
+ }
+
+ /**
* Tests whether a item is present in the vector, and appends it to the end if not.
* The '!=' operator of T is used for comparison.
* @param item Item to test for