mirror of
https://github.com/bkthomps/Containers.git
synced 2026-04-05 01:49:53 +00:00
Add function used to obtain vector capacity
This commit is contained in:
12
src/vector.c
12
src/vector.c
@@ -74,6 +74,18 @@ int vector_size(vector me)
|
|||||||
return me->item_count;
|
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.
|
* Determines whether or not the vector is empty.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ vector vector_init(size_t data_size);
|
|||||||
|
|
||||||
// Utility
|
// Utility
|
||||||
int vector_size(vector me);
|
int vector_size(vector me);
|
||||||
|
int vector_capacity(vector me);
|
||||||
bool vector_is_empty(vector me);
|
bool vector_is_empty(vector me);
|
||||||
int vector_reserve(vector me, int size);
|
int vector_reserve(vector me, int size);
|
||||||
int vector_trim(vector me);
|
int vector_trim(vector me);
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ void test_vector(void)
|
|||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
assert(data[i] == val[9 - i]);
|
assert(data[i] == val[9 - i]);
|
||||||
}
|
}
|
||||||
|
assert(vector_capacity(me) >= vector_size(me));
|
||||||
int trimmed[5] = {0};
|
int trimmed[5] = {0};
|
||||||
vector_trim(me);
|
vector_trim(me);
|
||||||
vector_reserve(me, 3);
|
vector_reserve(me, 3);
|
||||||
|
|||||||
Reference in New Issue
Block a user