/*>>>> Return data pointer for specified key <<<<*/
/* Main interface to store and retrieve AA data */
void *aa_addr(aa,key)
AA * aa; /* input -- AA definition */
void *key; /* input -- lookup key */
{
int index;
void **keyptr, **dataptr;
if (TOO_FULL(aa->current_elements,aa->max_elements))
if (!aa_resize(aa,INC_SIZE(aa->max_elements)))
fprintf(stderr,"AA: resize failed\n");
index=hashindex(aa,key); /* index for key & data */
keyptr=&aa->keys[index];
dataptr=&aa->data[index];
if (!VALID_KEY(*keyptr)) { /* if key not in table */
/* allocate key & data memory; copy/define key */
*keyptr=(void *)malloc(KEYSIZE(aa,key));
*dataptr=(void *)calloc(aa->data_size,1);
if (keyptr && dataptr) { /* if allocation ok */
KEYCOPY (aa, keyptr, key);
aa->current_elements++;
} else { /* allocation failed */
fprintf(stderr,"AA: key allocation failed\n");
fflush(stderr); /* probably will crash soon */
}
}
return(*dataptr); /* return pointer to data area */
}
/* End of File */