Add function used to obtain vector capacity

This commit is contained in:
Bailey Thompson
2018-01-25 19:48:27 -05:00
committed by GitHub
parent 00b849c42f
commit dd9e099605
3 changed files with 14 additions and 0 deletions

View File

@@ -74,6 +74,18 @@ int vector_size(vector me)
return me->item_count;
}
/**
* Gets the capacity that the internal storage of the vector is using.
*
* @param me The vector to check.
*
* @return The capacity that the internal storage of the vector is using
*/
int vector_capacity(vector me)
{
return me->item_capacity;
}
/**
* Determines whether or not the vector is empty.
*

View File

@@ -32,6 +32,7 @@ vector vector_init(size_t data_size);
// Utility
int vector_size(vector me);
int vector_capacity(vector me);
bool vector_is_empty(vector me);
int vector_reserve(vector me, int size);
int vector_trim(vector me);

View File

@@ -88,6 +88,7 @@ void test_vector(void)
for (int i = 0; i < 10; i++) {
assert(data[i] == val[9 - i]);
}
assert(vector_capacity(me) >= vector_size(me));
int trimmed[5] = {0};
vector_trim(me);
vector_reserve(me, 3);