20 #include <lal/LALHashTbl.h>
24 #define DEL ((void*) &hash_del)
27 #define HASHIDX(ht, x) ((int)((ht)->hash((ht)->hash_param, (x)) % (ht)->data_len))
30 #define INCRIDX(ht, i) do { if (++(i) == (ht)->data_len) { (i) = 0; } } while(0)
33 #define EQUAL(ht, x, y) ((ht)->cmp((ht)->cmp_param, (x), (y)) == 0)
64 void **old_data = ht->data;
65 int old_data_len = ht->data_len;
67 while ( ht->data_len < 3*ht->n ) {
70 ht->data =
XLALCalloc( ht->data_len,
sizeof( ht->data[0] ) );
73 for (
int k = 0; k < old_data_len; ++k ) {
74 if ( old_data[k] != NULL && old_data[k] !=
DEL ) {
75 int i =
HASHIDX( ht, old_data[k] );
76 while ( ht->data[i] != NULL ) {
79 ht->data[i] = old_data[k];
115 LALHashTbl *ht =
XLALCalloc( 1,
sizeof( *ht ) );
121 ht->hash_param = hash_param;
123 ht->cmp_param = cmp_param;
134 if ( ht->data != NULL ) {
135 if ( ht->dtor != NULL ) {
136 for (
int i = 0; i < ht->data_len; ++i ) {
137 if ( ht->data[i] != NULL && ht->data[i] !=
DEL ) {
138 ht->dtor( ht->data[i] );
157 if ( ht->data != NULL ) {
158 if ( ht->dtor != NULL ) {
159 for (
int i = 0; i < ht->data_len; ++i ) {
160 if ( ht->data[i] != NULL ) {
161 if ( ht->data[i] !=
DEL ) {
162 ht->dtor( ht->data[i] );
186 const LALHashTbl *ht,
198 if ( ht->data_len > 0 ) {
200 while ( ht->data[i] != NULL ) {
233 if ( 2*( ht->q + 1 ) > ht->data_len ) {
239 while ( ht->data[i] != NULL && ht->data[i] !=
DEL ) {
242 if ( ht->data[i] == NULL ) {
265 if ( ht->data_len > 0 ) {
267 while ( ht->data[i] != NULL ) {
272 if ( 8*ht->n < ht->data_len ) {
302 if ( ht->dtor != NULL ) {
static size_t hash(const char *s)
static int hashtbl_no_param_cmp(void *param, const void *x, const void *y)
static int hashtbl_resize(LALHashTbl *ht)
static UINT8 hashtbl_no_param_hash(void *param, const void *x)
static const void * hash_del
static int cmp(REAL4Sequence *a, REAL4Sequence *b)
uint64_t UINT8
Eight-byte unsigned integer; on some platforms this is equivalent to unsigned long int instead.
int XLALHashTblFind(const LALHashTbl *ht, const void *x, const void **y)
Find the element matching x in a hash table; if found, return in *y
LALHashTbl * XLALHashTblCreate2(LALHashTblDtorFcn dtor, LALHashTblHashParamFcn hash, void *hash_param, LALHashTblCmpParamFcn cmp, void *cmp_param)
Create a hash table with parameterised hash and comparison functions.
void(* LALHashTblDtorFcn)(void *x)
Function which free memory associated with hash table element x
UINT8(* LALHashTblHashParamFcn)(void *param, const void *x)
Hash function for the hash table element x, with a parameter param.
LALHashTbl * XLALHashTblCreate(LALHashTblDtorFcn dtor, LALHashTblHashFcn hash, LALHashTblCmpFcn cmp)
Create a hash table.
int(* LALHashTblCmpParamFcn)(void *param, const void *x, const void *y)
Function which compares hash table elements x and y, with a parameter param.
int XLALHashTblSize(const LALHashTbl *ht)
Return the size of a hash table.
int XLALHashTblAdd(LALHashTbl *ht, void *x)
Add an element to a hash table.
UINT8(* LALHashTblHashFcn)(const void *x)
Hash function for the hash table element x
int XLALHashTblExtract(LALHashTbl *ht, const void *x, void **y)
Find the element matching x in a hash table; if found, remove it and return in *y
int XLALHashTblRemove(LALHashTbl *ht, const void *x)
Find the element matching x in a hash table; if found, remove and destroy it.
void XLALHashTblDestroy(LALHashTbl *ht)
Destroy a hash table and its elements.
int XLALHashTblClear(LALHashTbl *ht)
Clear a hash table.
int(* LALHashTblCmpFcn)(const void *x, const void *y)
Function which compares hash table elements x and y
#define XLAL_CHECK(assertion,...)
Macro to test an assertion and invoke a failure if it is not true in a function that returns an integ...
#define XLAL_CHECK_NULL(assertion,...)
Macro to test an assertion and invoke a failure if it is not true in a function that returns a pointe...
@ XLAL_ENOMEM
Memory allocation error.
@ XLAL_SUCCESS
Success return value (not an error number)
@ XLAL_EFAULT
Invalid pointer.
@ XLAL_EFUNC
Internal function call failed bit: "or" this with existing error number.
@ XLAL_EINVAL
Invalid argument.
@ XLAL_EFAILED
Generic failure.
Generic hash table with elements of type void *
LALHashTblHashParamFcn hash
LALHashTblCmpParamFcn cmp