text
stringlengths
0
357
uintptr_t v1 = *(uintptr_t*)p1;
uintptr_t v2 = *(uintptr_t*)p2;
return (v1<v2)? -1 : ((v1>v2)? 1 : 0); /* CAVE: do not use v1-v2 as the uintptr_t may be 64bit and the return value may be 32bit only... */
}
/**
* Sort the array, assuming it contains unsigned integers.
*
* @private @memberof dc_array_t
* @param array The array object.
* @return The duplicated array.
*/
void dc_array_sort_ids(dc_array_t* array)
{
if (array==NULL || array->magic!=DC_ARRAY_MAGIC || array->count <= 1) {
return;
}
qsort(array->array, array->count, sizeof(uintptr_t), cmp_intptr_t);
}
static int cmp_strings_t(const void* p1, const void* p2)
{
const char* v1 = *(const char **)p1;
const char* v2 = *(const char **)p2;
return strcmp(v1, v2);
}
/**
* Sort the array, assuming it contains pointers to strings.
*
* @private @memberof dc_array_t
* @param array The array object.
* @return The duplicated array.
*/
void dc_array_sort_strings(dc_array_t* array)
{
if (array==NULL || array->magic!=DC_ARRAY_MAGIC || array->count <= 1) {
return;
}
qsort(array->array, array->count, sizeof(char*), cmp_strings_t);
}
/**
* Empty an array object. Allocated data is not freed by this function, only the count is set to null.
*
* @private @memberof dc_array_t
* @param array The array object to empty.
* @return None.
*/
void dc_array_empty(dc_array_t* array)
{
if (array==NULL || array->magic!=DC_ARRAY_MAGIC) {
return;
}
array->count = 0;
}
/**
* Add an unsigned integer to the array.
* After calling this function the size of the array grows by one.
* It is okay to add the ID 0, event in this case, the array grows by one.
*
* @param array The array to add the item to.
* @param item The item to add.
* @return None.
*/
void dc_array_add_uint(dc_array_t* array, uintptr_t item)
{
if (array==NULL || array->magic!=DC_ARRAY_MAGIC) {
return;
}
if (array->count==array->allocated) {
int newsize = (array->allocated * 2) + 10;
if ((array->array=realloc(array->array, newsize*sizeof(uintptr_t)))==NULL) {
exit(49);
}
array->allocated = newsize;
}
array->array[array->count] = item;
array->count++;
}
/**
* Add an ID to the array.
* After calling this function the size of the array grows by one.
* It is okay to add the ID 0, event in this case, the array grows by one.
*
* @param array The array to add the item to.
* @param item The item to add.
* @return None.
*/