diff --git a/headers/private/kernel/util/khash.h b/headers/private/kernel/util/khash.h index 99db5b5e82..d1f54682cf 100644 --- a/headers/private/kernel/util/khash.h +++ b/headers/private/kernel/util/khash.h @@ -60,7 +60,8 @@ void hash_dump_table(struct hash_table* table); * the key, returning 0 if equal, other if not */ -uint32 hash_hash_string(const char *str); +uint32 hash_hash_string(const char *string); +uint32 hash_hash_string_part(const char *string, size_t maxLength); #ifdef __cplusplus } diff --git a/src/system/kernel/util/khash.cpp b/src/system/kernel/util/khash.cpp index b3bdd53a9f..e52d88b94d 100644 --- a/src/system/kernel/util/khash.cpp +++ b/src/system/kernel/util/khash.cpp @@ -398,6 +398,23 @@ hash_hash_string(const char *string) } +uint32 +hash_hash_string_part(const char *string, size_t maxLength) +{ + uint32 hash = 0; + char c; + + // we assume hash to be at least 32 bits + while (maxLength-- > 0 && (c = *string++) != 0) { + hash ^= hash >> 28; + hash <<= 4; + hash ^= c; + } + + return hash; +} + + uint32 hash_count_elements(struct hash_table *table) {