void* hashtab_lookup(hashtab_t* htab, char* key) { return hashtab_lookup_with_hash( htab, key, hashtab_hash(key, htab->nbuck)); }
void hashtab_pseudo_delete(hashtab_t *htab, char* key) { int hash = hashtab_hash(key, htab->nbuck); hashtab_entry_t *ptr = htab->buck[hash]; while (ptr) if (!strcmp(ptr->key, key)) break; else ptr = ptr->next; if (ptr && !strcmp(ptr->key, key)) *(ptr->key) = 0; }
void hashtab_insert(hashtab_t* htab, char* key, void* val) { unsigned int hash = hashtab_hash(key, htab->nbuck); hashtab_entry_t **ptr = &(htab->buck[hash]); while (*ptr) ptr = &((*ptr)->next); *ptr = malloc(sizeof(hashtab_entry_t)); if (!*ptr) fail("couldn't create a hash table bucket node"); (*ptr)->key = malloc(strlen(key) + 1); if (!((*ptr)->key)) fail("couldn't allocate a string"); strcpy((*ptr)->key, key); (*ptr)->val = val; (*ptr)->next = NULL; }