The qDecoder Project

qHashtbl.c File Reference

Hash-table Data Structure API. More…


Functions

Q_HASHTBLqHashtblInit (int max)
 Initialize dynamic-hash table.
bool qHashtblFree (Q_HASHTBL *tbl)
 De-allocate hash table.
bool qHashtblPut (Q_HASHTBL *tbl, const char *key, const void *value, int size)
 Put object into hash table.
bool qHashtblPutStr (Q_HASHTBL *tbl, const char *key, const char *value)
 Put string into hash table.
bool qHashtblPutInt (Q_HASHTBL *tbl, const char *key, const int value)
 Put integer into hash table.
void * qHashtblGet (Q_HASHTBL *tbl, const char *key, int *size)
 Get object from hash table.
char * qHashtblGetStr (Q_HASHTBL *tbl, const char *key)
 Get string from hash table.
int qHashtblGetInt (Q_HASHTBL *tbl, const char *key)
 Get integer from hash table.
const char * qHashtblGetFirstKey (Q_HASHTBL *tbl, int *idx)
 Get first key name.
const char * qHashtblGetNextKey (Q_HASHTBL *tbl, int *idx)
 Get next key name.
bool qHashtblRemove (Q_HASHTBL *tbl, const char *key)
 Remove key from hash table.
bool qHashtblPrint (Q_HASHTBL *tbl, FILE *out, bool showvalue)
 Print hash table for debugging purpose.
bool qHashtblStatus (Q_HASHTBL *tbl, int *used, int *max)
 Get hash table internal status.


Detailed Description

Hash-table Data Structure API.


Function Documentation

Q_HASHTBL* qHashtblInit ( int  max  ) 

Initialize dynamic-hash table.

Parameters:
max a number of maximum size of Q_HASHARR
Returns:
a pointer of malloced Q_HASHTBL, otherwise returns false
   Q_HASHTBL *hashtbl = qHashtblInit(1000);
   qHashtblFree(hashtbl);

bool qHashtblFree ( Q_HASHTBL tbl  ) 

De-allocate hash table.

Parameters:
tbl a pointer of Q_HASHTBL
Returns:
true if successful, otherwise returns false

bool qHashtblPut ( Q_HASHTBL tbl,
const char *  key,
const void *  value,
int  size 
)

Put object into hash table.

Parameters:
tbl a pointer of Q_HASHTBL
key key string
value value object data
size size of value
Returns:
true if successful, otherwise returns false

bool qHashtblPutStr ( Q_HASHTBL tbl,
const char *  key,
const char *  value 
)

Put string into hash table.

Parameters:
tbl a pointer of Q_HASHTBL
key key string
value value string
Returns:
true if successful, otherwise returns false

bool qHashtblPutInt ( Q_HASHTBL tbl,
const char *  key,
const int  value 
)

Put integer into hash table.

Parameters:
tbl a pointer of Q_HASHTBL
key key string
value value integer
Returns:
true if successful, otherwise returns false

void* qHashtblGet ( Q_HASHTBL tbl,
const char *  key,
int *  size 
)

Get object from hash table.

Parameters:
tbl a pointer of Q_HASHTBL
key key string
size if not NULL, oject size will be stored
Returns:
malloced object pointer if successful, otherwise(not found) returns NULL
Note:
returned object must be freed after done using.

char* qHashtblGetStr ( Q_HASHTBL tbl,
const char *  key 
)

Get string from hash table.

Parameters:
tbl a pointer of Q_HASHTBL
key key string
Returns:
string pointer if successful, otherwise(not found) returns NULL
Note:
returned object must be freed after done using.

int qHashtblGetInt ( Q_HASHTBL tbl,
const char *  key 
)

Get integer from hash table.

Parameters:
tbl a pointer of Q_HASHARR
key key string
Returns:
value integer if successful, otherwise(not found) returns 0

const char* qHashtblGetFirstKey ( Q_HASHTBL tbl,
int *  idx 
)

Get first key name.

Parameters:
tbl a pointer of Q_HASHTBL
idx index pointer
Returns:
key name string if successful, otherwise returns NULL
Note:
Do not free returned key string.
   char *key;
   int idx;
   for(key = qHashtblGetFirstKey(tbl, &idx); key != NULL; key = qHashtblGetNextKey(tbl, &idx) {
     char *value = qHashtblGetStr(tbl, key);
     if(value != NULL) free(value);
   }

const char* qHashtblGetNextKey ( Q_HASHTBL tbl,
int *  idx 
)

Get next key name.

Parameters:
tbl a pointer of Q_HASHTBL
idx index pointer
Returns:
key name string if successful, otherwise(end of table) returns NULL
Note:
Do not free returned key string.

bool qHashtblRemove ( Q_HASHTBL tbl,
const char *  key 
)

Remove key from hash table.

Parameters:
tbl a pointer of Q_HASHTBL
key key string
Returns:
true if successful, otherwise(not found) returns false

bool qHashtblPrint ( Q_HASHTBL tbl,
FILE *  out,
bool  showvalue 
)

Print hash table for debugging purpose.

Parameters:
tbl a pointer of Q_HASHTBL
out output stream
showvalue print out value if set to true
Returns:
true if successful, otherwise returns false

bool qHashtblStatus ( Q_HASHTBL tbl,
int *  used,
int *  max 
)

Get hash table internal status.

Parameters:
tbl a pointer of Q_HASHARR
used if not NULL, a number of used keys will be stored
max if not NULL, the maximum usable number of keys will be stored
Returns:
true if successful, otherwise returns false


[Home] [About] [Examples] [Changes] [Download] [SVN Repository] [Install] [Reference]