summaryrefslogtreecommitdiff
path: root/legacy/eet/src/lib/eet_utils.c
diff options
context:
space:
mode:
authorSebastian Dransfeld <sd@tango.flipp.net>2006-12-28 15:23:47 +0000
committerSebastian Dransfeld <sd@tango.flipp.net>2006-12-28 15:23:47 +0000
commit98b5b625abcc8b1fb8188224e136e39e35c1d002 (patch)
tree5eab5bee85c346549cf0ea7e57cf605d15ec93b5 /legacy/eet/src/lib/eet_utils.c
parent4518aa12179346f090d7d88fb2c43c4cb17b3b63 (diff)
Move hash gen func to own file.
SVN revision: 27605
Diffstat (limited to 'legacy/eet/src/lib/eet_utils.c')
-rw-r--r--legacy/eet/src/lib/eet_utils.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/legacy/eet/src/lib/eet_utils.c b/legacy/eet/src/lib/eet_utils.c
new file mode 100644
index 0000000000..898d87fa1f
--- /dev/null
+++ b/legacy/eet/src/lib/eet_utils.c
@@ -0,0 +1,35 @@
1int
2_eet_hash_gen(const char *key, int hash_size)
3{
4 int hash_num = 0;
5 int value, i;
6 unsigned char *ptr;
7
8 const int masks[9] =
9 {
10 0x00,
11 0x01,
12 0x03,
13 0x07,
14 0x0f,
15 0x1f,
16 0x3f,
17 0x7f,
18 0xff
19 };
20
21 /* no string - index 0 */
22 if (!key) 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 hash_num &= masks[hash_size];
32 /* return it */
33 return hash_num;
34}
35