From dd9e099605615bdf49bcd0b9ca76bd9bb745b628 Mon Sep 17 00:00:00 2001 From: Bailey Thompson Date: Thu, 25 Jan 2018 19:48:27 -0500 Subject: [PATCH] Add function used to obtain vector capacity --- src/vector.c | 12 ++++++++++++ src/vector.h | 1 + tst/vector.c | 1 + 3 files changed, 14 insertions(+) diff --git a/src/vector.c b/src/vector.c index 61fa5f3..fb0a328 100644 --- a/src/vector.c +++ b/src/vector.c @@ -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. * diff --git a/src/vector.h b/src/vector.h index 0e64427..a8fc9c6 100644 --- a/src/vector.h +++ b/src/vector.h @@ -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); diff --git a/tst/vector.c b/tst/vector.c index 84c00af..e47fc94 100644 --- a/tst/vector.c +++ b/tst/vector.c @@ -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);