svn update: 51457 (latest:51480)
[framework/uifw/eet.git] / src / lib / eet_utils.c
1 #ifdef HAVE_CONFIG_H
2 # include <config.h>
3 #endif /* ifdef HAVE_CONFIG_H */
4
5 #include <stdio.h>
6 #include <math.h>
7
8 #include "Eet.h"
9 #include "Eet_private.h"
10
11 int
12 _eet_hash_gen(const char *key,
13               int         hash_size)
14 {
15    int hash_num = 0;
16    int value, i;
17    int mask;
18    unsigned char *ptr;
19
20    /* no string - index 0 */
21    if (!key)
22       return 0;
23
24    /* calc hash num */
25    for (i = 0, ptr = (unsigned char *)key, value = (int)(*ptr);
26         value;
27         ptr++, i++, value = (int)(*ptr))
28       hash_num ^= (value | (value << 8)) >> (i & 0x7);
29
30    /* mask it */
31    mask = (1 << hash_size) - 1;
32    hash_num &= mask;
33    /* return it */
34    return hash_num;
35 } /* _eet_hash_gen */
36