2009-08-23 02:36:43 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
2010-07-30 18:54:48 -07:00
|
|
|
#endif /* ifdef HAVE_CONFIG_H */
|
2009-08-23 02:36:43 -07:00
|
|
|
|
2007-09-25 11:26:49 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
2008-04-03 12:30:18 -07:00
|
|
|
#include "Eet.h"
|
|
|
|
#include "Eet_private.h"
|
|
|
|
|
2006-12-28 07:23:47 -08:00
|
|
|
int
|
2010-07-31 11:54:54 -07:00
|
|
|
_eet_hash_gen(const char *key,
|
|
|
|
int hash_size)
|
2006-12-28 07:23:47 -08:00
|
|
|
{
|
2010-07-27 18:45:57 -07:00
|
|
|
int hash_num = 0;
|
|
|
|
int value, i;
|
|
|
|
int mask;
|
2010-07-31 11:54:54 -07:00
|
|
|
unsigned char *ptr;
|
2008-03-07 23:28:12 -08:00
|
|
|
|
2006-12-28 07:23:47 -08:00
|
|
|
/* no string - index 0 */
|
2010-07-27 18:45:57 -07:00
|
|
|
if (!key)
|
2011-10-20 22:40:01 -07:00
|
|
|
return 0;
|
2008-03-07 23:28:12 -08:00
|
|
|
|
2006-12-28 07:23:47 -08:00
|
|
|
/* calc hash num */
|
|
|
|
for (i = 0, ptr = (unsigned char *)key, value = (int)(*ptr);
|
2010-07-27 18:45:57 -07:00
|
|
|
value;
|
|
|
|
ptr++, i++, value = (int)(*ptr))
|
2011-10-20 22:40:01 -07:00
|
|
|
hash_num ^= (value | (value << 8)) >> (i & 0x7);
|
2006-12-28 07:23:47 -08:00
|
|
|
|
|
|
|
/* mask it */
|
2008-09-11 04:24:13 -07:00
|
|
|
mask = (1 << hash_size) - 1;
|
|
|
|
hash_num &= mask;
|
2006-12-28 07:23:47 -08:00
|
|
|
/* return it */
|
|
|
|
return hash_num;
|
2011-12-02 06:42:13 -08:00
|
|
|
}
|
2006-12-28 07:23:47 -08:00
|
|
|
|