mirror of
https://github.com/amadvance/snapraid.git
synced 2026-11-29 19:37:06 -05:00
Updates to latest TommyDS version.
This commit is contained in:
parent
acb1bad9b0
commit
aff9f97d50
11 changed files with 188 additions and 117 deletions
|
|
@ -28,11 +28,11 @@
|
|||
/** \file
|
||||
* Dynamic array based on segments of exponential growing size.
|
||||
*
|
||||
* This array is able to grow dynamically upon request.
|
||||
* This array is able to grow dynamically upon request, without any reallocation.
|
||||
*
|
||||
* The resize involve an allocation of a new array segment, without reallocating
|
||||
* the already allocated memory, and then not increasing the heap fragmentation.
|
||||
* This means that the address of the allocated segments never change.
|
||||
* The grow operation involves an allocation of a new array segment, without reallocating
|
||||
* the already used memory, and then not increasing the heap fragmentation.
|
||||
* This also implies that the address of the stored elements never change.
|
||||
*
|
||||
* Allocated segments grow in size exponentially.
|
||||
*/
|
||||
|
|
@ -59,14 +59,14 @@
|
|||
#define TOMMY_ARRAY_BIT_MAX 32
|
||||
|
||||
/**
|
||||
* Array.
|
||||
* 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. */
|
||||
unsigned bucket_bit; /**< Bits used in the bit mask. */
|
||||
unsigned bucket_max; /**< Number of buckets. */
|
||||
unsigned bucket_mac; /**< Number of vectors allocated. */
|
||||
unsigned size; /**< Currently allocated and initialized size. */
|
||||
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;
|
||||
|
||||
/**
|
||||
|
|
@ -80,21 +80,21 @@ void tommy_array_init(tommy_array* array);
|
|||
void tommy_array_done(tommy_array* array);
|
||||
|
||||
/**
|
||||
* Grow the size up to the specified value.
|
||||
* 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, unsigned size);
|
||||
void tommy_array_grow(tommy_array* array, tommy_count_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, unsigned pos)
|
||||
tommy_inline void** tommy_array_ref(tommy_array* array, tommy_count_t pos)
|
||||
{
|
||||
unsigned bsr;
|
||||
tommy_uint_t bsr;
|
||||
|
||||
assert(pos < array->size);
|
||||
assert(pos < array->count);
|
||||
|
||||
/* get the highest bit set, in case of all 0, return 0 */
|
||||
bsr = tommy_ilog2_u32(pos | 1);
|
||||
|
|
@ -107,7 +107,7 @@ tommy_inline void** tommy_array_ref(tommy_array* array, unsigned 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, unsigned pos, void* element)
|
||||
tommy_inline void tommy_array_set(tommy_array* array, tommy_count_t pos, void* element)
|
||||
{
|
||||
*tommy_array_ref(array, pos) = element;
|
||||
}
|
||||
|
|
@ -117,7 +117,7 @@ tommy_inline void tommy_array_set(tommy_array* array, unsigned pos, void* elemen
|
|||
* 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, unsigned pos)
|
||||
tommy_inline void* tommy_array_get(tommy_array* array, tommy_count_t pos)
|
||||
{
|
||||
return *tommy_array_ref(array, pos);
|
||||
}
|
||||
|
|
@ -127,7 +127,7 @@ tommy_inline void* tommy_array_get(tommy_array* array, unsigned pos)
|
|||
*/
|
||||
tommy_inline void tommy_array_insert(tommy_array* array, void* element)
|
||||
{
|
||||
unsigned pos = array->size;
|
||||
tommy_count_t pos = array->count;
|
||||
|
||||
tommy_array_grow(array, pos + 1);
|
||||
|
||||
|
|
@ -137,9 +137,9 @@ tommy_inline void tommy_array_insert(tommy_array* array, void* element)
|
|||
/**
|
||||
* Gets the initialized size of the array.
|
||||
*/
|
||||
tommy_inline unsigned tommy_array_size(tommy_array* array)
|
||||
tommy_inline tommy_count_t tommy_array_size(tommy_array* array)
|
||||
{
|
||||
return array->size;
|
||||
return array->count;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue