CITS2002-labs/Week 8-workshop/hashstring.c

18 lines
364 B
C
Raw Permalink Normal View History

#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;
}