aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/eet/src/lib/eet_utils.c
blob: 8e591a2833ee42fd26d3f37e6d287f30ce86e699 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* ifdef HAVE_CONFIG_H */

#include <stdio.h>
#include <math.h>

#include "Eet.h"
#include "Eet_private.h"

int
_eet_hash_gen(const char *key,
              int         hash_size)
{
   int hash_num = 0;
   int value, i;
   int mask;
   unsigned char *ptr;

   /* no string - index 0 */
   if (!key)
     return 0;

   /* calc hash num */
   for (i = 0, ptr = (unsigned char *)key, value = (int)(*ptr);
        value;
        ptr++, i++, value = (int)(*ptr))
     hash_num ^= (value | (value << 8)) >> (i & 0x7);

   /* mask it */
   mask = (1 << hash_size) - 1;
   hash_num &= mask;
   /* return it */
   return hash_num;
} /* _eet_hash_gen */