src/misc/smallvec.h
changeset 9348 dc680f675138
parent 9335 4f1e59a9aed4
child 9427 af652de004a0
--- a/src/misc/smallvec.h	Sun May 25 15:57:45 2008 +0000
+++ b/src/misc/smallvec.h	Sun May 25 16:12:13 2008 +0000
@@ -19,6 +19,29 @@
 	}
 
 	/**
+	 * 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 @@
 		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 @@
 	{
 		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 */