Skip to content

Commit a4df5cf

Browse files
committed
1-djb2.c
1 parent 4cde866 commit a4df5cf

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

0x1A-hash_tables/1-djb2.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "hash_tables.h"
2+
3+
/**
4+
* hash_djb2 - Hash function implementing the djb2 algorithm.
5+
* @str: The string to hash.
6+
*
7+
* Return: The calculated hash.
8+
*/
9+
unsigned long int hash_djb2(const unsigned char *str)
10+
{
11+
unsigned long int hash;
12+
int c;
13+
14+
hash = 5381;
15+
while ((c = *str++))
16+
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
17+
18+
return (hash);
19+
}

0 commit comments

Comments
 (0)