Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenlib/intern/BLI_ghash.c')
-rw-r--r--source/blender/blenlib/intern/BLI_ghash.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c
index c4094920c2a..7d2fc38272d 100644
--- a/source/blender/blenlib/intern/BLI_ghash.c
+++ b/source/blender/blenlib/intern/BLI_ghash.c
@@ -39,7 +39,7 @@
#include "BLI_mempool.h"
#include "BLI_ghash.h"
-#include "BLO_sys_types.h" // for intptr_t support
+#include "MEM_sys_types.h" /* for intptr_t support */
/***/
unsigned int hashsizes[] = {
@@ -312,17 +312,25 @@ int BLI_ghashutil_intcmp(const void *a, const void *b)
return (a < b) ? -1 : 1;
}
+/**
+ * This function implements the widely used "djb" hash apparently posted
+ * by Daniel Bernstein to comp.lang.c some time ago. The 32 bit
+ * unsigned hash value starts at 5381 and for each byte 'c' in the
+ * string, is updated: <literal>hash = hash * 33 + c</literal>. This
+ * function uses the signed value of each byte.
+ *
+ * note: this is the same hash method that glib 2.34.0 uses.
+ */
unsigned int BLI_ghashutil_strhash(const void *ptr)
{
- const char *s = ptr;
- unsigned int i = 0;
- unsigned char c;
+ const signed char *p;
+ unsigned int h = 5381;
- while ((c = *s++)) {
- i = i * 37 + c;
+ for (p = ptr; *p != '\0'; p++) {
+ h = (h << 5) + h + *p;
}
- return i;
+ return h;
}
int BLI_ghashutil_strcmp(const void *a, const void *b)
{
@@ -376,4 +384,3 @@ void BLI_ghashutil_pairfree(void *ptr)
{
MEM_freeN((void *)ptr);
}
-