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