Update to TommyDS v3.0

This commit is contained in:
Andrea Mazzoleni 2018-04-01 22:36:42 +02:00
parent 9d142e72a4
commit c696c56df1
12 changed files with 181 additions and 102 deletions

View file

@ -53,20 +53,15 @@
*/
#define TOMMY_ARRAY_BIT 6
/** \internal
* Max number of elements as a power of 2.
*/
#define TOMMY_ARRAY_BIT_MAX 32
/**
* Array container type.
* \note Don't use internal fields directly, but access the container only using functions.
*/
typedef struct tommy_array_struct {
void** bucket[TOMMY_ARRAY_BIT_MAX]; /**< Dynamic array of buckets. */
void** bucket[TOMMY_SIZE_BIT]; /**< Dynamic array of buckets. */
tommy_size_t bucket_max; /**< Number of buckets. */
tommy_size_t count; /**< Number of initialized elements in the array. */
tommy_uint_t bucket_bit; /**< Bits used in the bit mask. */
tommy_count_t bucket_max; /**< Number of buckets. */
tommy_count_t count; /**< Number of initialized elements in the array. */
} tommy_array;
/**
@ -83,21 +78,21 @@ void tommy_array_done(tommy_array* array);
* Grows the size up to the specified value.
* All the new elements in the array are initialized with the 0 value.
*/
void tommy_array_grow(tommy_array* array, tommy_count_t size);
void tommy_array_grow(tommy_array* array, tommy_size_t size);
/**
* Gets a reference of the element at the specified position.
* You must be sure that space for this position is already
* allocated calling tommy_array_grow().
*/
tommy_inline void** tommy_array_ref(tommy_array* array, tommy_count_t pos)
tommy_inline void** tommy_array_ref(tommy_array* array, tommy_size_t pos)
{
tommy_uint_t bsr;
assert(pos < array->count);
/* get the highest bit set, in case of all 0, return 0 */
bsr = tommy_ilog2_u32(pos | 1);
bsr = tommy_ilog2(pos | 1);
return &array->bucket[bsr][pos];
}
@ -107,7 +102,7 @@ tommy_inline void** tommy_array_ref(tommy_array* array, tommy_count_t pos)
* You must be sure that space for this position is already
* allocated calling tommy_array_grow().
*/
tommy_inline void tommy_array_set(tommy_array* array, tommy_count_t pos, void* element)
tommy_inline void tommy_array_set(tommy_array* array, tommy_size_t pos, void* element)
{
*tommy_array_ref(array, pos) = element;
}
@ -117,7 +112,7 @@ tommy_inline void tommy_array_set(tommy_array* array, tommy_count_t pos, void* e
* You must be sure that space for this position is already
* allocated calling tommy_array_grow().
*/
tommy_inline void* tommy_array_get(tommy_array* array, tommy_count_t pos)
tommy_inline void* tommy_array_get(tommy_array* array, tommy_size_t pos)
{
return *tommy_array_ref(array, pos);
}
@ -127,7 +122,7 @@ tommy_inline void* tommy_array_get(tommy_array* array, tommy_count_t pos)
*/
tommy_inline void tommy_array_insert(tommy_array* array, void* element)
{
tommy_count_t pos = array->count;
tommy_size_t pos = array->count;
tommy_array_grow(array, pos + 1);
@ -137,7 +132,7 @@ tommy_inline void tommy_array_insert(tommy_array* array, void* element)
/**
* Gets the initialized size of the array.
*/
tommy_inline tommy_count_t tommy_array_size(tommy_array* array)
tommy_inline tommy_size_t tommy_array_size(tommy_array* array)
{
return array->count;
}