Site hosted by Angelfire.com: Build your free website today!

(c) 2002 - Pedro Flynn <pflynn@microsoftsucks.org>

CHTable


typedef struct
_CHTable {
    LList** llists;
    int size;
    int buckets;
    comparefunc* cmp;
    destroyfunc* destroy;
    hashfunc* hash;
} CHTable;


    The CHTable data structure represents a chained hash table.


Related functions and macros



CHTable* chtable_create(destroyfunc* destroy, comparefunc* cmp, hashfunc* hash, int buckets)

description: creates a new, empty chained hashtable. The destroy parameter is a pointer to a user-defined destroyfunc. This function'll be used by chtable_destroy to free dynamically allocated data. If the data to be inserted in the table should not be freed, destroy should be set to NULL. The cmp parameter is a valid pointer to a user-defined comparefunc. This function'll be used by the table to compare keys. The hash parameter is a valid pointer to a user-defined hashfunc. This function will be used by the table for hashing keys. The buckets parameter is the number of buckets allocated in the table.

return value: a pointer to a new CHTable data structure, or NULL if the allocation fails.

since:
YACLib 1.0

int chtable_insert(CHTable* chtable, const void* data)

description: Inserts an element into the chained hash table specified by chtable. The new element stores a pointer to data.

return value:
0 if the element could be inserted, -1 otherwise.

since: YACLib 1.0
int chtable_remove(CHTable* chtable, const void* key, void** keyptr)

description: removes an element matching key from the chained hash table specified by chtable. Upon return, keyptr points to the data stored in the element that was removed.

return value:
0 if the element could be removed, -1 otherwise.

since: YACLib 1.0
int chtable_remove_all(CHTable* chtable)

description: removes all elements from the chained hash table specified by chtable.

return value:
0 if the elements could be removed, -1 otherwise.

since:
YACLib 1.0
int chtable_lookup(const CHTable* chtable,const void* key,void** keyptr)

description: searches for an element matching key in the chained hash table specified by chtable. Upon return, keyptr points to the data stored in the element found.

return value:
0 if the element could be found, -1 otherwise.

since:
YACLib 1.0
void chtable_destroy(CHTable* chtable)

description: destroys the chained hash table specified by chtable, removing all the elements from the table and calling the destroyfunc passed to chtable_create for each element as it is removed, provided the destroyfunc wasn's set to NULL.

return value:
none.

since: YACLib 1.0
int chtable_size(const CHTable* chtable)

description: macro that evaluates to the number of elements stored in the chained hash table specified by chtable.

return value:
the number of elements stored in chtable.

since:
YACLib 1.0
int chtable_buckets(const CHTable* chtable)

description: macro that evaluates to the number of buckets allocated by the chained hash table specified by chtable.

returns:
the number of buckets allocated by chtable.

since: YACLib 1.0