Remove assumption that node is in the bottom of the bucket.

This is the last remaining instance of this assumption.
This commit is contained in:
Payton Turnage 2014-01-14 00:51:42 -05:00
parent e6d9d92d8c
commit 27a090e704

View file

@ -127,8 +127,19 @@ int htab_add(tvm_htab_t *htab, const char *k, int v)
int htab_add_str(tvm_htab_t *htab, const char *key, const void *valptr, int len)
{
int hash = htab_add(htab, key, 0);
htab->nodes[hash]->valptr = calloc(len, sizeof(char));
memcpy(htab->nodes[hash]->valptr, valptr, len);
int found = 0;
tvm_htab_node_t *node = htab->nodes[hash];
while (node && !found)
{
if (!strcmp(node->key, key))
found = 1;
else
node = node->next;
}
node->valptr = calloc(len, sizeof(char));
memcpy(node->valptr, valptr, len);
return hash;
}