From 2fdd1d9ef18ba45b507e94c40ebc85510f830e00 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Tue, 19 Nov 2013 15:08:34 +0100 Subject: [PATCH] khash: Move string hash functions to own header/source file Unlike khash they shouldn't be phased out (only renamed). --- headers/private/kernel/util/StringHash.h | 29 ++++++++++++++++ headers/private/kernel/util/khash.h | 6 ++-- src/system/kernel/util/StringHash.cpp | 44 ++++++++++++++++++++++++ src/system/kernel/util/khash.cpp | 34 ------------------ 4 files changed, 75 insertions(+), 38 deletions(-) create mode 100644 headers/private/kernel/util/StringHash.h create mode 100644 src/system/kernel/util/StringHash.cpp diff --git a/headers/private/kernel/util/StringHash.h b/headers/private/kernel/util/StringHash.h new file mode 100644 index 0000000000..29be9b34c3 --- /dev/null +++ b/headers/private/kernel/util/StringHash.h @@ -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 + + +#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 */ diff --git a/headers/private/kernel/util/khash.h b/headers/private/kernel/util/khash.h index d1f54682cf..ae1b71fd5a 100644 --- a/headers/private/kernel/util/khash.h +++ b/headers/private/kernel/util/khash.h @@ -9,7 +9,8 @@ #define _KERNEL_UTIL_KHASH_H -#include +#include + // 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 diff --git a/src/system/kernel/util/StringHash.cpp b/src/system/kernel/util/StringHash.cpp new file mode 100644 index 0000000000..ed8bd258bc --- /dev/null +++ b/src/system/kernel/util/StringHash.cpp @@ -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 + + +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; +} diff --git a/src/system/kernel/util/khash.cpp b/src/system/kernel/util/khash.cpp index e52d88b94d..4b626ee3f1 100644 --- a/src/system/kernel/util/khash.cpp +++ b/src/system/kernel/util/khash.cpp @@ -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) {