diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-08-25 00:30:08 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-08-25 00:30:08 +0400 |
commit | 150af65d9f4794a3397dabb307c37d42607ec07a (patch) | |
tree | 372e74d1ba67ad199ba9ac9a3e4dbaecf7bd15c1 /source/blender/blenlib/intern | |
parent | 7c65015ab84360f7e029a5495324a595fec3eee1 (diff) |
For pointer hashing use the same method as python, it gives better distribution.
some tests with high poly mesh data in hashes.
- empty buckets before 4-5%, after 1-2%
- speedup for hash lookups, in my tests lookups take approx ~60% of the time they did before.
Diffstat (limited to 'source/blender/blenlib/intern')
-rw-r--r-- | source/blender/blenlib/intern/BLI_ghash.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c index 1ae3ac18f24..918fc55df72 100644 --- a/source/blender/blenlib/intern/BLI_ghash.c +++ b/source/blender/blenlib/intern/BLI_ghash.c @@ -408,10 +408,23 @@ bool BLI_ghashIterator_done(GHashIterator *ghi) /***/ +#if 0 +/* works but slower */ unsigned int BLI_ghashutil_ptrhash(const void *key) { return (unsigned int)(intptr_t)key; } +#else +/* based python3.3's pointer hashing function */ +unsigned int BLI_ghashutil_ptrhash(const void *key) +{ + size_t y = (size_t)key; + /* bottom 3 or 4 bits are likely to be 0; rotate y by 4 to avoid + * excessive hash collisions for dicts and sets */ + y = (y >> 4) | (y << (8 * sizeof(void *) - 4)); + return (unsigned int)y; +} +#endif int BLI_ghashutil_ptrcmp(const void *a, const void *b) { if (a == b) |