khash: Move string hash functions to own header/source file

Unlike khash they shouldn't be phased out (only renamed).
This commit is contained in:
Ingo Weinhold 2013-11-19 15:08:34 +01:00
parent efe9df3791
commit 2fdd1d9ef1
4 changed files with 75 additions and 38 deletions

View File

@ -0,0 +1,29 @@
/*
* Copyright 2002-2013, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
* Distributed under the terms of the NewOS License.
*/
#ifndef _KERNEL_UTIL_STRING_HASH_H
#define _KERNEL_UTIL_STRING_HASH_H
#include <SupportDefs.h>
#ifdef __cplusplus
extern "C" {
#endif
uint32 hash_hash_string(const char* string);
uint32 hash_hash_string_part(const char* string, size_t maxLength);
#ifdef __cplusplus
}
#endif
#endif /* _KERNEL_UTIL_STRING_HASH_H */

View File

@ -9,7 +9,8 @@
#define _KERNEL_UTIL_KHASH_H
#include <SupportDefs.h>
#include <util/StringHash.h>
// The use of offsetof() on non-PODs is invalid. Since many structs use
// templated members (i.e. DoublyLinkedList) which makes them non-PODs we
@ -60,9 +61,6 @@ void hash_dump_table(struct hash_table* table);
* the key, returning 0 if equal, other if not
*/
uint32 hash_hash_string(const char *string);
uint32 hash_hash_string_part(const char *string, size_t maxLength);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,44 @@
/*
* Copyright 2002-2013, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Copyright 2001, Travis Geiselbrecht. All rights reserved.
* Distributed under the terms of the NewOS License.
*/
#include <util/StringHash.h>
uint32
hash_hash_string(const char* string)
{
uint32 hash = 0;
char c;
// we assume hash to be at least 32 bits
while ((c = *string++) != 0) {
hash ^= hash >> 28;
hash <<= 4;
hash ^= c;
}
return hash;
}
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;
}

View File

@ -381,40 +381,6 @@ restart:
}
uint32
hash_hash_string(const char *string)
{
uint32 hash = 0;
char c;
// we assume hash to be at least 32 bits
while ((c = *string++) != 0) {
hash ^= hash >> 28;
hash <<= 4;
hash ^= c;
}
return hash;
}
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)
{