HashTable* _hashtable_new(size_t dataSize, size_t hashSize)
{
- HashTable* hashTable = (HashTable*) safe_malloc(sizeof (HashTable));
+ HashTable* hashTable = (HashTable*) safe_malloc(sizeof(HashTable));
_hashtable_init(hashTable, dataSize, hashSize);
return hashTable;
}
while (cell != NULL)
{
// cellCopy == NULL (from empty list)
- cellCopy = (HashCell*) safe_malloc(sizeof(HashCell*));
+ cellCopy = (HashCell*) safe_malloc(sizeof(HashCell));
cellCopy->key = (char*) safe_malloc(strlen(cell->key) + 1);
strcpy(cellCopy->key, cell->key);
cellCopy->data = safe_malloc(hashTable->dataSize);
UInt res = 0;
for (unsigned char* s = key; *s != '\0'; s++)
// NOTE: '31' from here https://stackoverflow.com/a/4384446
- res += *s + 31 * res;
- return res % hashSize;
+ res = (*s + 31 * res) % hashSize;
+ return res;
}
void* _hashtable_get(HashTable* hashTable, char* key)
HashCell* cell = hashTable->head[hashIdx];
while (cell != NULL)
{
- if (strcmp(cell->key, key) == 0) return cell->data;
+ if (strcmp(cell->key, key) == 0)
+ return cell->data;
cell = cell->next;
}
return NULL;