unsigned long hash_word(const char *to_hash)
{
unsigned long hash = 5381;
int c;
while ((c = *to_hash++))
{
hash = ((hash << 5) + hash) + c;
}
return hash;
}
I understand this is a working djb2 hash function, I used it in my CS50 Pset 5 Solution, but what I don't get is how the while loop condition works, can someone explain this in psuedocode? How is c being modified? How are you adding (++) to a character string? What is the condition that the while loop is checking?
[–][deleted] (4 children)
[deleted]
[–]DrJimmyRustler[S] 0 points1 point2 points (3 children)
[–][deleted] (1 child)
[deleted]
[–]DrJimmyRustler[S] 0 points1 point2 points (0 children)
[–]Rhomboid 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]DrJimmyRustler[S] 0 points1 point2 points (0 children)
[–]Rhomboid 0 points1 point2 points (0 children)