Merge pull request #2497 from erwincoumans/master
tweak hash function (sdf)
This commit is contained in:
@@ -20,27 +20,38 @@ subject to the following restrictions:
|
|||||||
#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
|
#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
|
||||||
#include "BulletCollision/NarrowPhaseCollision/btGjkEpa2.h"
|
#include "BulletCollision/NarrowPhaseCollision/btGjkEpa2.h"
|
||||||
|
|
||||||
// Modified Paul Hsieh hash
|
// Fast Hash
|
||||||
template <const int DWORDLEN>
|
|
||||||
unsigned int HsiehHash(const void* pdata)
|
#if !defined (get16bits)
|
||||||
{
|
#define get16bits(d) ((((unsigned int)(((const unsigned char *)(d))[1])) << 8)\
|
||||||
const unsigned short* data = (const unsigned short*)pdata;
|
+(unsigned int)(((const unsigned char *)(d))[0]) )
|
||||||
unsigned hash = DWORDLEN << 2, tmp;
|
#endif
|
||||||
for (int i = 0; i < DWORDLEN; ++i)
|
//
|
||||||
{
|
// super hash function by Paul Hsieh
|
||||||
hash += data[0];
|
//
|
||||||
tmp = (data[1] << 11) ^ hash;
|
inline unsigned int HsiehHash (const char * data, int len) {
|
||||||
hash = (hash << 16) ^ tmp;
|
unsigned int hash = len, tmp;
|
||||||
data += 2;
|
len>>=2;
|
||||||
hash += hash >> 11;
|
|
||||||
}
|
/* Main loop */
|
||||||
hash ^= hash << 3;
|
for (;len > 0; len--) {
|
||||||
hash += hash >> 5;
|
hash += get16bits (data);
|
||||||
hash ^= hash << 4;
|
tmp = (get16bits (data+2) << 11) ^ hash;
|
||||||
hash += hash >> 17;
|
hash = (hash << 16) ^ tmp;
|
||||||
hash ^= hash << 25;
|
data += 2*sizeof (unsigned short);
|
||||||
hash += hash >> 6;
|
hash += hash >> 11;
|
||||||
return (hash);
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Force "avalanching" of final 127 bits */
|
||||||
|
hash ^= hash << 3;
|
||||||
|
hash += hash >> 5;
|
||||||
|
hash ^= hash << 4;
|
||||||
|
hash += hash >> 17;
|
||||||
|
hash ^= hash << 25;
|
||||||
|
hash += hash >> 6;
|
||||||
|
|
||||||
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <const int CELLSIZE>
|
template <const int CELLSIZE>
|
||||||
@@ -209,6 +220,9 @@ struct btSparseSdf
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// printf("c->hash/c[0][1][2]=%d,%d,%d,%d\n", c->hash, c->c[0], c->c[1],c->c[2]);
|
||||||
|
//printf("h,ixb,iyb,izb=%d,%d,%d,%d\n", h,ix.b, iy.b, iz.b);
|
||||||
|
|
||||||
c = c->next;
|
c = c->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -334,22 +348,22 @@ struct btSparseSdf
|
|||||||
{
|
{
|
||||||
struct btS
|
struct btS
|
||||||
{
|
{
|
||||||
int x, y, z, w;
|
int x, y, z,w;
|
||||||
void* p;
|
void* p;
|
||||||
};
|
};
|
||||||
|
|
||||||
btS myset;
|
btS myset;
|
||||||
//memset may be needed in case of additional (uninitialized) padding!
|
//memset may be needed in case of additional (uninitialized) padding!
|
||||||
//memset(myset, 0, sizeof(btS));
|
//memset(&myset, 0, sizeof(btS));
|
||||||
|
|
||||||
myset.x = x;
|
myset.x = x;
|
||||||
myset.y = y;
|
myset.y = y;
|
||||||
myset.z = z;
|
myset.z = z;
|
||||||
myset.w = 0;
|
myset.w = 0;
|
||||||
myset.p = (void*)shape;
|
myset.p = (void*)shape;
|
||||||
const void* ptr = &myset;
|
const char* ptr = (const char*)&myset;
|
||||||
|
|
||||||
unsigned int result = HsiehHash<sizeof(btS) / 4>(ptr);
|
unsigned int result = HsiehHash(ptr, sizeof(btS) );
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user