util/khash: Add hash_hash_string_part()
This commit is contained in:
parent
1e7416d9b3
commit
1848fdc329
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user