summaryrefslogtreecommitdiff
path: root/src/misc/smallvec.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/misc/smallvec.h')
-rw-r--r--src/misc/smallvec.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/misc/smallvec.h b/src/misc/smallvec.h
index 984d634ac..7f85cc96a 100644
--- a/src/misc/smallvec.h
+++ b/src/misc/smallvec.h
@@ -19,6 +19,29 @@ struct SmallVector {
}
/**
+ * Remove all items from the list.
+ */
+ void Clear()
+ {
+ /* In fact we just reset the item counter avoiding the need to
+ * probably reallocate the same amount of memory the list was
+ * previously using. */
+ this->items = 0;
+ }
+
+ /**
+ * Compact the list down to the smallest block size boundary.
+ */
+ void Compact()
+ {
+ uint capacity = Align(this->items, S);
+ if (capacity >= this->capacity) return;
+
+ this->capacity = capacity;
+ this->data = ReallocT(this->data, this->capacity);
+ }
+
+ /**
* Append an item and return it.
*/
T *Append()
@@ -31,6 +54,14 @@ struct SmallVector {
return &this->data[this->items++];
}
+ /**
+ * Get the number of items in the list.
+ */
+ uint Length() const
+ {
+ return this->items;
+ }
+
const T *Begin() const
{
return this->data;
@@ -60,6 +91,16 @@ struct SmallVector {
{
return &this->data[index];
}
+
+ const T &operator[](uint index) const
+ {
+ return this->data[index];
+ }
+
+ T &operator[](uint index)
+ {
+ return this->data[index];
+ }
};
#endif /* SMALLVEC_H */