mirror of
https://github.com/peter-tanner/Systems-programming-labs.git
synced 2024-11-30 09:00:30 +08:00
18 lines
364 B
C
18 lines
364 B
C
#include "hashstring.h"
|
|
|
|
// FUNCTION hash_string() ACCEPTS A STRING PARAMETER,
|
|
// AND RETURNS AN UNSIGNED 32-BIT INTEGER AS ITS RESULT
|
|
//
|
|
// see: https://en.cppreference.com/w/c/types/integer
|
|
|
|
uint32_t hash_string(char *string)
|
|
{
|
|
uint32_t hash = 0;
|
|
|
|
while(*string != '\0') {
|
|
hash = hash*33 + *string;
|
|
++string;
|
|
}
|
|
return hash;
|
|
}
|