experiment with slower but better hashes

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@36344 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2013-03-12 16:11:10 +00:00
parent da1e4a48e2
commit d314f0f843
7 changed files with 429 additions and 79 deletions

View file

@ -376,34 +376,6 @@ GSPrivateIsByteEncoding(NSStringEncoding encoding) GS_ATTRIB_PRIVATE;
BOOL
GSPrivateIsEncodingSupported(NSStringEncoding encoding) GS_ATTRIB_PRIVATE;
/* Hash function to hash up to limit bytes from data of specified length.
* If the flag is NO then a result of 0 is mapped to 0xffffffff.
* This is a pretty useful general purpose hash function.
*/
static inline unsigned
GSPrivateHash(const void *data, unsigned length, unsigned limit, BOOL zero)
__attribute__((unused));
static inline unsigned
GSPrivateHash(const void *data, unsigned length, unsigned limit, BOOL zero)
{
unsigned ret = length;
unsigned l = length;
if (limit < length)
{
l = limit;
}
while (l-- > 0)
{
ret = (ret << 5) + ret + ((const unsigned char*)data)[l];
}
if (ret == 0 && zero == NO)
{
ret = 0xffffffff;
}
return ret;
}
/* load a module into the runtime
*/
long
@ -543,5 +515,28 @@ GSPrivateIsCollectable(const void *ptr) GS_ATTRIB_PRIVATE;
NSZone*
GSAtomicMallocZone (void);
/* Generate a 32bit hash from supplied byte data.
*/
uint32_t
GSPrivateHash(uint32_t seed, const void *bytes, int length)
GS_ATTRIB_PRIVATE;
/* Incorporate 'l' bytes of data from the buffer pointed to by 'b' into
* the hash state information pointed to by p0 and p1.
* The hash state variables should have been initialised to zero before
* the first call to this function, and the result should be produced
* by calling the GSPrivateFinishHash() function.
*/
void
GSPrivateIncrementalHash(uint32_t *p0, uint32_t *p1, const void *b, int l)
GS_ATTRIB_PRIVATE;
/* Generate a 32bit hash from supplied state variables resulting from
* calls to the GSPrivateIncrementalHash() function.
*/
uint32_t
GSPrivateFinishHash(uint32_t s0, uint32_t s1, uint32_t totalLength)
GS_ATTRIB_PRIVATE;
#endif /* _GSPrivate_h_ */