#define TAG "UARRAYLIST"
/**
- * Use this default size when initialized
+ * Use this default capacity when initialized
*/
-#define U_ARRAYLIST_DEFAULT_SIZE 1
+#define U_ARRAYLIST_DEFAULT_CAPACITY 1
u_arraylist_t *u_arraylist_create()
{
return NULL;
}
- list->size = U_ARRAYLIST_DEFAULT_SIZE;
+ list->capacity = U_ARRAYLIST_DEFAULT_CAPACITY;
list->length = 0;
- list->data = (void **) OICMalloc(list->size * sizeof(list->data[0]));
+ list->data = (void **) OICMalloc(list->capacity * sizeof(list->data[0]));
if (!list->data)
{
OIC_LOG(DEBUG, TAG, "Out of memory");
void u_arraylist_reserve(u_arraylist_t *list, size_t count)
{
- if (list && (count > list->size))
+ if (list && (count > list->capacity))
{
void *tmp = OICRealloc(list->data, count * sizeof(list->data[0]));
if (!tmp)
else
{
list->data = (void **) tmp;
- list->size = count;
+ list->capacity = count;
}
}
}
return;
}
- if ((list->size > list->length)
- && (list->length >= U_ARRAYLIST_DEFAULT_SIZE))
+ if ((list->capacity > list->length)
+ && (list->length >= U_ARRAYLIST_DEFAULT_CAPACITY))
{
void *tmp = OICRealloc(list->data,
list->length * sizeof(list->data[0]));
else
{
list->data = (void **) tmp;
- list->size = list->length;
+ list->capacity = list->length;
}
}
}
return false;
}
- if (list->size <= list->length)
+ if (list->capacity <= list->length)
{
- uint32_t new_size = (list->size * GROWTH_FACTOR) + 0.5;
+ uint32_t new_capacity = (list->capacity * GROWTH_FACTOR) + 0.5;
// In case the re-alloc returns null, use a local variable to avoid
// losing the current block of memory.
- void *tmp = OICRealloc(list->data, new_size * sizeof(list->data[0]));
+ void *tmp = OICRealloc(list->data,
+ new_capacity * sizeof(list->data[0]));
if (!tmp)
{
OIC_LOG(DEBUG, TAG, "Memory reallocation failed.");
return false;
}
list->data = (void **) tmp;
- memset(list->data + list->size, 0,
- (new_size - list->size) * sizeof(list->data[0]));
- list->size = new_size;
+ memset(list->data + list->capacity, 0,
+ (new_capacity - list->capacity) * sizeof(list->data[0]));
+ list->capacity = new_capacity;
}
list->data[list->length] = data;
return false;
}
- for (uint32_t i = 0; i < list->size; i++)
+ for (uint32_t i = 0; i < list->length; i++)
{
if (data == list->data[i])
{