Updates to latest TommyDS version.

This commit is contained in:
Andrea Mazzoleni 2014-10-25 17:28:41 +02:00
parent acb1bad9b0
commit aff9f97d50
11 changed files with 188 additions and 117 deletions

View file

@ -27,14 +27,12 @@
#include "tommyarray.h"
#include <stddef.h> /* for ptrdiff_t */
/******************************************************************************/
/* array */
void tommy_array_init(tommy_array* array)
{
unsigned i;
tommy_uint_t i;
/* fixed initial size */
array->bucket_bit = TOMMY_ARRAY_BIT;
@ -43,28 +41,27 @@ void tommy_array_init(tommy_array* array)
for (i = 1; i < TOMMY_ARRAY_BIT; ++i)
array->bucket[i] = array->bucket[0];
array->bucket_mac = TOMMY_ARRAY_BIT;
array->size = 0;
array->count = 0;
}
void tommy_array_done(tommy_array* array)
{
unsigned i;
tommy_uint_t i;
tommy_free(array->bucket[0]);
for (i = TOMMY_ARRAY_BIT; i < array->bucket_mac; ++i) {
for (i = TOMMY_ARRAY_BIT; i < array->bucket_bit; ++i) {
void** segment = array->bucket[i];
tommy_free(&segment[1 << i]);
tommy_free(&segment[((tommy_ptrdiff_t)1) << i]);
}
}
void tommy_array_grow(tommy_array* array, unsigned size)
void tommy_array_grow(tommy_array* array, tommy_count_t count)
{
if (array->size >= size)
if (array->count >= count)
return;
array->size = size;
array->count = count;
while (size > array->bucket_max) {
while (count > array->bucket_max) {
void** segment;
/* allocate one more segment */
@ -72,9 +69,8 @@ void tommy_array_grow(tommy_array* array, unsigned size)
/* store it adjusting the offset */
/* cast to ptrdiff_t to ensure to get a negative value */
array->bucket[array->bucket_mac] = &segment[-(ptrdiff_t)array->bucket_max];
array->bucket[array->bucket_bit] = &segment[-(tommy_ptrdiff_t)array->bucket_max];
++array->bucket_mac;
++array->bucket_bit;
array->bucket_max = 1 << array->bucket_bit;
}