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_uppercase (char chr);
|
||||||
bool string_is_char_lowercase (char chr);
|
bool string_is_char_lowercase (char chr);
|
||||||
|
|
||||||
|
uint32_t string_hash_djb (string_t str);
|
||||||
|
|
||||||
#endif //NOX_STRING_H
|
#endif //NOX_STRING_H
|
||||||
|
|
|
@ -462,4 +462,14 @@ bool string_is_char_lowercase (char chr) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
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