blob: a207eb91d84edc451c7265e87798581084962ae7 [file] [log] [blame]
willy tarreau12350152005-12-18 01:03:27 +01001/*
2 This File is copied from
3
4 http://www.oreilly.com/catalog/masteralgoc/index.html
5 Mastering Algorithms with C
6 By Kyle Loudon
7 ISBN: 1-56592-453-3
8 Publishd by O'Reilly
9
10 We have added our own struct to these function.
11 */
12
13/*****************************************************************************
14* *
15* ------------------------------- hashpjw.c ------------------------------ *
16* *
17*****************************************************************************/
18
19#include <include/hashpjw.h>
20
21/*****************************************************************************
22* *
23* -------------------------------- hashpjw ------------------------------- *
24* *
25*****************************************************************************/
26
27int hashpjw(const void *key) {
28
29 const char *ptr;
30 unsigned int val;
willy tarreau598da412005-12-18 01:07:29 +010031 appsess *appsession_temp;
willy tarreau12350152005-12-18 01:03:27 +010032
33 /*****************************************************************************
34 * *
35 * Hash the key by performing a number of bit operations on it. *
36 * *
37 *****************************************************************************/
38
39 val = 0;
willy tarreau598da412005-12-18 01:07:29 +010040 appsession_temp = (appsess *)key;
willy tarreau12350152005-12-18 01:03:27 +010041 ptr = appsession_temp->sessid;
42
43 while (*ptr != '\0') {
44
45 int tmp;
46
47 val = (val << 4) + (*ptr);
48
49 if((tmp = (val & 0xf0000000))) {
50 val = val ^ (tmp >> 24);
51 val = val ^ tmp;
52 }
53 ptr++;
54 }/* end while */
55
56 /*****************************************************************************
57 * *
58 * In practice, replace PRIME_TBLSIZ with the actual table size. *
59 * *
60 *****************************************************************************/
61 return val % PRIME_TBLSIZ;
62}/* end hashpjw */