feature (strings): implemented DJB string hashing function
This commit is contained in:
parent
e69065f889
commit
83f5e77d52
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue