diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2012-12-19 05:49:58 +0400 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2012-12-19 05:49:58 +0400 |
commit | d433cd65f7127d60e17d05a824290423ad226eae (patch) | |
tree | f0a9c821f6046e97b74c6969d41269b558fd52ab /source/blender/blenlib/intern/BLI_ghash.c | |
parent | 10f0f66560234a04aed3295c74fff20adacbc57f (diff) | |
parent | f10dea7e3b9b431edae9c787fa1a9e09cd567ed7 (diff) |
Merged changes in the trunk up to revision 53146.
Conflicts resolved:
release/datafiles/startup.blend
source/blender/blenkernel/CMakeLists.txt
source/blender/blenlib/intern/bpath.c
source/blender/blenloader/intern/readfile.c
Diffstat (limited to 'source/blender/blenlib/intern/BLI_ghash.c')
-rw-r--r-- | source/blender/blenlib/intern/BLI_ghash.c | 23 |
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); } - |