Week06 Lab Notes
A new phrase: Vibe Coding
Ex1 HashMap
You can use the DJB2 hash function (provided in Ex2), which is suitable fro strings.
// Hash function using DJB2 algorithm
unsigned long hashFunction(char *str)
{
unsigned long hash = 5381; // a prime
int c;
while ((c = *str++))
{
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
}
return hash % HASH_TABLE_SIZE;
}
Ex2 A simple blockchain
How to calculate the hash for a block?
Convert name, age, and previous hash into a string using sprintf() followed by a DJB2 hash.
Last updated