// Search for an address for a given oid
void *chashSearch(chashtable_t *table, unsigned int key) {
- int index;
- chashlistnode_t *ptr, *node;
+ int index = chashFunction(table, key);
+ chashlistnode_t *ptr =table -> table;
+ chashlistnode_t *node = &ptr[index];
- ptr = table->table;
- index = chashFunction(table, key);
- node = &ptr[index];
while(node != NULL) {
if(node->key == key) {
return node->val;
}
//Delete the entire hash table
-void chashDelete(chashtable_t *table) {
+void chashDelete(chashtable_t *ctable) {
int i, isFirst;
chashlistnode_t *ptr, *curr, *next;
- ptr = table->table;
+ ptr = ctable->table;
- for(i=0 ; i<table->size ; i++) {
+ for(i=0 ; i<ctable->size ; i++) {
curr = &ptr[i];
isFirst = 1 ;
while(curr != NULL) {
}
free(ptr);
- free(table);
- table = NULL;
+ ptr = NULL;
+ free(ctable);
+ ctable = NULL;
}