feature (strings): implemented DJB string hashing function

This commit is contained in:
antifallobst 2023-06-05 17:41:34 +02:00
parent e69065f889
commit 83f5e77d52
2 changed files with 13 additions and 1 deletions

View File

@ -57,4 +57,6 @@ bool string_is_char_alpha (char chr);
bool string_is_char_uppercase (char chr);
bool string_is_char_lowercase (char chr);
uint32_t string_hash_djb (string_t str);
#endif //NOX_STRING_H

View File

@ -463,3 +463,13 @@ bool string_is_char_lowercase (char chr) {
}
return false;
}
uint32_t string_hash_djb(string_t str) {
uint32_t hash = 5381;
while (*(++str) != '\0') {
hash = ((hash << 5) + hash) + (*str);
}
return hash;
}