CWB
Defines | Functions

binsert.c File Reference

#include "globals.h"
#include "macros.h"
#include "binsert.h"
#include <string.h>

Defines

Functions


Define Documentation

#define REALLOC_THRESHOLD   16

Memory reallocation threshold for binserting.

This threshold applies to "tables" manipulated with binsert_g(). When the memory for these "tables" is allocated/reallocated, this is done in increments of REALLOC_THRESHOLD elements. So in theory reallocation will not be need more than once every REALLOC_THRESHOLD times the binsert_g() function is called.

See also:
binsert_g

Referenced by binsert_g().


Function Documentation

void* binsert_g ( const void *  key,
void **  base,
size_t *  nel,
size_t  size,
int(*)(const void *, const void *)  compar 
)

Inserts an element into the table of elements at base.

If base is NULL, a new "table" is created, and a single element copied into it.

The memory of this table of elements will be reallocated if necessary.

How to call this function:

(void) binsert_g(&nr, (void **)&Table, &Nr_Elements, sizeof(int), intcompare);

Parameters:
keyPointer to the element to add
baseLocation of pointer to the table
nelNumber of elements (will be incremented by this function)
sizeThe size of each element in the table.
comparComparison function (returns int, takes two pointers as arguments)
Returns:
Address of the (new) element

References cl_malloc(), cl_realloc(), and REALLOC_THRESHOLD.

Referenced by ComputeGroupInternally().