BString, HashString: Replace string hashes with hashdjb2.

This commit is contained in:
Augustin Cavalier
2024-09-09 13:39:29 -04:00
parent e9254dd79c
commit 67c0b8f2d1
2 changed files with 25 additions and 30 deletions
+15 -18
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2004-2007, Ingo Weinhold, [email protected]. All rights reserved.
* Copyright 2004-2007, Ingo Weinhold <[email protected]>. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef HASH_STRING_H
@@ -7,29 +7,25 @@
#include <SupportDefs.h>
// string_hash
//
// from the Dragon Book: a slightly modified hashpjw()
static inline
uint32
string_hash(const char *name)
static inline uint32
string_hash(const char *_string)
{
uint32 h = 0;
if (name) {
for (; *name; name++) {
uint32 g = h & 0xf0000000;
if (g)
h ^= g >> 24;
h = (h << 4) + *name;
}
}
const uint8* string = (const uint8*)_string;
if (string == NULL)
return 0;
uint32 h = 5381;
char c;
while ((c = *string++) != 0)
h = (h * 33) + c;
return h;
}
#ifdef __cplusplus
namespace BPrivate {
// HashString
class HashString {
public:
@@ -60,10 +56,11 @@ private:
char *fString;
};
} // namespace BPrivate
using BPrivate::HashString;
#endif // __cplusplus
#endif // HASH_STRING_H